java.lang.Double.compareTo()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(274)

本文整理了Java中java.lang.Double.compareTo()方法的一些代码示例,展示了Double.compareTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Double.compareTo()方法的具体详情如下:
包路径:java.lang.Double
类名称:Double
方法名:compareTo

Double.compareTo介绍

[英]Compares this object to the specified double object to determine their relative order. There are two special cases:

  • Double.NaN is equal to Double.NaN and it is greater than any other double value, including Double.POSITIVE_INFINITY;
  • +0.0d is greater than -0.0d
    [中]将此对象与指定的双对象进行比较,以确定它们的相对顺序。有两种特殊情况:
    *加倍。南等于双。NaN,它大于任何其他双精度值,包括double。正无穷大;
    *+0.0d大于-0.0d

代码示例

代码示例来源:origin: apache/incubator-druid

@Override
 public int compare(Object o, Object o1)
 {
  return ((Double) o).compareTo((Double) o1);
 }
};

代码示例来源:origin: apache/incubator-druid

@Override
 public int compare(Object o, Object o1)
 {
  return ((Double) o).compareTo((Double) o1);
 }
};

代码示例来源:origin: apache/hbase

@Override
public int compare(final Double d1, final Double d2) {
 if (d1 == null ^ d2 == null) {
  return d1 == null ? -1 : 1; // either of one is null.
 } else if (d1 == null)
  return 0; // both are null
 return d1.compareTo(d2); // natural ordering.
}

代码示例来源:origin: h2oai/h2o-2

@Override
 public int compare(Integer o1, Integer o2) {
  return ((Double)means[o1]).compareTo(means[o2]);
 }
});

代码示例来源:origin: stackoverflow.com

public class District implements Comparable<District>{
 String zipcode; 
 Double populationDensity;
 public int compareTo(District other)
 {
  return populationDensity.compareTo(other.populationDensity);
 }
}

代码示例来源:origin: apache/kylin

@Override
  public int compare(String str1, String str2) {
    try {
      Double num1 = Double.parseDouble(str1);
      Double num2 = Double.parseDouble(str2);
      return num1.compareTo(num2);
    } catch (NumberFormatException e) {
      logger.error("NumberFormatException when parse doul family number.str1:" + str1 + " str2:" + str2);
      return 0;
    }
  }
};

代码示例来源:origin: apache/incubator-pinot

@Override
 public int compare(Number2ObjectPair o1, Number2ObjectPair o2) {
  return new Double(o1.a.doubleValue()).compareTo(new Double(o2.a.doubleValue()));
 }
}

代码示例来源:origin: apache/incubator-pinot

@Override
 public int compare(Number2ObjectPair o1, Number2ObjectPair o2) {
  return new Double(o2.a.doubleValue()).compareTo(new Double(o1.a.doubleValue()));
 }
}

代码示例来源:origin: FudanNLP/fnlp

public int compare(Object arg0, Object arg1) {   
    Double key1 = Double.valueOf(((Map.Entry) arg0).getValue().toString());   
    Double key2 = Double.valueOf(((Map.Entry) arg1).getValue().toString());   
    return -key1.compareTo(key2);   
  }   
});

代码示例来源:origin: h2oai/h2o-3

@Override
 public int compare(final double[] a, final double[] b) {
  Double d1 = a[0]; Double d2 = b[0];
  return d1.compareTo(d2);
 }
});

代码示例来源:origin: com.h2database/h2

@Override
public int compare(Object aObj, Object bObj) {
  if (aObj instanceof Double && bObj instanceof Double) {
    Double a = (Double) aObj;
    Double b = (Double) bObj;
    return a.compareTo(b);
  }
  return super.compare(aObj, bObj);
}

代码示例来源:origin: google/guava

@Override
public int compare(Number a, Number b) {
 return ((Double) a.doubleValue()).compareTo(b.doubleValue());
}

代码示例来源:origin: stackoverflow.com

SortedSet<Map.Entry<String, Double>> sortedset = new TreeSet<Map.Entry<String, Double>>(
     new Comparator<Map.Entry<String, Double>>() {
       @Override
       public int compare(Map.Entry<String, Double> e1,
           Map.Entry<String, Double> e2) {
         return e1.getValue().compareTo(e2.getValue());
       }
     });
sortedset.addAll(myMap.entrySet());

代码示例来源:origin: neo4j/neo4j

@Override
public int compareTo( PositionData o )
{
  return f().compareTo( o.f() );
}

代码示例来源:origin: apache/kylin

@Override
  public int compare(String o1, String o2) {
    Double d1 = Double.parseDouble(o1);
    Double d2 = Double.parseDouble(o2);
    return d1.compareTo(d2);
  }
}));

代码示例来源:origin: google/guava

public void testCompare() {
 for (double x : VALUES) {
  for (double y : VALUES) {
   // note: spec requires only that the sign is the same
   assertEquals(x + ", " + y, Double.valueOf(x).compareTo(y), Doubles.compare(x, y));
  }
 }
}

代码示例来源:origin: apache/kylin

@Override
  public int compare(String o1, String o2) {
    try {
      Double d1 = Double.parseDouble(o1);
      Double d2 = Double.parseDouble(o2);
      return d1.compareTo(d2);
    } catch (NumberFormatException e) {
      e.printStackTrace();
      return 0;
    }
  }
});

代码示例来源:origin: apache/kylin

@Override
  public int compare(String o1, String o2) {
    try {
      Double d1 = Double.parseDouble(o1);
      Double d2 = Double.parseDouble(o2);
      return d1.compareTo(d2);
    } catch (NumberFormatException e) {
      e.printStackTrace();
      return 0;
    }
  }
});

代码示例来源:origin: SonarSource/sonarqube

private static boolean isBestValue(Measure measure, Double bestValue) {
  switch (measure.getValueType()) {
   case BOOLEAN:
    return (bestValue.intValue() == 1) == measure.getBooleanValue();
   case INT:
    return bestValue.intValue() == measure.getIntValue();
   case LONG:
    return bestValue.longValue() == measure.getLongValue();
   case DOUBLE:
    return bestValue.compareTo(measure.getDoubleValue()) == 0;
   default:
    return false;
  }
 }
}

代码示例来源:origin: azkaban/azkaban

@Override
 public int compare(final Executor o1, final Executor o2) {
  final ExecutorInfo stat1 = o1.getExecutorInfo();
  final ExecutorInfo stat2 = o2.getExecutorInfo();
  final int result = 0;
  if (statisticsObjectCheck(stat1, stat2, CPUUSAGE_COMPARATOR_NAME)) {
   return result;
  }
  // CPU usage , the lesser the value is, the better.
  return ((Double) stat2.getCpuUsage()).compareTo(stat1.getCpuUsage());
 }
});

相关文章