Java Code Examples for java.util.Comparator#comparingDouble()

The following examples show how to use java.util.Comparator#comparingDouble() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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);
}
 
Example 2
@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);
	}
}
 
Example 3
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);
}
 
Example 4
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);
}
 
Example 5
Source Project: jdk8u60   File: BasicTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 6
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);
}
 
Example 7
@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);
	}
}
 
Example 8
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);
}
 
Example 9
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);
}
 
Example 10
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);
}
 
Example 11
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);
}
 
Example 12
Source Project: hottub   File: BasicTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 13
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);
}
 
Example 14
private Priority(String name,
	ToDoubleFunction<LivingEntity> keyExtractor)
{
	this.name = name;
	comparator = Comparator.comparingDouble(keyExtractor);
}
 
Example 15
private Priority(String name,
	ToDoubleFunction<LivingEntity> keyExtractor)
{
	this.name = name;
	comparator = Comparator.comparingDouble(keyExtractor);
}
 
Example 16
Source Project: j2objc   File: ComparatorTest.java    License: Apache License 2.0 4 votes vote down vote up
public void testComparingDouble() {
    Comparator<Item> comparator = Comparator.comparingDouble(Item::getOrderAsDouble);
    checkComparison(comparator, orderedItems);
}
 
Example 17
private Priority(String name,
	ToDoubleFunction<LivingEntity> keyExtractor)
{
	this.name = name;
	comparator = Comparator.comparingDouble(keyExtractor);
}
 
Example 18
private Priority(String name,
	ToDoubleFunction<LivingEntity> keyExtractor)
{
	this.name = name;
	comparator = Comparator.comparingDouble(keyExtractor);
}
 
Example 19
private Priority(String name,
	ToDoubleFunction<EntityLivingBase> keyExtractor)
{
	this.name = name;
	comparator = Comparator.comparingDouble(keyExtractor);
}
 
Example 20
/** Comparator that sorts cheaper units before expensive ones. */
public static Comparator<Unit> getCostComparator(final ProData proData) {
  return Comparator.comparingDouble((unit) -> ProPurchaseUtils.getCost(proData, unit));
}