@Override public int compare(int[] left, int[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Ints.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@Override public int compare(int[] left, int[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Ints.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@Override public int compare(String s, String s2) { return Ints.compare(s.length(), s2.length()); } }).nullsFirst().compound(Ordering.natural());
@Override public int compareTo(Composite<T> that) { return Ints.compare(rank, that.rank); }
@Override public ComparisonChain compare(int left, int right) { return classify(Ints.compare(left, right)); }
@Override public int compareTo(Element that) { return Ints.compare(hash, that.hash); }
@Override public int compare(int[] left, int[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Ints.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@Override public int compare(Invokable<?, ?> left, Invokable<?, ?> right) { return Ints.compare(left.getParameters().size(), right.getParameters().size()); } };
@Override public int compareTo(VSizeColumnarInts o) { int retVal = Ints.compare(numBytes, o.numBytes); if (retVal == 0) { retVal = buffer.compareTo(o.buffer); } return retVal; }
@Override public ComparisonChain compare(int left, int right) { return classify(Ints.compare(left, right)); }
@Override public int compare(File o1, File o2) { try { return Ints.compare(Integer.parseInt(o1.getName()), Integer.parseInt(o2.getName())); } catch (NumberFormatException e) { log.error(e, "Couldn't compare as numbers? [%s][%s]", o1, o2); return o1.compareTo(o2); } } }
/** * Compares the two specified {@code int} values, treating them as unsigned values between {@code * 0} and {@code 2^32 - 1} inclusive. * * <p><b>Java 8 users:</b> use {@link Integer#compareUnsigned(int, int)} instead. * * @param a the first unsigned {@code int} to compare * @param b the second unsigned {@code int} to compare * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is * greater than {@code b}; or zero if they are equal */ public static int compare(int a, int b) { return Ints.compare(flip(a), flip(b)); }
@Override public int compare(Method m1, Method m2) { int nameComparison = m1.getName().compareTo(m2.getName()); if (nameComparison != 0) { return nameComparison; } else { return Ints.compare(m1.getParameterTypes().length, m2.getParameterTypes().length); } } });
public void testCompare() { for (int x : VALUES) { for (int y : VALUES) { // note: spec requires only that the sign is the same assertEquals(x + ", " + y, Integer.valueOf(x).compareTo(y), Ints.compare(x, y)); } } }
@Override public int compare(ByteBuffer lhsBuffer, ByteBuffer rhsBuffer, int lhsPosition, int rhsPosition) { return Ints.compare(lhsBuffer.getInt(lhsPosition), rhsBuffer.getInt(rhsPosition)); } };
/** * Compares the two specified {@code int} values, treating them as unsigned values between {@code * 0} and {@code 2^32 - 1} inclusive. * * <p><b>Java 8 users:</b> use {@link Integer#compareUnsigned(int, int)} instead. * * @param a the first unsigned {@code int} to compare * @param b the second unsigned {@code int} to compare * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is * greater than {@code b}; or zero if they are equal */ public static int compare(int a, int b) { return Ints.compare(flip(a), flip(b)); }
@Override public int compare(Entry<? extends CallSiteKey, Integer> o1, Entry<? extends CallSiteKey, Integer> o2) { int offset1 = encodedArraySection.getItemOffset(callSiteSection.getEncodedCallSite(o1.getKey())); int offset2 = encodedArraySection.getItemOffset(callSiteSection.getEncodedCallSite(o2.getKey())); return Ints.compare(offset1, offset2); } };
public void testCompare() { // This is the only ordering for primitives that does not have a // corresponding Comparable wrapper in java.lang. for (int i = 0; i < VALUES.length; i++) { for (int j = 0; j < VALUES.length; j++) { byte x = VALUES[i]; byte y = VALUES[j]; // note: spec requires only that the sign is the same assertEquals( x + ", " + y, Math.signum(UnsignedBytes.compare(x, y)), Math.signum(Ints.compare(i, j))); } } }