Java Code Examples for com.google.common.primitives.Doubles#compare()
The following examples show how to use
com.google.common.primitives.Doubles#compare() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpResponseAssert.java From wisdom with Apache License 2.0 | 6 votes |
/** * Checks that the Http Response contains a numeric value at the given Json Pointer (JavaScript Object Notation * (JSON) Pointer). The Json Pointer syntax is described in the * <a href="https://tools.ietf.org/html/rfc6901">RFC 6901</a>. * * @param path the Json Pointer * @param value the expected value * @return the current {@link HttpResponseAssert} */ public HttpResponseAssert<T> hasJsonNumericField(String path, double value) { isNotNull(); isJson(); final JsonNode node = ((JsonNode) actual.body()).at(path); if (node.isMissingNode()) { failWithMessage("Expected node pointed by <%s> to be present in <%s>", path, actual.body().toString()); } // We cannot compare double directly as it may lead to precision issues. if (Doubles.compare(node.asDouble(), value) == 0) { failWithMessage("Expected node pointed by <%s> to be <%s> but was <%s>", path, value, node.asDouble()); } return this; }
Example 2
Source File: Ideas_2011_08_01.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
@ExpectWarning(value="RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", num = 9) public static int testGuavaPrimitiveCompareCalls() { int count = 0; if (Booleans.compare(false, true) == -1) count++; if (Chars.compare('a', 'b') == -1) count++; if (Doubles.compare(1, 2) == -1) count++; if (Floats.compare(1, 2) == -1) count++; if (Ints.compare(1, 2) == -1) count++; if (Longs.compare(1, 2) == -1) count++; if (Shorts.compare((short) 1, (short) 2) == -1) count++; if (SignedBytes.compare((byte) 1, (byte) 2) == -1) count++; if (UnsignedBytes.compare((byte) 1, (byte) 2) == -1) count++; return count; }
Example 3
Source File: PLong.java From phoenix with Apache License 2.0 | 6 votes |
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (lhs == rhs) { return 0; } if (lhs == null) { return -1; } if (rhs == null) { return 1; } if (rhsType == PDecimal.INSTANCE) { return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue())); } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE)) { return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue()); } return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue()); }
Example 4
Source File: PUnsignedDouble.java From phoenix with Apache License 2.0 | 6 votes |
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (lhs == rhs) { return 0; } if (lhs == null) { return -1; } if (rhs == null) { return 1; } if (rhsType == PDecimal.INSTANCE) { return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).doubleValue())); } return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue()); }
Example 5
Source File: PUnsignedLong.java From phoenix with Apache License 2.0 | 6 votes |
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (lhs == rhs) { return 0; } if (lhs == null) { return -1; } if (rhs == null) { return 1; } if (rhsType == PDecimal.INSTANCE) { return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue())); } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE)) { return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue()); } return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue()); }
Example 6
Source File: PDouble.java From phoenix with Apache License 2.0 | 6 votes |
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (lhs == rhs) { return 0; } if (lhs == null) { return -1; } if (rhs == null) { return 1; } if (rhsType == PDecimal.INSTANCE) { return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).doubleValue())); } return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue()); }
Example 7
Source File: SingularityTaskRequestWithPriority.java From Singularity with Apache License 2.0 | 5 votes |
public static Comparator<SingularityTaskRequestWithPriority> weightedPriorityComparator() { return new Comparator<SingularityTaskRequestWithPriority>() { @Override public int compare( SingularityTaskRequestWithPriority o1, SingularityTaskRequestWithPriority o2 ) { return Doubles.compare(o2.getWeightedPriority(), o1.getWeightedPriority()); } }; }
Example 8
Source File: PDouble.java From phoenix with Apache License 2.0 | 5 votes |
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (rhsType == PDecimal.INSTANCE) { return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).doubleValue())); } return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue()); }
Example 9
Source File: PUnsignedLong.java From phoenix with Apache License 2.0 | 5 votes |
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (rhsType == PDecimal.INSTANCE) { return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue())); } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE)) { return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue()); } return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue()); }
Example 10
Source File: PUnsignedDouble.java From phoenix with Apache License 2.0 | 5 votes |
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (rhsType == PDecimal.INSTANCE) { return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).doubleValue())); } return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue()); }
Example 11
Source File: PLong.java From phoenix with Apache License 2.0 | 5 votes |
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (rhsType == PDecimal.INSTANCE) { return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue())); } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE)) { return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue()); } return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue()); }
Example 12
Source File: TaggerEmbeddings.java From easyccg with MIT License | 4 votes |
@Override public int compareTo(ScoredCategory o) { return Doubles.compare(o.score, score); }
Example 13
Source File: NumericValuePredicate.java From suro with Apache License 2.0 | 4 votes |
private static int doComparison(Number a, Number b) { return Doubles.compare(a.doubleValue(), b.doubleValue()); }
Example 14
Source File: MutableServiceCall.java From glowroot with Apache License 2.0 | 4 votes |
@Override public int compare(MutableServiceCall left, MutableServiceCall right) { return Doubles.compare(right.totalDurationNanos, left.totalDurationNanos); }
Example 15
Source File: MutableQuery.java From glowroot with Apache License 2.0 | 4 votes |
@Override public int compare(MutableQuery left, MutableQuery right) { return Doubles.compare(right.getTotalDurationNanos(), left.getTotalDurationNanos()); }
Example 16
Source File: ChunkCompileTaskGeneratorSchematic.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
public int compareTo(ChunkCompileTaskGeneratorSchematic other) { return Doubles.compare(this.distanceSq, other.distanceSq); }
Example 17
Source File: Util.java From EasySRL with Apache License 2.0 | 4 votes |
@Override public int compareTo(final Scored<T> o) { return Doubles.compare(o.score, score); }
Example 18
Source File: SortACollection.java From levelup-java-examples with Apache License 2.0 | 4 votes |
public int compare(Wrestler left, Wrestler right) { return Doubles.compare(left.getWeightClass(), right.getWeightClass()); }
Example 19
Source File: LiteralImpl.java From emodb with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public int compareTo(Literal o) { Object that = o.getValue(); // Sort nulls first if (_value == null) { return that == null ? 0 : -1; } else if (that == null) { return 1; } // Optimize for common case where values being compared are of the same type Class<?> thisClass = _value.getClass(); Class<?> thatClass = that.getClass(); if (!areClassesEqual(thisClass, thatClass)) { // Values are of different types // If both values are numeric then use numeric comparison regardless of the underlying type (int, double, and so on) if (isNumber(thisClass) && isNumber(thatClass)) { if (isDouble((Class<? extends Number>) thisClass) || isDouble((Class<? extends Number>) thatClass)) { return Doubles.compare(((Number) _value).doubleValue(), ((Number) that).doubleValue()); } else { return Longs.compare(((Number) _value).longValue(), ((Number) that).longValue()); } } // Sort by simple class name return getComparisonClassName(thisClass).compareTo(getComparisonClassName(thatClass)); } if (Comparable.class.isAssignableFrom(thisClass)) { return ((Comparable) _value).compareTo(that); } // When not comparable, compare the string representations try { StringBuilder thisStr = new StringBuilder(); StringBuilder thatStr = new StringBuilder(); this.appendTo(thisStr); o.appendTo(thatStr); return thisStr.toString().compareTo(thatStr.toString()); } catch (IOException e) { // Should never happen throw Throwables.propagate(e); } }
Example 20
Source File: ChunkRenderDispatcherLitematica.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
public int compareTo(ChunkRenderDispatcherLitematica.PendingUpload other) { return Doubles.compare(this.distanceSq, other.distanceSq); }