/** * Create a Composite Collection with only coll composited. * * @param coll a collection to decorate */ public CompositeCollection(Collection coll) { this(); this.addComposited(coll); }
/** * Factory method to create an unmodifiable bounded collection. * * @param coll the <code>BoundedCollection</code> to decorate, must not be null * @return a new unmodifiable bounded collection * @throws IllegalArgumentException if bag is null */ public static BoundedCollection decorate(BoundedCollection coll) { return new UnmodifiableBoundedCollection(coll); }
/** * Factory method to create a synchronized collection. * * @param coll the collection to decorate, must not be null * @return a new synchronized collection * @throws IllegalArgumentException if collection is null */ public static Collection decorate(Collection coll) { return new SynchronizedCollection(coll); }
public void testToCollection() { setUpTest(); one.add("1"); two.add("2"); c.addComposited(one, two); Collection foo = c.toCollection(); assertTrue(foo.containsAll(c)); assertEquals(c.size(), foo.size()); one.add("3"); assertTrue(!foo.containsAll(c)); }
public void testRemove() { setUpMutatorTest(); one.add("1"); two.add("2"); two.add("1"); c.addComposited(one, two); c.remove("1"); assertTrue(!c.contains("1")); assertTrue(!one.contains("1")); assertTrue(!two.contains("1")); }
public void testIsEmpty() { setUpTest(); assertTrue(c.isEmpty()); HashSet empty = new HashSet(); c.addComposited(empty); assertTrue(c.isEmpty()); empty.add("a"); assertTrue(!c.isEmpty()); }
/** * Empty collection is empty composite */ public Collection makeCollection() { return new CompositeCollection(); }
public void testContainsAll() { setUpTest(); one.add("1"); two.add("1"); c.addComposited(one); assertTrue(c.containsAll(two)); }
/** * Returns an unmodifiable collection backed by the given collection. * <p> * This method uses the implementation in the decorators subpackage. * * @param collection the collection to make unmodifiable, must not be null * @return an unmodifiable collection backed by the given collection * @throws IllegalArgumentException if the collection is null */ public static Collection unmodifiableCollection(Collection collection) { return UnmodifiableCollection.decorate(collection); }
/** * Returns a typed collection backed by the given collection. * <p> * Only objects of the specified type can be added to the collection. * * @param collection the collection to limit to a specific type, must not be null * @param type the type of objects which may be added to the collection * @return a typed collection backed by the specified collection */ public static Collection typedCollection(Collection collection, Class type) { return TypedCollection.decorate(collection, type); }
/** * This can receive either a <code>CompositeCollection.CollectionMutator</code> * or a <code>CompositeSet.SetMutator</code>. If a * <code>CompositeCollection.CollectionMutator</code> is used than conflicts when adding * composited sets will throw IllegalArgumentException * <p> */ public void setMutator(CollectionMutator mutator) { super.setMutator(mutator); }
public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(TestCompositeCollection.suite()); suite.addTest(TestPredicatedCollection.suite()); suite.addTest(TestSynchronizedCollection.suite()); suite.addTest(TestTransformedCollection.suite()); suite.addTest(TestUnmodifiableCollection.suite()); return suite; }
/** * Resets the {@link #collection} and {@link #confirmed} fields to full * collections. Invoke this method before performing a modification * test. */ public void resetFull() { this.collection = makeFullCollection(); this.confirmed = makeConfirmedFullCollection(); }
/** * Resets the {@link #collection} and {@link #confirmed} fields to empty * collections. Invoke this method before performing a modification * test. */ public void resetEmpty() { this.collection = makeCollection(); this.confirmed = makeConfirmedCollection(); }
/** * Returns an array of elements that are <I>not</I> contained in a * full collection. Every element in the returned array must * not exist in a collection returned by {@link #makeFullCollection()}. * The default implementation returns a heterogenous array of elements * without null. Note that some of the tests add these elements * to an empty or full collection, so if your collection restricts * certain kinds of elements, you should override this method. */ public Object[] getOtherElements() { return getOtherNonNullElements(); }
/** * Returns an empty collection for Object tests. */ public Object makeObject() { return makeCollection(); }
/** * Create a CompositeCollection with colls as the initial list of * composited collections. * * @param colls an array of collections to decorate */ public CompositeCollection(Collection[] colls) { this(); this.addComposited(colls); }
public void testClear() { setUpTest(); one.add("1"); two.add("2"); c.addComposited(one, two); c.clear(); assertTrue(one.isEmpty()); assertTrue(two.isEmpty()); assertTrue(c.isEmpty()); }
/** * Add two additional collections to this composite. * * @param c the first collection to add * @param d the second collection to add */ public void addComposited(Collection c, Collection d) { this.addComposited(new Collection[]{c, d}); }
/** * Add an additional collection to this composite. * * @param c the collection to add */ public void addComposited(Collection c) { this.addComposited(new Collection[]{c}); }