BooleanTerm extends HashSet<BooleanVar> { public BooleanTerm andWith(BooleanTerm other) { if (isFalse() || other.isFalse()) { return BooleanTerm.FALSE; } if (other.isTrue()) { return this; } if (isTrue()) { return other; } Set<BooleanVar> result = new HashSet<BooleanVar>(this); for (BooleanVar var : other) { if (result.contains(var.negate())) { return BooleanTerm.FALSE; } result.add(var); } return new BooleanTerm(result); } private  BooleanTerm();  BooleanTerm(BooleanVar var);  BooleanTerm(Set<BooleanVar> term);  BooleanTerm(String str); boolean isTrue(); boolean isFalse(); BooleanTerm resolveWith(Features features); BooleanTerm resolveWith(Features features, boolean coerceUndefinedToFalse); BooleanTerm andWith(BooleanTerm other); @Override String toString(); @Override boolean add(BooleanVar object); @Override void clear(); @Override boolean remove(Object object); @Override boolean removeAll(Collection<?> collection); @Override boolean addAll(Collection<? extends BooleanVar> collection); @Override boolean retainAll(Collection<?> collection); @Override int hashCode(); @Override boolean equals(Object other); static final BooleanTerm TRUE; static final BooleanTerm FALSE; }
@Test public void testAndWith() { assertEquals(BooleanTerm.TRUE, BooleanTerm.TRUE.andWith(BooleanTerm.TRUE)); assertEquals(BooleanTerm.FALSE, BooleanTerm.TRUE.andWith(BooleanTerm.FALSE)); assertEquals(new BooleanTerm("A*B"), BooleanTerm.TRUE.andWith(new BooleanTerm("A*B"))); assertEquals(BooleanTerm.FALSE, BooleanTerm.FALSE.andWith(BooleanTerm.TRUE)); assertEquals(BooleanTerm.FALSE, BooleanTerm.FALSE.andWith(BooleanTerm.FALSE)); assertEquals(BooleanTerm.FALSE, BooleanTerm.FALSE.andWith(new BooleanTerm("A*B"))); assertEquals(new BooleanTerm("A*B"), new BooleanTerm("A*B").andWith(BooleanTerm.TRUE)); assertEquals(BooleanTerm.FALSE, new BooleanTerm("A*B").andWith(BooleanTerm.FALSE)); assertEquals(new BooleanTerm("A*B"), new BooleanTerm("A*B").andWith(new BooleanTerm("A"))); assertEquals(new BooleanTerm("A*B"), new BooleanTerm("A").andWith(new BooleanTerm("A*B"))); assertEquals(new BooleanTerm("A*B"), new BooleanTerm("A*B").andWith(new BooleanTerm("A*B"))); assertEquals(new BooleanTerm("A*AB*B*BA"), new BooleanTerm("A*B").andWith(new BooleanTerm("AB*BA"))); assertEquals(BooleanTerm.FALSE, new BooleanTerm("A*B").andWith(new BooleanTerm("!A"))); assertEquals(BooleanTerm.FALSE, new BooleanTerm("!A").andWith(new BooleanTerm("A*B"))); assertEquals(BooleanTerm.FALSE, new BooleanTerm("A*B").andWith(new BooleanTerm("!A*!B"))); }