本文整理了Java中java.lang.Double.compare()
方法的一些代码示例,展示了Double.compare()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Double.compare()
方法的具体详情如下:
包路径:java.lang.Double
类名称:Double
方法名:compare
[英]Compares the two specified double values. There are two special cases:
代码示例来源:origin: google/guava
/**
* Compares the two specified {@code double} values. The sign of the value returned is the same as
* that of <code>((Double) a).{@linkplain Double#compareTo compareTo}(b)</code>. As with that
* method, {@code NaN} is treated as greater than all other values, and {@code 0.0 > -0.0}.
*
* <p><b>Note:</b> this method simply delegates to the JDK method {@link Double#compare}. It is
* provided for consistency with the other primitive types, whose compare methods were not added
* to the JDK until JDK 7.
*
* @param a the first {@code double} to compare
* @param b the second {@code double} 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(double a, double b) {
return Double.compare(a, b);
}
代码示例来源:origin: hankcs/HanLP
@Override
public int compare(PairFrequency o1, PairFrequency o2)
{
return -Double.compare(o1.mi, o2.mi);
}
});
代码示例来源:origin: hankcs/HanLP
@Override
public int compareTo(QueueElement other)
{
return Double.compare(weight, other.weight);
}
}
代码示例来源:origin: hankcs/HanLP
@Override
public int compare(PairFrequency o1, PairFrequency o2)
{
return -Double.compare(o1.le, o2.le);
}
});
代码示例来源:origin: hankcs/HanLP
@Override
public int compare(PairFrequency o1, PairFrequency o2)
{
return -Double.compare(o1.re, o2.re);
}
});
代码示例来源:origin: hankcs/HanLP
@Override
public int compare(PairFrequency o1, PairFrequency o2)
{
return -Double.compare(o1.score, o2.score);
}
});
代码示例来源:origin: hankcs/HanLP
@Override
public int compareTo(State o)
{
return Double.compare(cost, o.cost);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Compares this mutable to another in ascending order.
*
* @param other the other mutable to compare to, not null
* @return negative if this is less, zero if equal, positive if greater
*/
@Override
public int compareTo(final MutableDouble other) {
return Double.compare(this.value, other.value);
}
代码示例来源:origin: google/guava
@Override
public int compare(double[] left, double[] right) {
int minLength = Math.min(left.length, right.length);
for (int i = 0; i < minLength; i++) {
int result = Double.compare(left[i], right[i]);
if (result != 0) {
return result;
}
}
return left.length - right.length;
}
代码示例来源:origin: jenkinsci/jenkins
public int compareTo(Tag that) {
int r = Double.compare(this.ordinal, that.ordinal);
if (r!=0) return -r; // descending for ordinal
return this.hierarchy.compareTo(that.hierarchy);
}
}
代码示例来源:origin: prestodb/presto
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Estimate estimate = (Estimate) o;
return Double.compare(estimate.value, value) == 0;
}
代码示例来源:origin: skylot/jadx
private static String doubleToString(double value) {
if (Double.compare(value, Math.floor(value)) == 0
&& !Double.isInfinite(value)) {
return Integer.toString((int) value);
}
// remove trailing zeroes
NumberFormat f = NumberFormat.getInstance(Locale.ROOT);
f.setMaximumFractionDigits(4);
f.setMinimumIntegerDigits(1);
return f.format(value);
}
代码示例来源:origin: google/guava
@Override
public ComparisonChain compare(double left, double right) {
return classify(Double.compare(left, right));
}
代码示例来源:origin: prestodb/presto
@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
double leftValue = longBitsToDouble(leftBlock.getLong(leftPosition, 0));
double rightValue = longBitsToDouble(rightBlock.getLong(rightPosition, 0));
return Double.compare(leftValue, rightValue);
}
代码示例来源:origin: hankcs/HanLP
@Override
public int compareTo(Cluster<K> o)
{
return Double.compare(o.sectioned_gain(), sectioned_gain());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected int compareParameters(MediaType mediaType1, MediaType mediaType2) {
double quality1 = mediaType1.getQualityValue();
double quality2 = mediaType2.getQualityValue();
int qualityComparison = Double.compare(quality2, quality1);
if (qualityComparison != 0) {
return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3
}
return super.compareParameters(mediaType1, mediaType2);
}
};
代码示例来源:origin: google/guava
private static void testSortDescending(
double[] input, int fromIndex, int toIndex, double[] expectedOutput) {
input = Arrays.copyOf(input, input.length);
Doubles.sortDescending(input, fromIndex, toIndex);
// GWT's Arrays.equals doesn't appear to handle NaN correctly, so test each element individually
for (int i = 0; i < input.length; i++) {
assertEquals(0, Double.compare(expectedOutput[i], input[i]));
}
}
代码示例来源:origin: google/guava
private static void testSortDescending(double[] input, double[] expectedOutput) {
input = Arrays.copyOf(input, input.length);
Doubles.sortDescending(input);
// GWT's Arrays.equals doesn't appear to handle NaN correctly, so test each element individually
for (int i = 0; i < input.length; i++) {
assertEquals(0, Double.compare(expectedOutput[i], input[i]));
}
}
代码示例来源:origin: google/guava
private static void runTestFuzzyCompare(int toleranceIndex) {
double tolerance = get(TOLERANCE_CANDIDATES, toleranceIndex);
for (double a : ALL_DOUBLE_CANDIDATES) {
for (double b : ALL_DOUBLE_CANDIDATES) {
int expected = DoubleMath.fuzzyEquals(a, b, tolerance) ? 0 : Double.compare(a, b);
int actual = DoubleMath.fuzzyCompare(a, b, tolerance);
assertEquals(Integer.signum(expected), Integer.signum(actual));
}
}
}
代码示例来源:origin: prestodb/presto
private void testCustomAggregation(Double[] values, int n)
{
PriorityQueue<Double> heap = new PriorityQueue<>(n, (x, y) -> -Double.compare(x, y));
Arrays.stream(values).filter(x -> x != null).forEach(heap::add);
Double[] expected = new Double[heap.size()];
for (int i = heap.size() - 1; i >= 0; i--) {
expected[i] = heap.remove();
}
testAggregation(Arrays.asList(expected), createDoublesBlock(values), createLongRepeatBlock(n, values.length));
}
}
内容来源于网络,如有侵权,请联系作者删除!