use of games.strategy.engine.data.DefaultNamed in project triplea by triplea-game.
the class MyFormatter method defaultNamedToTextList.
public static String defaultNamedToTextList(final Collection<? extends DefaultNamed> list, final String seperator, final boolean showQuantity) {
final IntegerMap<DefaultNamed> map = new IntegerMap<>();
for (final DefaultNamed unit : list) {
if (unit == null || unit.getName() == null) {
throw new IllegalStateException("Unit or Resource no longer exists?!?");
}
map.add(unit, 1);
}
final StringBuilder buf = new StringBuilder();
// sort on unit name
final List<DefaultNamed> sortedList = new ArrayList<>(map.keySet());
sortedList.sort(Comparator.comparing(DefaultNamed::getName));
int count = map.keySet().size();
for (final DefaultNamed type : sortedList) {
if (showQuantity) {
final int quantity = map.getInt(type);
buf.append(quantity);
buf.append(" ");
buf.append(quantity > 1 ? pluralize(type.getName()) : type.getName());
} else {
buf.append(type.getName());
}
count--;
if (count > 1) {
buf.append(seperator);
}
if (count == 1) {
buf.append(" and ");
}
}
return buf.toString();
}
use of games.strategy.engine.data.DefaultNamed in project triplea by triplea-game.
the class MyFormatter method integerDefaultNamedMapToString.
public static String integerDefaultNamedMapToString(final IntegerMap<? extends DefaultNamed> map, final String separator, final String assignment, final boolean valueBeforeKey) {
final StringBuilder buf = new StringBuilder();
for (final Entry<? extends DefaultNamed, Integer> entry : map.entrySet()) {
buf.append(separator);
final DefaultNamed current = entry.getKey();
final int val = entry.getValue();
if (valueBeforeKey) {
buf.append(val).append(assignment).append(current.getName());
} else {
buf.append(current.getName()).append(assignment).append(val);
}
}
return buf.toString().replaceFirst(separator, "");
}
Aggregations