下面列出了java.util.Comparator#comparingDouble ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
@Override
public void run()
{
MC.options.keySneak.setPressed(true);
Vec3d velocity = MC.player.getVelocity();
MC.player.setVelocity(0, velocity.y, 0);
Vec3d eyes = RotationUtils.getEyesPos().add(-0.5, -0.5, -0.5);
Comparator<BlockPos> comparator =
Comparator.<BlockPos> comparingDouble(
p -> eyes.squaredDistanceTo(Vec3d.of(p)));
BlockPos pos = blocks.stream().max(comparator).get();
if(!equipSolidBlock(pos))
{
ChatUtils.error(
"Found a hole in the tunnel's floor but don't have any blocks to fill it with.");
setEnabled(false);
return;
}
if(BlockUtils.getState(pos).getMaterial().isReplaceable())
placeBlockSimple(pos);
else
{
WURST.getHax().autoToolHack.equipBestTool(pos, false, true,
false);
breakBlockSimple(pos);
}
}
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);
}
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);
}
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);
}
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);
}
@Override
public void run()
{
KeyBindingUtils.setPressed(mc.gameSettings.keyBindSneak, true);
WMinecraft.getPlayer().motionX = 0;
WMinecraft.getPlayer().motionZ = 0;
Vec3d eyes = RotationUtils.getEyesPos().addVector(-0.5, -0.5, -0.5);
Comparator<BlockPos> comparator =
Comparator.<BlockPos> comparingDouble(
p -> eyes.squareDistanceTo(new Vec3d(p)));
BlockPos pos = blocks.stream().max(comparator).get();
if(!equipSolidBlock(pos))
{
ChatUtils.error(
"Found a hole in the tunnel's floor but don't have any blocks to fill it with.");
setEnabled(false);
return;
}
if(BlockUtils.getMaterial(pos).isReplaceable())
BlockUtils.placeBlockSimple(pos);
else
{
wurst.getHax().autoToolHack.equipBestTool(pos, false, true,
false);
BlockUtils.breakBlockSimple(pos);
}
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
private Priority(String name,
ToDoubleFunction<LivingEntity> keyExtractor)
{
this.name = name;
comparator = Comparator.comparingDouble(keyExtractor);
}
private Priority(String name,
ToDoubleFunction<LivingEntity> keyExtractor)
{
this.name = name;
comparator = Comparator.comparingDouble(keyExtractor);
}
public void testComparingDouble() {
Comparator<Item> comparator = Comparator.comparingDouble(Item::getOrderAsDouble);
checkComparison(comparator, orderedItems);
}
private Priority(String name,
ToDoubleFunction<LivingEntity> keyExtractor)
{
this.name = name;
comparator = Comparator.comparingDouble(keyExtractor);
}
private Priority(String name,
ToDoubleFunction<LivingEntity> keyExtractor)
{
this.name = name;
comparator = Comparator.comparingDouble(keyExtractor);
}
private Priority(String name,
ToDoubleFunction<EntityLivingBase> keyExtractor)
{
this.name = name;
comparator = Comparator.comparingDouble(keyExtractor);
}
/** Comparator that sorts cheaper units before expensive ones. */
public static Comparator<Unit> getCostComparator(final ProData proData) {
return Comparator.comparingDouble((unit) -> ProPurchaseUtils.getCost(proData, unit));
}