diff --git a/eclipse-collections/src/main/java/org/eclipse/collections/impl/map/strategy/mutable/UnifiedMapWithHashingStrategy.java b/eclipse-collections/src/main/java/org/eclipse/collections/impl/map/strategy/mutable/UnifiedMapWithHashingStrategy.java index 50bfc34059..e6a5289c93 100644 --- a/eclipse-collections/src/main/java/org/eclipse/collections/impl/map/strategy/mutable/UnifiedMapWithHashingStrategy.java +++ b/eclipse-collections/src/main/java/org/eclipse/collections/impl/map/strategy/mutable/UnifiedMapWithHashingStrategy.java @@ -28,6 +28,8 @@ import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.block.function.Function0; import org.eclipse.collections.api.block.function.Function2; +import org.eclipse.collections.api.block.predicate.Predicate; +import org.eclipse.collections.api.block.predicate.Predicate2; import org.eclipse.collections.api.block.procedure.Procedure; import org.eclipse.collections.api.block.procedure.Procedure2; import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure; @@ -1711,6 +1713,117 @@ else if (this.table[i] != null) return target; } + private boolean shortCircuit( + Predicate predicate, + boolean expected, + boolean onShortCircuit, + boolean atEnd) + { + for (int i = 0; i < this.table.length; i += 2) + { + if (this.table[i] == CHAINED_KEY) + { + Object[] chainedTable = (Object[]) this.table[i + 1]; + for (int j = 0; j < chainedTable.length; j += 2) + { + if (chainedTable[j] != null) + { + V value = (V) chainedTable[j + 1]; + if (predicate.accept(value) == expected) + { + return onShortCircuit; + } + } + } + } + else if (this.table[i] != null) + { + V value = (V) this.table[i + 1]; + + if (predicate.accept(value) == expected) + { + return onShortCircuit; + } + } + } + + return atEnd; + } + + private

boolean shortCircuitWith( + Predicate2 predicate, + P parameter, + boolean expected, + boolean onShortCircuit, + boolean atEnd) + { + for (int i = 0; i < this.table.length; i += 2) + { + if (this.table[i] == CHAINED_KEY) + { + Object[] chainedTable = (Object[]) this.table[i + 1]; + for (int j = 0; j < chainedTable.length; j += 2) + { + if (chainedTable[j] != null) + { + V value = (V) chainedTable[j + 1]; + if (predicate.accept(value, parameter) == expected) + { + return onShortCircuit; + } + } + } + } + else if (this.table[i] != null) + { + V value = (V) this.table[i + 1]; + + if (predicate.accept(value, parameter) == expected) + { + return onShortCircuit; + } + } + } + + return atEnd; + } + + @Override + public boolean anySatisfy(Predicate predicate) + { + return this.shortCircuit(predicate, true, true, false); + } + + @Override + public

boolean anySatisfyWith(Predicate2 predicate, P parameter) + { + return this.shortCircuitWith(predicate, parameter, true, true, false); + } + + @Override + public boolean allSatisfy(Predicate predicate) + { + return this.shortCircuit(predicate, false, false, true); + } + + @Override + public

boolean allSatisfyWith(Predicate2 predicate, P parameter) + { + return this.shortCircuitWith(predicate, parameter, false, false, true); + } + + @Override + public boolean noneSatisfy(Predicate predicate) + { + return this.shortCircuit(predicate, true, false, true); + } + + @Override + public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) + { + return this.shortCircuitWith(predicate, parameter, true, false, true); + } + protected class KeySet implements Set, Serializable, BatchIterable { private static final long serialVersionUID = 1L;