當前位置: 首頁>>代碼示例>>Java>>正文


Java Comparator.comparingDouble方法代碼示例

本文整理匯總了Java中java.util.Comparator.comparingDouble方法的典型用法代碼示例。如果您正苦於以下問題:Java Comparator.comparingDouble方法的具體用法?Java Comparator.comparingDouble怎麽用?Java Comparator.comparingDouble使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Comparator的用法示例。


在下文中一共展示了Comparator.comparingDouble方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compare

import java.util.Comparator; //導入方法依賴的package包/類
@Override
public int compare(T o1, T o2) {
  Comparable obj1 = null;
  Comparable obj2 = null;

  try {
    obj1 = (Comparable) PropertyUtils.getProperty(o1, this.propertyPath);
    obj2 = (Comparable) PropertyUtils.getProperty(o2, this.propertyPath);
  } catch (NestedNullException ignored) {
    // Ignored, als het property NULL is, dan vergelijken met NULL
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    throw new IllegalArgumentException("Could not retrieve property " + this.propertyPath, e);
  }

  Comparator<Comparable<Object>> objectComparator = null;
  if ((obj1 != null && obj2 != null) && obj1 instanceof String) {
    obj1 = ((String) obj1).toLowerCase().trim();
    obj2 = ((String) obj2).toLowerCase().trim();

    if (!StringUtils.isEmpty((String) obj1) && !StringUtils.isEmpty((String) obj2)) {
      if (StringUtils.isNumeric((String) obj1) && StringUtils.isNumeric((String) obj2)) {
        objectComparator = Comparator.comparingDouble(o -> new Double(String.valueOf(o)));
      }
    }
  }

  if (objectComparator == null) {
    objectComparator = Comparator.naturalOrder();
  }

  //noinspection unchecked
  return Comparator.nullsLast(objectComparator).compare(obj1, obj2);
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:34,代碼來源:XmlElementPathBeanComparator.java

示例2: getBestGoodsWish

import java.util.Comparator; //導入方法依賴的package包/類
/**
 * Gets the best goods wish for a carrier unit.
 *
 * @param aiUnit The carrier {@code AIUnit}.
 * @param goodsType The {@code GoodsType} to wish for.
 * @return The best {@code GoodsWish} for the unit.
 */
public GoodsWish getBestGoodsWish(AIUnit aiUnit, GoodsType goodsType) {
    final Unit carrier = aiUnit.getUnit();
    final ToDoubleFunction<GoodsWish> wishValue
        = cacheDouble(gw -> {
                int turns = carrier.getTurnsToReach(carrier.getLocation(),
                                                    gw.getDestination());
                return (turns >= Unit.MANY_TURNS) ? -1.0
                    : (double)gw.getValue() / turns;
            });
    final Comparator<GoodsWish> comp
        = Comparator.comparingDouble(wishValue);

    List<GoodsWish> wishes = goodsWishes.get(goodsType);
    return (wishes == null) ? null
        : maximize(wishes, gw -> wishValue.applyAsDouble(gw) > 0.0, comp);
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:24,代碼來源:EuropeanAIPlayer.java

示例3: testDoubleComparator

import java.util.Comparator; //導入方法依賴的package包/類
public void testDoubleComparator() {
    Thing[] things = new Thing[doubleValues.length];
    for (int i=0; i<doubleValues.length; i++)
        things[i] = new Thing(0, 0L, doubleValues[i], null);
    Comparator<Thing> comp = Comparator.comparingDouble(new ToDoubleFunction<Thing>() {
        @Override
        public double applyAsDouble(Thing thing) {
            return thing.getDoubleField();
        }
    });

    assertComparisons(things, comp, comparisons);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:BasicTest.java

示例4: comparator

import java.util.Comparator; //導入方法依賴的package包/類
/** */
private static Comparator<IgniteBiTuple<Integer, IgniteBiTuple<Integer, Double>>> comparator() {
    return Comparator.comparingDouble(bt -> bt != null && bt.get2() != null ? bt.get2().get2() : Double.NEGATIVE_INFINITY);
}
 
開發者ID:Luodian,項目名稱:Higher-Cloud-Computing-Project,代碼行數:5,代碼來源:ColumnDecisionTreeTrainer.java

示例5: cachingDoubleComparator

import java.util.Comparator; //導入方法依賴的package包/類
/**
 * Helper to create a caching comparator.
 *
 * @param <T> The argument type to be converted to double.
 * @param f The double valued function to use in comparison.
 * @return A caching {@code Comparator}.
 */
public static <T> Comparator<T> cachingDoubleComparator(Function<T, Double> f) {
    return Comparator.comparingDouble(cacheDouble(f));
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:11,代碼來源:CollectionUtils.java


注:本文中的java.util.Comparator.comparingDouble方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。