/** * Returns a new comparator which sorts iterables by comparing corresponding elements pairwise * until a nonzero result is found; imposes "dictionary order." If the end of one iterable is * reached, but not the other, the shorter iterable is considered to be less than the longer one. * For example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, * 1] < [1, 2] < [2]}. * * <p>Note that {@code Collections.reverseOrder(lexicographical(comparator))} is not equivalent to * {@code lexicographical(Collections.reverseOrder(comparator))} (consider how each would order * {@code [1]} and {@code [1, 1]}). */ // Note: 90% of the time we don't add type parameters or wildcards that serve only to "tweak" the // desired return type. However, *nested* generics introduce a special class of problems that we // think tip it over into being worthwhile. public static <T, S extends T> Comparator<Iterable<S>> lexicographical(Comparator<T> comparator) { return new LexicographicalOrdering<S>(checkNotNull(comparator)); }
@SuppressWarnings("unchecked") // deserialization is unsafe public static LexicographicalOrdering<Object> instantiate(SerializationStreamReader reader) throws SerializationException { return new LexicographicalOrdering<>((Ordering<Object>) reader.readObject()); }
/** * Returns a new comparator which sorts iterables by comparing corresponding elements pairwise * until a nonzero result is found; imposes "dictionary order." If the end of one iterable is * reached, but not the other, the shorter iterable is considered to be less than the longer one. * For example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, * 1] < [1, 2] < [2]}. * * <p>Note that {@code Collections.reverseOrder(lexicographical(comparator))} is not equivalent to * {@code lexicographical(Collections.reverseOrder(comparator))} (consider how each would order * {@code [1]} and {@code [1, 1]}). */ // Note: 90% of the time we don't add type parameters or wildcards that serve only to "tweak" the // desired return type. However, *nested* generics introduce a special class of problems that we // think tip it over into being worthwhile. public static <T, S extends T> Comparator<Iterable<S>> lexicographical(Comparator<T> comparator) { return new LexicographicalOrdering<S>(checkNotNull(comparator)); }
/** * Returns a new comparator which sorts iterables by comparing corresponding elements pairwise * until a nonzero result is found; imposes "dictionary order." If the end of one iterable is * reached, but not the other, the shorter iterable is considered to be less than the longer one. * For example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, * 1] < [1, 2] < [2]}. * * <p>Note that {@code Collections.reverseOrder(lexicographical(comparator))} is not equivalent to * {@code lexicographical(Collections.reverseOrder(comparator))} (consider how each would order * {@code [1]} and {@code [1, 1]}). */ // Note: 90% of the time we don't add type parameters or wildcards that serve only to "tweak" the // desired return type. However, *nested* generics introduce a special class of problems that we // think tip it over into being worthwhile. public static <T, S extends T> Comparator<Iterable<S>> lexicographical(Comparator<T> comparator) { return new LexicographicalOrdering<S>(checkNotNull(comparator)); }
/** * Returns a new ordering which sorts iterables by comparing corresponding elements pairwise until * a nonzero result is found; imposes "dictionary order". If the end of one iterable is reached, * but not the other, the shorter iterable is considered to be less than the longer one. For * example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, 1] < * [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not equivalent to {@code * ordering.reverse().lexicographical()} (consider how each would order {@code [1]} and {@code [1, * 1]}). * * <p><b>Java 8 users:</b> Use {@link Comparators#lexicographical(Comparator)} instead. * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding elements pairwise until * a nonzero result is found; imposes "dictionary order". If the end of one iterable is reached, * but not the other, the shorter iterable is considered to be less than the longer one. For * example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, 1] < * [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not equivalent to {@code * ordering.reverse().lexicographical()} (consider how each would order {@code [1]} and {@code [1, * 1]}). * * <p><b>Java 8 users:</b> Use {@link Comparators#lexicographical(Comparator)} instead. * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding elements pairwise until * a nonzero result is found; imposes "dictionary order". If the end of one iterable is reached, * but not the other, the shorter iterable is considered to be less than the longer one. For * example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, 1] < * [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not equivalent to {@code * ordering.reverse().lexicographical()} (consider how each would order {@code [1]} and {@code [1, * 1]}). * * <p><b>Java 8 users:</b> Use {@link Comparators#lexicographical(Comparator)} instead. * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new comparator which sorts iterables by comparing corresponding elements pairwise * until a nonzero result is found; imposes "dictionary order." If the end of one iterable is * reached, but not the other, the shorter iterable is considered to be less than the longer one. * For example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, * 1] < [1, 2] < [2]}. * * <p>Note that {@code Collections.reverseOrder(lexicographical(comparator))} is not equivalent to * {@code lexicographical(Collections.reverseOrder(comparator))} (consider how each would order * {@code [1]} and {@code [1, 1]}). */ // Note: 90% of the time we don't add type parameters or wildcards that serve only to "tweak" the // desired return type. However, *nested* generics introduce a special class of problems that we // think tip it over into being worthwhile. public static <T, S extends T> Comparator<Iterable<S>> lexicographical(Comparator<T> comparator) { return new LexicographicalOrdering<S>(checkNotNull(comparator)); }
/** * Returns a new comparator which sorts iterables by comparing corresponding elements pairwise * until a nonzero result is found; imposes "dictionary order." If the end of one iterable is * reached, but not the other, the shorter iterable is considered to be less than the longer one. * For example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, * 1] < [1, 2] < [2]}. * * <p>Note that {@code Collections.reverseOrder(lexicographical(comparator))} is not equivalent to * {@code lexicographical(Collections.reverseOrder(comparator))} (consider how each would order * {@code [1]} and {@code [1, 1]}). */ // Note: 90% of the time we don't add type parameters or wildcards that serve only to "tweak" the // desired return type. However, *nested* generics introduce a special class of problems that we // think tip it over into being worthwhile. public static <T, S extends T> Comparator<Iterable<S>> lexicographical(Comparator<T> comparator) { return new LexicographicalOrdering<S>(checkNotNull(comparator)); }
@SuppressWarnings("unchecked") // deserialization is unsafe public static LexicographicalOrdering<Object> instantiate(SerializationStreamReader reader) throws SerializationException { return new LexicographicalOrdering<>((Ordering<Object>) reader.readObject()); }
/** * Returns a new ordering which sorts iterables by comparing corresponding elements pairwise until * a nonzero result is found; imposes "dictionary order". If the end of one iterable is reached, * but not the other, the shorter iterable is considered to be less than the longer one. For * example, a lexicographical natural ordering over integers considers {@code [] < [1] < [1, 1] < * [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not equivalent to {@code * ordering.reverse().lexicographical()} (consider how each would order {@code [1]} and {@code [1, * 1]}). * * <p><b>Java 8 users:</b> Use {@link Comparators#lexicographical(Comparator)} instead. * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2.0 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }
/** * Returns a new ordering which sorts iterables by comparing corresponding * elements pairwise until a nonzero result is found; imposes "dictionary * order". If the end of one iterable is reached, but not the other, the * shorter iterable is considered to be less than the longer one. For example, * a lexicographical natural ordering over integers considers {@code * [] < [1] < [1, 1] < [1, 2] < [2]}. * * <p>Note that {@code ordering.lexicographical().reverse()} is not * equivalent to {@code ordering.reverse().lexicographical()} (consider how * each would order {@code [1]} and {@code [1, 1]}). * * @since 2 */ @GwtCompatible(serializable = true) // type parameter <S> lets us avoid the extra <String> in statements like: // Ordering<Iterable<String>> o = // Ordering.<String>natural().lexicographical(); public <S extends T> Ordering<Iterable<S>> lexicographical() { /* * Note that technically the returned ordering should be capable of * handling not just {@code Iterable<S>} instances, but also any {@code * Iterable<? extends S>}. However, the need for this comes up so rarely * that it doesn't justify making everyone else deal with the very ugly * wildcard. */ return new LexicographicalOrdering<S>(this); }