final boolean forEachWhile(BiPredicate<? super K, ? super V> predicate) { for (long a, tail, allocations = (a = ~bitSet) << (tail = Long.numberOfLeadingZeros(a)), allocIndex = 64 - tail; allocations != 0; allocations <<= 1, allocIndex--) { if (allocations < 0 && !predicate.test(this.<K>readKey(allocIndex), this.<V>readValue(allocIndex))) { return false; } } return true; }
final int removeIf( SmoothieMap<K, V> map, BiPredicate<? super K, ? super V> filter, int modCount) { if (isEmpty()) return modCount; long startSlot = 0; while (readSlot(startSlot) != 0) { startSlot++; } for (long slotIndex = startSlot + 1, slot, allocIndex; slotIndex != startSlot; slotIndex = nextSlotIndex(slotIndex)) { if ((slot = readSlot(slotIndex)) != 0) { if (filter.test(readKey((allocIndex = allocIndex(slot))), readValue(allocIndex))) { if (remove(map, slotIndex, allocIndex)) slotIndex = prevSlotIndex(slotIndex); modCount++; } } } return modCount; }
@Test public void canAdaptPredicate() { final Predicate<Pair<O, O>> predicate = new Always<>(); final BiPredicate<O, O> adapted = Tuples.Pairs.untupled(predicate); Assert.assertTrue(adapted.test(O.IGNORED, O.IGNORED)); }