Poset extends PartiallyOrdered<Poset<C>> implements Iterable<C> { @Override public Poset<C> intersect(final Poset<C> that) { if(this == MAGIC || that == NULL) { return that; } if(this == NULL) { return NULL; } if(that == MAGIC) { return new Poset(collection); } List<C> intersection = new ArrayList<>(collection); intersection.retainAll(that.collection); return new Poset(intersection); } Poset(final List<C> list);  Poset(); @Override boolean isLessOrEqualTo(final Poset that); @Override boolean isLessThan(final Poset that); @Override boolean isGreaterThan(final Poset that); @Override boolean isGreaterOrEqualTo(final Poset that); static List<Poset<C>> singletons(final Collection<? extends C> collection); static List<Poset<C>> cartesianProduct(Poset<C>...posets); static List<Poset<C>> cartesianProduct(List<Poset<C>> posets); @Override Poset<C> intersect(final Poset<C> that); @Override Poset<C> union(final Poset<C> that); Poset<C> coalesce(final Poset<C> that); @Override double measure(); @Override String toString(); @Override boolean equals(final Object right); @Override int hashCode(); @Override Iterator<C> iterator(); public List<C> collection; final static Poset NULL; final static Poset MAGIC; }
@Test public void testIntersect() { assertEquals(A.intersect(B), Poset.NULL); assertEquals(A.intersect(A), A); assertEquals(ABC.intersect(AD), A); assertEquals(Poset.MAGIC.intersect(Poset.NULL), Poset.NULL); }