mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +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) {
|
public <T> ProbabilityCollection<T> map(Function<E, T> mapper, boolean carryNull) {
|
||||||
ProbabilityCollection<T> newCollection = new ProbabilityCollection<>();
|
ProbabilityCollection<T> newCollection = new ProbabilityCollection<>();
|
||||||
cont.forEach((o, count) -> {
|
newCollection.array = new Object[array.length];
|
||||||
if(o != null) newCollection.add(mapper.apply(o), count.get());
|
|
||||||
else if(carryNull) newCollection.add(null, count.get());
|
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;
|
return newCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user