Creates a matcher for {@link Iterable}s matching when the examined {@linkplain Iterable} has the elements sorted
according to the given {@linkplain Comparator}, but in a reverse order.
765848
public static <K> Matcher<Iterable<K>> sortedReversed(final Comparator<K> comparator) {
        return IsSortedIterableWithComparator.sortedReversed(comparator);
    }
398137
public static <U extends Comparable<U>, T extends Iterable<U>> Comparator<T> lexComparator() {
        return CmpUtil::lexCompare;
    }
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);
    }
874034
public static <T, L extends List<T>> L sortThis(L list, final Predicate2<? super T, ? super T> predicate)
    {
        return Iterate.sortThis(list, new Comparator<T>()
        {
            public int compare(T o1, T o2)
            {
                if (predicate.accept(o1, o2))
                {
                    return -1;
                }
                if (predicate.accept(o2, o1))
                {
                    return 1;
                }
                return 0;
            }
        });
    }
991601
public static <T> Collector<T, ?, Seq<T>> minAll(Comparator<? super T> comparator) {
        return minAllBy(t -> t, comparator);
    }
104957
public static boolean matches(Pattern patternMatcher, Object... elements)
    {
        if (patternMatcher == null) {
            return true;
        }

        for (Object element : elements) {
            if (matches(patternMatcher, element)) {
                return true;
            }
        }

        return false;
    }
285481
static Matcher startsWithCharSeq(Matcher matcher) {
    if (matcher instanceof SeqMatcher) {
      List<Matcher> matchers = matcher.<SeqMatcher>as().matchers();
      if (matchers.size() >= 2
          && matchers.get(0) instanceof StartMatcher
          && matchers.get(1) instanceof CharSeqMatcher) {
        List<Matcher> ms = new ArrayList<>();
        ms.add(new StartsWithMatcher(matchers.get(1).<CharSeqMatcher>as().pattern()));
        ms.addAll(matchers.subList(2, matchers.size()));
        return SeqMatcher.create(ms);
      }
    }
    return matcher;
  }
270446
public static Predicate<Element> shouldGenerateMatcher() {
        return element -> ElementParentsIterable.stream(element)
                .noneMatch(next -> nonNull(next.getAnnotation(DoNotGenerateMatcher.class)));
    }
1083223
public static <T extends Tree> Matcher<T> isPrimitiveOrBoxedPrimitiveType() {
    return new Matcher<T>() {
      @Override
      public boolean matches(Tree t, VisitorState state) {
        Type type = getType(t);
        return type != null && state.getTypes().unboxedTypeOrType(type).isPrimitive();
      }
    };
  }
396007
static Matcher create(Matcher... matchers) {
    switch (matchers.length) {
      case 0:  return TrueMatcher.INSTANCE;
      case 1:  return matchers[0];
      default: return new SeqMatcher(matchers);
    }
  }
455055
static Matcher inlineMatchAnyPrecedingOr(Matcher matcher) {
    if (matcher instanceof ZeroOrMoreMatcher) {
      ZeroOrMoreMatcher zm = matcher.as();
      if (zm.repeated() instanceof AnyMatcher && zm.next() instanceof OrMatcher) {
        List<Matcher> matchers = zm.next().<OrMatcher>as().matchers();
        List<Matcher> ms = new ArrayList<>();
        for (Matcher m : matchers) {
          ms.add(new ZeroOrMoreMatcher(AnyMatcher.INSTANCE, m));
        }
        return OrMatcher.create(ms);
      }
    }
    return matcher;
  }
1273336
@Override
	public Iterable<T> findAll(final Sort sort) {
		return new Iterable<T>() {
			@Override
			public Iterator<T> iterator() {
				return findAllInternal(sort, null, new HashMap<>());
			}
		};
	}
440561
public static <E> Ordering<Multiset.Entry<E>>
  byCountDescendingThenItemAscendingOrdering(Comparator<? super E> itemComparator) {
    final Ordering<Multiset.Entry<E>> byCount = byCountOrdering();
    final Ordering<Multiset.Entry<E>> byCountReversed = byCount.reverse();
    final Ordering<Multiset.Entry<E>> byElement = byElementOrdering(itemComparator);
    return byCountReversed.compound(byElement);
  }
1097984
public static <T> Predicate<T> contains(final Iterable<T> iterable) {
        return new Predicate<T>() {
            @Override
            public boolean test(final T testValue) {
                return Iterables.contains(iterable, testValue);
            }
        };
    }
748521
static Matcher flattenNestedSequences(Matcher matcher) {
    if (matcher instanceof SeqMatcher) {
      List<Matcher> matchers = matcher.<SeqMatcher>as().matchers();
      List<Matcher> ms = new ArrayList<>();
      for (Matcher m : matchers) {
        if (m instanceof SeqMatcher) {
          ms.addAll(m.<SeqMatcher>as().matchers());
        } else {
          ms.add(m);
        }
      }
      return SeqMatcher.create(ms);
    }
    return matcher;
  }
961715
public static <T> List<T> sorted(Iterable<T> items, Comparator<T> comparator) {
    List<T> result = toList(items);
    Collections.sort(result, comparator);
    return result;
  }
1285117
def _ordered_iterator(self):
        
        # A list of tuples, each with:
        #   * The iterable
        #   * The QuerySet number
        #   * The next value
        #
        # (Remember that each QuerySet is already sorted.)
        iterables = []
        for i, qs in zip(self._queryset_idxs, self._querysets):
            it = iter(qs)
            try:
                value = next(it)
            except StopIteration:
                # If this is already empty, just skip it.
                continue
            # Set the QuerySet number so that the comparison works properly.
            setattr(value, '#', i)
            iterables.append((it, i, value))

        # The offset of items returned.
        index = 0

        # Create a comparison function based on the requested ordering.
        _comparator = self._generate_comparator(self._order_by)
        def comparator(tuple_1, tuple_2):
            # The last element in each tuple is the actual item to compare.
            return _comparator(tuple_1[2], tuple_2[2])
        comparator = functools.cmp_to_key(comparator)

        # If in reverse mode, get the last value instead of the first value from
        # ordered_values below.
        if self._standard_ordering:
            next_value_ind = 0
        else:
            next_value_ind = -1

        # Continue until all iterables are empty.
        while iterables:
            # If there's only one iterator left, don't bother sorting.
            if len(iterables) > 1:
                # Sort the current values for each iterable.
                iterables = sorted(iterables, key=comparator)

                # The next ordering item is in the first position, unless we're
                # in reverse mode.
                it, i, value = iterables[next_value_ind]
            else:
                it, i, value = iterables[0]

            # Return the next value if we're within the slice of interest.
            if self._low_mark <= index:
                yield value
            index += 1
            # We've left the slice of interest, we're done.
            if index == self._high_mark:
                return

            # Iterate the iterable that just lost a value.
            try:
                value = next(it)
                # Set the QuerySet number so that the comparison works properly.
                setattr(value, '#', i)
                iterables[next_value_ind] = it, i, value
            except StopIteration:
                # This iterator is done, remove it.
                del iterables[next_value_ind]