@Test void testAddAll() { Set<String> doesFill1 = ImmutableSet.of("coffee", "tea"); Set<String> doesFill2 = ImmutableSet.of("chocolate"); Set<String> overfill = ImmutableSet.of("Coke", "Pepsi"); Collection<String> coll = CappedSet.create(3); assertTrue(coll.addAll(doesFill1), "did not add items"); assertTrue(coll.addAll(doesFill2), "did not add items"); assertThrows(IllegalStateException.class, () -> coll.addAll(overfill), "items added to collection although it is too full"); assertEquals(3, coll.size(), "collection grew in size unexpectedly"); }
@Override public boolean addAll(Collection<? extends T> collection) { return this.standardAddAll(collection); }
CappedSet extends ForwardingSet<T> { @Override public boolean addAll(Collection<? extends T> collection) { return this.standardAddAll(collection); } }
CappedSet extends ForwardingSet<T> { @Override public boolean addAll(Collection<? extends T> collection) { return this.standardAddAll(collection); } private  CappedSet(Set<T> delegate, int upperSize); }
CappedSet extends ForwardingSet<T> { @Override public boolean addAll(Collection<? extends T> collection) { return this.standardAddAll(collection); } private  CappedSet(Set<T> delegate, int upperSize); static Set<T> create(int maxSize); @Override boolean add(T element); @Override boolean addAll(Collection<? extends T> collection); }
CappedSet extends ForwardingSet<T> { @Override public boolean addAll(Collection<? extends T> collection) { return this.standardAddAll(collection); } private  CappedSet(Set<T> delegate, int upperSize); static Set<T> create(int maxSize); @Override boolean add(T element); @Override boolean addAll(Collection<? extends T> collection);  }