use of org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap in project robozonky by RoboZonky.
the class Util method rankRatingsByDemand.
public static Stream<Rating> rankRatingsByDemand(final ParsedStrategy strategy, final Map<Rating, BigDecimal> currentShare) {
final SortedMap<BigDecimal, EnumSet<Rating>> mostWantedRatings = new TreeSortedMap<>(Comparator.reverseOrder());
// put the ratings into buckets based on how much we're missing them
currentShare.forEach((r, currentRatingShare) -> {
final BigDecimal maximumAllowedShare = toDecimalShare(strategy.getMaximumShare(r));
final BigDecimal undershare = maximumAllowedShare.subtract(currentRatingShare);
if (undershare.signum() < 1) {
// we over-invested into this rating; do not include
final BigDecimal pp = undershare.multiply(ONE_HUNDRED).negate();
Decisions.report(logger -> logger.debug("Rating {} over-invested by {} percentage points.", r, pp));
return;
}
mostWantedRatings.compute(undershare, (k, v) -> {
// rank the rating
if (v == null) {
return EnumSet.of(r);
}
v.add(r);
return v;
});
final BigDecimal minimumNeededShare = toDecimalShare(strategy.getMinimumShare(r));
if (currentRatingShare.compareTo(minimumNeededShare) < 0) {
// inform that the rating is under-invested
final BigDecimal pp = minimumNeededShare.subtract(currentRatingShare).multiply(ONE_HUNDRED);
Decisions.report(logger -> logger.debug("Rating {} under-invested by {} percentage points.", r, pp));
}
});
return mostWantedRatings.values().stream().flatMap(Collection::stream);
}
use of org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap in project eclipse-collections by eclipse.
the class ImmutableTreeMapTest method entrySet.
@Override
public void entrySet() {
super.entrySet();
Interval interval = Interval.oneTo(100);
LazyIterable<Pair<String, Integer>> pairs = interval.collect(Object::toString).zip(interval);
MutableSortedMap<String, Integer> mutableSortedMap = new TreeSortedMap<>(pairs.toArray(new Pair[] {}));
ImmutableSortedMap<String, Integer> immutableSortedMap = mutableSortedMap.toImmutable();
MutableList<Map.Entry<String, Integer>> entries = FastList.newList(immutableSortedMap.castToSortedMap().entrySet());
MutableList<Map.Entry<String, Integer>> sortedEntries = entries.toSortedListBy(Map.Entry::getKey);
Assert.assertEquals(sortedEntries, entries);
}
Aggregations