Poset extends PartiallyOrdered<Poset<C>> implements Iterable<C> { public static <C extends Comparable<?>> List<Poset<C>> singletons(final Collection<? extends C> collection) { List<Poset<C>> singletons = new ArrayList(); Poset previous = NULL; for(C element : collection) { List<C> set = new ArrayList<>(); set.add(element); Poset poset = new Poset(set); if(previous != NULL && poset.isComparableTo(previous)) { throw new IllegalArgumentException("singletons must be disjoint"); } singletons.add(poset); previous = poset; } return singletons; } 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 testSingletons() { List<Poset<String>> strings = Poset.singletons(Arrays.asList("a", "b", "c")); assertEquals(strings.size(), 3); assertEquals(strings.get(0), A); exception.expect(java.lang.IllegalArgumentException.class); strings = Poset.singletons(Arrays.asList("a", "a")); }