本文整理汇总了Java中java.util.Comparator.comparingInt方法的典型用法代码示例。如果您正苦于以下问题:Java Comparator.comparingInt方法的具体用法?Java Comparator.comparingInt怎么用?Java Comparator.comparingInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Comparator
的用法示例。
在下文中一共展示了Comparator.comparingInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printSorted
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Print all tuples in IDHashTable sorted
*/
public final void printSorted() {
int iter;
Collection<Entry> list;
list = new TreeSet<>(Comparator.comparingInt(p_entryA -> p_entryA.m_key));
for (int i = 0; i < m_elementCapacity; i++) {
iter = getKey(i);
if (iter != 0) {
list.add(new Entry(iter, getValue(i)));
}
}
for (Entry entry : list) {
System.out.println("Key: " + entry.m_key + ", value: " + ChunkID.toHexString(entry.m_value));
}
}
示例2: toCourseRequirements
import java.util.Comparator; //导入方法依赖的package包/类
public CourseRequirements toCourseRequirements(HashMap<Integer, Shift> shifts) {
Set<Shift> requiredShifts = new TreeSet<>(Comparator.comparingInt(Shift::getId));
Map<Integer, Integer> numTutorsPerShift = new HashMap<>();
this.specifics.forEach(specific -> {
int shiftId = specific.getShiftId();
int numTutors = specific.getNumTutors();
Shift shift = shifts.get(shiftId);
if (shift != null) {
requiredShifts.add(shift);
numTutorsPerShift.put(shift.getId(), numTutors);
}
});
CourseIntensity intensity = CourseIntensity.fromString(this.intensity);
return new CourseRequirements(requiredShifts, this.timesPerWeek, 0, intensity, numTutorsPerShift, this.numTutors);
}
示例3: resolveExistingMigrations
import java.util.Comparator; //导入方法依赖的package包/类
static List<Path> resolveExistingMigrations(File migrationsDir, boolean reversed, boolean onlySchemaMigrations) {
if (!migrationsDir.exists()) {
migrationsDir.mkdirs();
}
File[] files = migrationsDir.listFiles();
if (files == null) {
return Collections.emptyList();
}
Comparator<Path> pathComparator = Comparator.comparingInt(FileResolver::compareVersionedMigrations);
if (reversed) {
pathComparator = pathComparator.reversed();
}
return Arrays.stream(files)
.map(File::toPath)
.filter(path -> !onlySchemaMigrations || SCHEMA_FILENAME_PATTERN.matcher(path.getFileName().toString()).matches())
.sorted(pathComparator)
.collect(Collectors.toList());
}
示例4: goodsToMake
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Chooses a type of goods for some of the natives in a settlement
* to manufacture.
* Simple rule: choose the refined goods that is the greatest shortage
* for which there is a surplus of the raw material.
*
* @return A {@code GoodsType} to manufacture, or null if
* none suitable.
*/
private GoodsType goodsToMake() {
final ToIntFunction<GoodsType> deficit = cacheInt(gt ->
getWantedGoodsAmount(gt) - getGoodsCount(gt));
final Predicate<GoodsType> goodsPred = gt ->
gt.isRawMaterial()
&& gt.getOutputType() != null
&& !gt.getOutputType().isBreedable()
&& gt.getOutputType().isStorable()
&& deficit.applyAsInt(gt) < 0
&& deficit.applyAsInt(gt.getOutputType()) > 0;
final Comparator<GoodsType> comp = Comparator.comparingInt(deficit);
return maximize(getSpecification().getGoodsTypeList(), goodsPred, comp);
}
示例5: NewUnitPanel
import java.util.Comparator; //导入方法依赖的package包/类
/**
* The constructor to use.
*
* @param freeColClient The {@code FreeColClient} for the game.
* @param layout The {@code LayoutManager} to use.
* @param label The label for the panel.
* @param units A list of {@code UnitType}s to offer.
*/
public NewUnitPanel(FreeColClient freeColClient, LayoutManager layout,
String label, List<UnitType> units) {
super(freeColClient, layout);
this.question = new JLabel(label);
this.units.addAll(units);
final Europe europe = getMyPlayer().getEurope();
this.priceComparator = Comparator.comparingInt((UnitType ut) ->
europe.getUnitPrice(ut));
okButton.setText(Messages.message("close"));
update();
}
示例6: getMostValuableGoods
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Get the most valuable goods available in one of the player's
* colonies for the purposes of choosing a threat-to-boycott. The
* goods must not currently be boycotted, the player must have
* traded in it, and the amount to be discarded will not exceed
* GoodsContainer.CARGO_SIZE.
*
* @return A goods object, or null if nothing suitable found.
*/
public Goods getMostValuableGoods() {
if (!isEuropean()) return null;
final Predicate<Goods> boycottPred = g ->
getArrears(g.getType()) <= 0 && hasTraded(g.getType());
final Comparator<Goods> tradedValueComp = Comparator.comparingInt(g ->
market.getSalePrice(g.getType(),
Math.min(g.getAmount(), GoodsContainer.CARGO_SIZE)));
return maximize(flatten(getColonies(),
c -> c.getCompactGoodsList().stream()),
boycottPred, tradedValueComp);
}
示例7: getClosestTerritory
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Find the closest territory to a given tile from a list of choices.
*
* @param tile The {@code Tile} to search from.
* @param territories The list of {@code Territory}s to choose from.
* @return The closest {@code Territory} found, or null if none.
*/
private Territory getClosestTerritory(final Tile tile,
List<Territory> territories) {
final Map map = tile.getMap();
final Comparator<Territory> comp = Comparator.comparingInt(t ->
map.getDistance(tile, t.getCenterTile(map)));
return minimize(territories, comp);
}
示例8: updateMostHated
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Updates the most hated nation of this settlement.
* Needs to be public so it can be set by backwards compatibility code
* in FreeColServer.loadGame.
*
* -til: This might change the tile appearance.
*
* @return True if the most hated nation changed.
*/
public boolean updateMostHated() {
final Player old = this.mostHated;
final Predicate<Player> hatedPred = p -> {
Tension alarm = getAlarm(p);
return alarm != null && alarm.getLevel() != Tension.Level.HAPPY;
};
final Comparator<Player> mostHatedComp
= Comparator.comparingInt(p -> getAlarm(p).getValue());
this.mostHated = maximize(getGame().getLiveEuropeanPlayers(),
hatedPred, mostHatedComp);
return this.mostHated != old;
}
示例9: testIntComparator
import java.util.Comparator; //导入方法依赖的package包/类
public void testIntComparator() {
Thing[] things = new Thing[intValues.length];
for (int i=0; i<intValues.length; i++)
things[i] = new Thing(intValues[i], 0L, 0.0, null);
Comparator<Thing> comp = Comparator.comparingInt(new ToIntFunction<Thing>() {
@Override
public int applyAsInt(Thing thing) {
return thing.getIntField();
}
});
assertComparisons(things, comp, comparisons);
}
示例10: getMostValuableGoods
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Get the most valuable goods available in one of the player's
* colonies for the purposes of choosing a threat-to-boycott. The
* goods must not currently be boycotted, the player must have
* traded in it, and the amount to be discarded will not exceed
* GoodsContainer.CARGO_SIZE.
*
* @return A goods object, or null if nothing suitable found.
*/
public Goods getMostValuableGoods() {
if (!isEuropean()) return null;
final Market market = getMarket();
if (market == null) return null;
final Predicate<Goods> boycottPred = g ->
getArrears(g.getType()) <= 0 && hasTraded(g.getType());
final Comparator<Goods> tradedValueComp = Comparator.comparingInt(g ->
market.getSalePrice(g.getType(),
Math.min(g.getAmount(), GoodsContainer.CARGO_SIZE)));
return maximize(flatten(getColonies(),
c -> c.getCompactGoodsList().stream()),
boycottPred, tradedValueComp);
}
示例11: getBestFoodProduction
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Get the best food type to produce here.
*
* @return The {@code AbstractGoods} to produce.
*/
public AbstractGoods getBestFoodProduction() {
final Comparator<AbstractGoods> goodsComp
= Comparator.comparingInt(ag ->
getPotentialProduction(ag.getType(), null));
return maximize(flatten(getType().getAvailableProductionTypes(true),
pt -> pt.getOutputs()),
AbstractGoods::isFoodType, goodsComp);
}
示例12: search
import java.util.Comparator; //导入方法依赖的package包/类
private static Set<Node> search(Node inputNode, int desiredCost) {
log.info("Searching at desiredCost: " + desiredCost);
frontier = new PriorityQueue<>(Comparator.comparingInt(Node::getCost));
explored = new HashSet<>();
frontier.add(inputNode);
Set<Node> success = new HashSet<>();
while (frontier.size() != 0) {
Node node = frontier.remove();
explored.add(node);
int parentCost = generateCost(node);
log.info("Removing from frontier with cost " + parentCost+ " | remaining nodes on frontier: " + frontier.size());
List<Node> successors = successors(node);
for (Node successor : successors) {
int cost = generateCost(successor);
if (cost <= desiredCost) {
success.add(successor);
if (success.size() >= GENERATE_SCHEDULE_SIZE) {
return success;
}
}
if (cost < parentCost && !frontier.contains(successor)) {
frontier.add(successor);
log.info("Adding to frontier | parentCost: " + parentCost + " | childCost: " + cost + " | remaining nodes on frontier: " + frontier.size());
}
}
}
return success.isEmpty() ? null : success;
}
示例13: getBestPlanTile
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Gets the best plan for a colony from the tipMap.
*
* @param colony The {@code Colony} to check.
* @return The tile with the best plan for a colony, or null if none found.
*/
public Tile getBestPlanTile(Colony colony) {
final Comparator<TileImprovementPlan> valueComp
= Comparator.comparingInt(TileImprovementPlan::getValue);
final Function<Tile, TileImprovementPlan> tileMapper = t ->
tipMap.get(t);
TileImprovementPlan best
= maximize(map(colony.getOwnedTiles(), tileMapper),
isNotNull(), valueComp);
return (best == null) ? null : best.getTarget();
}
示例14: testMaxBy
import java.util.Comparator; //导入方法依赖的package包/类
public void testMaxBy() {
Comparator<People> cmp = Comparator.comparing(People::getFirstName);
// lesser
assertSame(maxBy(cmp).apply(people[0], people[1]), people[1]);
// euqal
cmp = Comparator.comparing(People::getLastName);
assertSame(maxBy(cmp).apply(people[0], people[1]), people[0]);
// greater
cmp = Comparator.comparingInt(People::getAge);
assertSame(maxBy(cmp).apply(people[0], people[1]), people[0]);
}
示例15: getClosestPortForEurope
import java.util.Comparator; //导入方法依赖的package包/类
/**
* Gets the port closest to Europe owned by this player.
*
* @return This players closest port.
*/
public Settlement getClosestPortForEurope() {
final Comparator<Settlement> comp
= Comparator.comparingInt(Settlement::getHighSeasCount);
return minimize(getSettlements(), comp);
}