OneOrMore implements Iterable<T> { public boolean add(final T item) { if (null == collection) { if (null == singleItem) { singleItem = item; return true; } if (deduplicate && singleItem.equals(item)) { return false; } collection = newCollection.apply(singleItem); singleItem = null; } return collection.add(item); } OneOrMore();  OneOrMore(final boolean deduplicate);  OneOrMore(final boolean deduplicate, final T item); boolean add(final T item); boolean addAll(final Collection<? extends T> items); void removeAnyItem(); int size(); boolean isEmpty(); boolean contains(final Object o); @Override Iterator<T> iterator(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void shouldAddItemsWithDeduplicate() { final boolean deduplicate = true; final OneOrMore<Integer> collection = new OneOrMore<>(deduplicate); final Set<Integer> expectedItems = new HashSet<>(); IntStream.rangeClosed(1, 200).forEach(expectedItems::add); for (int i = 200; 0 < i; i--) { collection.add(i); collection.add(i); } assertEquals(expectedItems, Sets.newHashSet(collection)); }