static int unsafeCompare(Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare(Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
/** * A builder for creating immutable sorted set instances, especially {@code public static final} * sets ("constant sets"), with a given comparator. Example: * * <pre>{@code * public static final ImmutableSortedSet<Number> LUCKY_NUMBERS = * new ImmutableSortedSet.Builder<Number>(ODDS_FIRST_COMPARATOR) * .addAll(SINGLE_DIGIT_PRIMES) * .add(42) * .build(); * }</pre> * * <p>Builder instances can be reused; it is safe to call {@link #build} multiple times to build * multiple sets in series. Each set is a superset of the set created before it. * * @since 2.0 */ public static final class Builder<E> extends ImmutableSet.Builder<E> { private final Comparator<? super E> comparator; /** * Creates a new builder. The returned builder is equivalent to the builder generated by {@link * ImmutableSortedSet#orderedBy}. */ public Builder(Comparator<? super E> comparator) { this.comparator = checkNotNull(comparator); } /** * Adds {@code element} to the {@code ImmutableSortedSet}. If the {@code ImmutableSortedSet}
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare(Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare(Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
static int unsafeCompare( Comparator<?> comparator, Object a, Object b) { // Pretend the comparator can compare anything. If it turns out it can't // compare a and b, we should get a CCE on the subsequent line. Only methods // that are spec'd to throw CCE should call this. @SuppressWarnings("unchecked") Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; return unsafeComparator.compare(a, b); }
public int compare(Entry<?, ?> entry1, Entry<?, ?> entry2) { return ImmutableSortedSet.unsafeCompare( comparator, entry1.getKey(), entry2.getKey()); } };
public int compare(Entry<?, ?> entry1, Entry<?, ?> entry2) { return ImmutableSortedSet.unsafeCompare( comparator, entry1.getKey(), entry2.getKey()); } };
private static void validateEntries(Entry<?, ?>[] entryArray, Comparator<?> comparator) { for (int i = 1; i < entryArray.length; i++) { if (ImmutableSortedSet.unsafeCompare(comparator, entryArray[i - 1].getKey(), entryArray[i].getKey()) == 0) { throw new IllegalArgumentException( "Duplicate keys in mappings " + entryArray[i - 1] + " and " + entryArray[i]); } } }
public int compare(Entry<?, ?> entry1, Entry<?, ?> entry2) { return ImmutableSortedSet.unsafeCompare( comparator, entry1.getKey(), entry2.getKey()); } };
private static void validateEntries(Entry<?, ?>[] entryArray, Comparator<?> comparator) { for (int i = 1; i < entryArray.length; i++) { if (ImmutableSortedSet.unsafeCompare(comparator, entryArray[i - 1].getKey(), entryArray[i].getKey()) == 0) { throw new IllegalArgumentException( "Duplicate keys in mappings " + entryArray[i - 1] + " and " + entryArray[i]); } } }
private static void validateEntries(Entry<?, ?>[] entryArray, Comparator<?> comparator) { for (int i = 1; i < entryArray.length; i++) { if (ImmutableSortedSet.unsafeCompare(comparator, entryArray[i - 1].getKey(), entryArray[i].getKey()) == 0) { throw new IllegalArgumentException( "Duplicate keys in mappings " + entryArray[i - 1] + " and " + entryArray[i]); } } }