use of games.strategy.triplea.util.UnitOwner in project triplea by triplea-game.
the class MyFormatter method unitsToText.
/**
* Converts the specified unit collection to a textual representation that describes the quantity of each distinct
* unit type owned by each distinct player.
*
* @param units The collection of units.
*
* @return A textual representation of the specified unit collection.
*/
public static String unitsToText(final Collection<Unit> units) {
checkNotNull(units);
final Map<UnitOwner, Long> quantitiesByOwner = units.stream().map(UnitOwner::new).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
final StringBuilder buf = new StringBuilder();
final AtomicInteger countRef = new AtomicInteger(quantitiesByOwner.size());
quantitiesByOwner.forEach((owner, quantity) -> {
buf.append(quantity);
buf.append(" ");
buf.append(quantity > 1 ? pluralize(owner.getType().getName()) : owner.getType().getName());
buf.append(" owned by the ");
buf.append(owner.getOwner().getName());
final int count = countRef.decrementAndGet();
if (count > 1) {
buf.append(", ");
} else if (count == 1) {
buf.append(" and ");
}
});
return buf.toString();
}
use of games.strategy.triplea.util.UnitOwner in project triplea by triplea-game.
the class BattleDisplay method updateKilledUnits.
/**
* updates the panel content according to killed units for the player.
*
* @param killedUnits
* list of units killed
* @param playerId
* player kills belongs to
*/
private Collection<Unit> updateKilledUnits(final Collection<Unit> killedUnits, final PlayerID playerId) {
final JPanel casualtyPanel;
if (playerId.equals(defender)) {
casualtyPanel = casualtiesInstantPanelDefender;
} else {
casualtyPanel = casualtiesInstantPanelAttacker;
}
Map<Unit, Collection<Unit>> dependentsMap;
gameData.acquireReadLock();
try {
dependentsMap = BattleCalculator.getDependents(killedUnits);
} finally {
gameData.releaseReadLock();
}
final Collection<Unit> dependentUnitsReturned = new ArrayList<>();
for (Collection<Unit> dependentCollection : dependentsMap.values()) {
dependentUnitsReturned.addAll(dependentCollection);
}
for (final UnitCategory category : UnitSeperator.categorize(killedUnits, dependentsMap, false, false)) {
final JPanel panel = new JPanel();
JLabel unit = uiContext.createUnitImageJLabel(category.getType(), category.getOwner());
panel.add(unit);
panel.add(new JLabel("x " + category.getUnits().size()));
for (final UnitOwner owner : category.getDependents()) {
unit = uiContext.createUnitImageJLabel(owner.getType(), owner.getOwner());
panel.add(unit);
// TODO this size is of the transport collection size, not the transportED collection size.
panel.add(new JLabel("x " + category.getUnits().size()));
}
casualtyPanel.add(panel);
}
return dependentUnitsReturned;
}
Aggregations