当前位置: 首页>>代码示例>>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;未经允许,请勿转载。