public BooleanHashSet select(BooleanPredicate predicate) { BooleanHashSet set = new BooleanHashSet(); switch (this.state) { case 0: return set; case 1: if (predicate.accept(false)) { set.add(false); } return set; case 2: if (predicate.accept(true)) { set.add(true); } return set; case 3: if (predicate.accept(false)) { set.add(false); } if (predicate.accept(true)) { set.add(true); } return set; default: throw new AssertionError("Invalid state"); } }
@Test public void toSet() { MutableObjectBooleanMap<String> map1 = this.newWithKeysValues("1", false, null, true, "2", false); MutableObjectBooleanMap<String> map0 = this.newWithKeysValues("1", false, null, true, "2", true); MutableObjectBooleanMap<String> map2 = this.newWithKeysValues("0", true); MutableObjectBooleanMap<String> map3 = this.newWithKeysValues("0", false); Assert.assertEquals(BooleanHashSet.newSetWith(false, true), map1.toSet()); Assert.assertEquals(BooleanHashSet.newSetWith(false, true), map0.toSet()); Assert.assertEquals(BooleanHashSet.newSetWith(true), map2.toSet()); Assert.assertEquals(BooleanHashSet.newSetWith(false), map3.toSet()); }
public static BooleanHashSet newSet(BooleanIterable source) { if (source instanceof BooleanHashSet) { return new BooleanHashSet((BooleanHashSet) source); } return BooleanHashSet.newSetWith(source.toArray()); }
public boolean removeAll(boolean... source) { if (this.isEmpty() || source.length == 0) { return false; } BooleanHashSet set = BooleanHashSet.newSetWith(source); if (set.size() == 2) { this.items = null; this.size = 0; return true; } int oldSize = this.size; int trueCount = this.getTrueCount(); if (set.contains(true)) { this.size -= trueCount; this.items.set(0, this.size, false); } else { this.size = trueCount; this.items.set(0, this.size, true); } return oldSize != this.size; }
public MutableBooleanSet toSet() { return BooleanHashSet.newSet(this); }
public static BooleanHashSet newSetWith(boolean... source) { BooleanHashSet hashSet = new BooleanHashSet(); hashSet.addAll(source); return hashSet; }
@Test public void toSet() { Assert.assertEquals( BooleanHashSet.newSetWith(true, false, true), this.classUnderTest().toSet()); }