/** * <p> * Groups input splits by file path. Each inout split group is ordered by starting bytes * to ensure file parts in correct order. * </p> * <p> * Example: * <pre> * hdfs:///tmp/table/file_1.txt -> hdfs:///tmp/table/file_1.txt:0+10000 * hdfs:///tmp/table/file_1.txt:10001+20000 * hdfs:///tmp/table/file_2.txt -> hdfs:///tmp/table/file_2.txt:0+10000 * </pre> * </p> * @param inputSplits input splits * @return multimap where key is file path and value is group of ordered file splits */ private Multimap<Path, FileSplit> transformFileSplits(InputSplit[] inputSplits) { Multimap<Path, FileSplit> inputSplitGroups = TreeMultimap.create( Ordering.natural(), Comparator.comparingLong(FileSplit::getStart)); for (InputSplit inputSplit : inputSplits) { FileSplit fileSplit = (FileSplit) inputSplit; inputSplitGroups.put(fileSplit.getPath(), fileSplit); } return inputSplitGroups; }
ContiguousSet(DiscreteDomain<C> domain) { super(Ordering.natural()); this.domain = domain; }
@SuppressWarnings("unchecked") AbstractSortedMultiset() { this((Comparator) Ordering.natural()); }
/** * Returns the specified comparator if not null; otherwise returns {@code * Ordering.natural()}. This method is an abomination of generics; the only * purpose of this method is to contain the ugly type-casting in one place. */ @SuppressWarnings("unchecked") static <E> Comparator<? super E> orNaturalOrder(@Nullable Comparator<? super E> comparator) { if (comparator != null) { // can't use ? : because of javac bug 5080917 return comparator; } return (Comparator<E>) Ordering.natural(); }
@SuppressWarnings("unchecked") // if sortedSet.comparator() is null, the set must be naturally ordered public static <E> Comparator<? super E> comparator(SortedSet<E> sortedSet) { Comparator<? super E> result = sortedSet.comparator(); if (result == null) { result = (Comparator<? super E>) Ordering.natural(); } return result; } }
/** * Constructs a {@code TreeMultimap}, ordered by the natural ordering of its * keys and values, with the same mappings as the specified multimap. * * @param multimap the multimap whose contents are copied to this multimap */ public static <K extends Comparable, V extends Comparable> TreeMultimap<K, V> create( Multimap<? extends K, ? extends V> multimap) { return new TreeMultimap<K, V>(Ordering.natural(), Ordering.natural(), multimap); }
/** * Returns an immutable sorted set containing the given elements sorted by * their natural ordering. When multiple elements are equivalent according to * {@link Comparable#compareTo}, only the first one specified is included. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1, E e2) { return construct(Ordering.natural(), 2, e1, e2); }
/** * Returns an immutable sorted set containing the given elements sorted by * their natural ordering. When multiple elements are equivalent according to * {@link Comparable#compareTo}, only the first one specified is included. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1, E e2, E e3) { return construct(Ordering.natural(), 3, e1, e2, e3); }
/** * Returns a {@code TopKSelector} that collects the greatest {@code k} elements added to it, * relative to the natural ordering of the elements, and returns them via {@link #topK} in * descending order. * * @throws IllegalArgumentException if {@code k < 0} */ public static <T extends Comparable<? super T>> TopKSelector<T> greatest(int k) { return greatest(k, Ordering.natural()); }
/** * Returns a builder that creates immutable sorted maps whose keys are * ordered by their natural ordering. The sorted maps use {@link * Ordering#natural()} as the comparator. */ public static <K extends Comparable<?>, V> Builder<K, V> naturalOrder() { return new Builder<K, V>(Ordering.natural()); }
/** * Returns an instance which specifies that the natural ordering of the elements is guaranteed. */ public static <S extends Comparable<? super S>> ElementOrder<S> natural() { return new ElementOrder<S>(Type.SORTED, Ordering.<S>natural()); }
/** * Returns a {@code TopKSelector} that collects the lowest {@code k} elements added to it, * relative to the natural ordering of the elements, and returns them via {@link #topK} in * ascending order. * * @throws IllegalArgumentException if {@code k < 0} */ public static <T extends Comparable<? super T>> TopKSelector<T> least(int k) { return least(k, Ordering.natural()); }
/** * Returns an immutable sorted multiset containing the given elements sorted by their natural * ordering. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) { return copyOf(Ordering.natural(), Arrays.asList(e1, e2, e3)); }
/** * Returns an immutable sorted set containing the given elements sorted by * their natural ordering. When multiple elements are equivalent according to * {@link Comparable#compareTo}, only the first one specified is included. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of( E e1, E e2, E e3, E e4, E e5) { return construct(Ordering.natural(), 5, e1, e2, e3, e4, e5); }
/** * Returns a builder that creates immutable sorted multisets whose elements are ordered by their * natural ordering. The sorted multisets use {@link Ordering#natural()} as the comparator. This * method provides more type-safety than {@link #builder}, as it can be called only for classes * that implement {@link Comparable}. * * <p>Note: the type parameter {@code E} extends {@code Comparable<?>} rather than {@code * Comparable<? super E>} as a workaround for javac <a * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6468354">bug 6468354</a>. */ public static <E extends Comparable<?>> Builder<E> naturalOrder() { return new Builder<E>(Ordering.natural()); }
/** * Creates a new min-max priority queue using natural order, no maximum size, * and initially containing the given elements. */ public static <E extends Comparable<E>> MinMaxPriorityQueue<E> create( Iterable<? extends E> initialContents) { return new Builder<E>(Ordering.<E>natural()).create(initialContents); }
/** * Creates and returns a new builder, configured to build {@code * MinMaxPriorityQueue} instances sized appropriately to hold {@code * expectedSize} elements. */ public static Builder<Comparable> expectedSize(int expectedSize) { return new Builder<Comparable>(Ordering.natural()).expectedSize(expectedSize); }
/** * Creates and returns a new builder, configured to build {@code * MinMaxPriorityQueue} instances that are limited to {@code maximumSize} * elements. Each time a queue grows beyond this bound, it immediately * removes its greatest element (according to its comparator), which might be * the element that was just added. */ public static Builder<Comparable> maximumSize(int maximumSize) { return new Builder<Comparable>(Ordering.natural()).maximumSize(maximumSize); }
@Override public int compare(CatalogMetadata left, CatalogMetadata right) { return Ordering.natural().compare(left.getCatalogName(), right.getCatalogName()); } };
ImmutableList<K> collectTypes(Iterable<? extends K> types) { // type -> order number. 1 for Object, 2 for anything directly below, so on so forth. Map<K, Integer> map = Maps.newHashMap(); for (K type : types) { collectTypes(type, map); } return sortKeysByValue(map, Ordering.natural().reverse()); }