return a sorted collection
514697
private static <V> Collection<V> sorted(Iterable<V> source, Comparator<V> comparator, int size)
    {
        V[] vs = (V[]) new Object[size];
        int i = 0;
        for (V v : source)
            vs[i++] = v;
        Arrays.sort(vs, comparator);
        return Arrays.asList(vs);
    }
786990
def _sorted_keys_items(dobj):
    """"""
    keys = sorted(dobj.keys())
    for key in keys:
        yield key, dobj[key]
779444
def sort_by_z(self):
        """"""
        return self.__class__(sorted(self, key=lambda p: p.Z))
227997
def as_sorted_list(options):
        
        if len(options) > 0:
            options = sorted(options, key=lambda o: o.number)
        return options
258804
function from(collection) {
  const result = [];
  const length = collection.length;
  let idx = -1;
  while (++idx < length) {
    result[idx] = collection[idx];
  }
  return result;
}
1286280
def sorted(cls, items, orders):
    ''''''
    return sorted(items, cmp=cls.multipleOrderComparison(orders))
1314626
private static <T> ArrayList<T> sorted(Collection<T> cls, Comparator<? super T> c) {
    ArrayList<T> sorted = new ArrayList<>(cls);
    sorted.sort(c);
    return sorted;
  }
377205
function sortCollectionByKey(col, isDESC) {
  col.sort(function(a, b) {
    return getKeyLen(a) - getKeyLen(b);
  });

  if (isDESC) col.reverse();

  return col;
}
525648
public function arsort(int $option = SORT_REGULAR): Collection
    {
        $index = 0;
        $items = $this->items;

        foreach ($items as &$item) {
            $item = [$index++, $item];
        }

        uasort($items, function ($a, $b) use ($option) {
            if ($a[1] === $b[1]) {
                return $a[0] - $b[0];
            }

            $set = [-1 => $b[1], 1 => $a[1]];

            asort($set, $option);
            reset($set);

            return key($set);
        });

        foreach ($items as &$item) {
            $item = $item[1];
        }

        return new static($items);
    }
188689
def _sortObjects(orderby='created', **kwargs):
    """"""
    o = []
    
    for m in kwargs.values():
        for l in iter(m):
            o.append(l)
    o = list(set(o))
    sortfunc = _sortByCreated if orderby == 'created' else _sortByModified
    if six.PY2:
        o.sort(sortfunc)
    else:
        o.sort(key=functools.cmp_to_key(sortfunc))

    return o
164216
public function natcasesort(): Collection
    {
        $index = 0;
        $items = $this->items;

        foreach ($items as &$item) {
            $item = [$index++, $item];
        }

        uasort($items, function ($a, $b) {
            $result = strnatcasecmp($a[1], $b[1]);

            return $result === 0 ? $a[0] - $b[0] : $result;
        });

        foreach ($items as &$item) {
            $item = $item[1];
        }

        return new static($items);
    }
1107844
@SuppressWarnings("unchecked")
    public static Collection<Object> getCollectionObj(Class<?> clazz) {
        if (clazz.isInterface()) {
            if (clazz.isAssignableFrom(List.class))
                return new ArrayList<>();
            else if (clazz.isAssignableFrom(Set.class))
                return new HashSet<>();
            else if (clazz.isAssignableFrom(Queue.class))
                return new ArrayDeque<>();
            else if (clazz.isAssignableFrom(SortedSet.class))
                return new TreeSet<>();
            else if (clazz.isAssignableFrom(BlockingQueue.class))
                return new LinkedBlockingDeque<>();
            else
                return null;
        } else {
            Collection<Object> collection = null;
            try {
                collection = (Collection<Object>) clazz.newInstance();
            } catch (Exception e) {
                System.err.println("new collection instance exception, " + e.getMessage());
            }
            return collection;
        }
    }
1189276
def _get_sorted_go2nt(self, go2nt, sortby):
        """"""
        if sortby is True:
            _fnc = self.get_fncsortnt()
            return sorted(go2nt.items(), key=lambda t: _fnc(t[1]))
        if sortby:
            return sorted(go2nt.items(), key=lambda t: sortby(t[1]))
        return go2nt.items()
1170818
def sort_items(items):
    """"""

    sorted_items = {}
    for item in items:
        category = lookup(item, 'itemCategory', 'categoryCode')
        if sorted_items.get(category) is None:
            sorted_items[category] = []
        sorted_items[category].append(item)

    return sorted_items
888768
def sorted_by_field(issues, field='closed_at', reverse=False):
    """"""
    return sorted(issues, key = lambda i:i[field], reverse=reverse)
939069
function(list, patterns) {

        var sorted = [];
        patterns.forEach(function(p) {
            sorted.push.apply(sorted, list.filter(function(file) {
                return p(file);
            }));
        });

        return sorted;

    }
648320
def items_sort(cls, items):
        
        class t(tuple):
            """Tuple with element-based sorting"""
            def __cmp__(self, other):
                for a, b in six.moves.zip_longest(self, other):
                    if a != b:
                        if a is None:
                            return 1
                        if b is None:
                            return -1
                        return a - b
                return 0

            def __lt__(self, other):
                return self.__cmp__(other) < 0
            def __gt_(self, other):
                return self.__cmp__(other) > 0
            def __le__(self, other):
                return self.__cmp__(other) <= 0
            def __ge_(self, other):
                return self.__cmp__(other) >= 0
            def __eq__(self, other):
                return self.__cmp__(other) == 0
            def __ne__(self, other):
                return self.__cmp__(other) != 0

        def key_func(x):
            if x.indented:
                return t((int(x.parent_item.sort), int(x.sort)))
            return t((int(x.sort), ))

        return sorted(items, key=key_func, reverse=True)