当前位置: 首页>>代码示例>>Java>>正文


Java Comparator.comparingInt方法代码示例

本文整理汇总了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));
    }
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:21,代码来源:NameserviceHashTable.java

示例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);
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:20,代码来源:ULCCourseRequirements.java

示例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());
}
 
开发者ID:Devskiller,项目名称:jpa2ddl,代码行数:22,代码来源:FileResolver.java

示例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);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:23,代码来源:IndianSettlement.java

示例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();
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:23,代码来源:NewUnitPanel.java

示例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);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:21,代码来源:Player.java

示例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);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:15,代码来源:SimpleMapGenerator.java

示例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;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:22,代码来源:ServerIndianSettlement.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:BasicTest.java

示例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);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:23,代码来源:Player.java

示例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);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:14,代码来源:Tile.java

示例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;
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:36,代码来源:Scheduler.java

示例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();
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:17,代码来源:EuropeanAIPlayer.java

示例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]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:BasicTest.java

示例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);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:11,代码来源:Player.java


注:本文中的java.util.Comparator.comparingInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。