mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
fix funny ProbabilityCollection bug
This commit is contained in:
parent
68aa38a51a
commit
e0d7b03820
@ -49,10 +49,14 @@ public class ProbabilityCollection<E> implements Collection<E> {
|
||||
|
||||
public <T> ProbabilityCollection<T> map(Function<E, T> mapper, boolean carryNull) {
|
||||
ProbabilityCollection<T> newCollection = new ProbabilityCollection<>();
|
||||
cont.forEach((o, count) -> {
|
||||
if(o != null) newCollection.add(mapper.apply(o), count.get());
|
||||
else if(carryNull) newCollection.add(null, count.get());
|
||||
});
|
||||
newCollection.array = new Object[array.length];
|
||||
|
||||
Map<E, T> cache = new HashMap<>();
|
||||
|
||||
for(int i = 0; i < array.length; i++) {
|
||||
if(carryNull && array[i] == null) continue;
|
||||
newCollection.array[i] = cache.computeIfAbsent((E) array[i], mapper);
|
||||
}
|
||||
return newCollection;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user