/** * Adds an element to the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface requires that this method returns * <code>true</code> always. However this class may return <code>false</code> * because of the <code>Set</code> behaviour. * * @param object the object to add * @return true if object was added */ public boolean add(Object object) { // gets initial size final int sizeBefore = size(); // adds element if unique add(size(), object); // compares sizes to detect if collection changed return (sizeBefore != size()); }
/** * Adds an element to the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface requires that this method returns * <code>true</code> always. However this class may return <code>false</code> * because of the <code>Set</code> behaviour. * * @param object the object to add * @return true if object was added */ public boolean add(Object object) { // gets initial size final int sizeBefore = size(); // adds element if unique add(size(), object); // compares sizes to detect if collection changed return (sizeBefore != size()); }
/** * Adds an element to the end of the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the element is * always inserted. This may not happen with this implementation. * * @param coll the collection to add */ public boolean addAll(Collection coll) { return addAll(size(), coll); }
/** * Adds a collection of objects a specific index in the list avoiding * duplicates. * <p> * Only elements that are not already in this list will be added, and * duplicates from the specified collection will be ignored. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the elements * are always inserted. This may not happen with this implementation. * * @param index the index to insert at * @param coll the collection to add in iterator order * @return true if this collection changed */ public boolean addAll(int index, Collection coll) { // gets initial size final int sizeBefore = size(); // adds all elements for (final Iterator it = coll.iterator(); it.hasNext();) { int sizeBeforeAddNext = size(); add(index, it.next()); // if it was inserted, then increase the target index if (sizeBeforeAddNext != size()) { index++; } } // compares sizes to detect if collection changed return sizeBefore != size(); }
/** * Adds an element to the end of the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the element is * always inserted. This may not happen with this implementation. * * @param coll the collection to add */ public boolean addAll(Collection coll) { return addAll(size(), coll); }
/** * Adds a collection of objects a specific index in the list avoiding * duplicates. * <p> * Only elements that are not already in this list will be added, and * duplicates from the specified collection will be ignored. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the elements * are always inserted. This may not happen with this implementation. * * @param index the index to insert at * @param coll the collection to add in iterator order * @return true if this collection changed */ public boolean addAll(int index, Collection coll) { // gets initial size final int sizeBefore = size(); // adds all elements for (final Iterator it = coll.iterator(); it.hasNext();) { int sizeBeforeAddNext = size(); add(index, it.next()); // if it was inserted, then increase the target index if (sizeBeforeAddNext != size()) { index++; } } // compares sizes to detect if collection changed return sizeBefore != size(); }
public void testAddAll() { final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet()); lset.addAll( Arrays.asList(new Integer[] { new Integer(1), new Integer(1)})); assertEquals("Duplicate element was added.", 1, lset.size()); }
public void testAdd() { final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet()); // Duplicate element final Object obj = new Integer(1); lset.add(obj); lset.add(obj); assertEquals("Duplicate element was added.", 1, lset.size()); // Unique element lset.add(new Integer(2)); assertEquals("Unique element was not added.", 2, lset.size()); }
public void testListIterator() { final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet()); final Object obj1 = new Integer(1); final Object obj2 = new Integer(2); lset.add(obj1); lset.add(obj2); // Attempts to add a duplicate object for (final ListIterator it = lset.listIterator(); it.hasNext();) { it.next(); if (!it.hasNext()) { it.add(obj1); break; } } assertEquals("Duplicate element was added", 2, lset.size()); }
public void testFactory() { Integer[] array = new Integer[] {new Integer(1), new Integer(2), new Integer(1)}; ArrayList list = new ArrayList(Arrays.asList(array)); final SetUniqueList lset = SetUniqueList.decorate(list); assertEquals("Duplicate element was added.", 2, lset.size()); assertEquals(new Integer(1), lset.get(0)); assertEquals(new Integer(2), lset.get(1)); assertEquals(new Integer(1), list.get(0)); assertEquals(new Integer(2), list.get(1)); }
public void testCollections304() { List list = new LinkedList(); SetUniqueList decoratedList = SetUniqueList.decorate(list); String s1 = "Apple"; String s2 = "Lemon"; String s3 = "Orange"; String s4 = "Strawberry"; decoratedList.add(s1); decoratedList.add(s2); decoratedList.add(s3); assertEquals(3, decoratedList.size()); decoratedList.set(1, s4); assertEquals(3, decoratedList.size()); decoratedList.add(1, s4); assertEquals(3, decoratedList.size()); decoratedList.add(1, s2); assertEquals(4, decoratedList.size()); }
public void testSetCollections444() { final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet()); // Duplicate element final Integer obj1 = new Integer(1); final Integer obj2 = new Integer(2); lset.add(obj1); lset.add(obj2); lset.set(0, obj1); assertEquals(2, lset.size()); assertSame(obj1, lset.get(0)); assertSame(obj2, lset.get(1)); assertTrue(lset.contains(obj1)); assertTrue(lset.contains(obj2)); }
lset.add(obj2); lset.set(0, obj1); assertEquals(2, lset.size()); assertSame(obj1, lset.get(0)); assertSame(obj2, lset.get(1)); lset.add(obj2); lset.set(0, obj2); assertEquals(1, lset.size()); assertSame(obj2, lset.get(0)); lset.add(obj2); lset.set(0, obj3); assertEquals(2, lset.size()); assertSame(obj3, lset.get(0)); assertSame(obj2, lset.get(1)); lset.add(obj2); lset.set(1, obj1); assertEquals(1, lset.size()); assertSame(obj1, lset.get(0));
/** * Adds an element to the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface requires that this method returns * <code>true</code> always. However this class may return <code>false</code> * because of the <code>Set</code> behaviour. * * @param object the object to add * @return true if object was added */ public boolean add(Object object) { // gets initial size final int sizeBefore = size(); // adds element if unique add(size(), object); // compares sizes to detect if collection changed return (sizeBefore != size()); }
/** * Adds an element to the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface requires that this method returns * <code>true</code> always. However this class may return <code>false</code> * because of the <code>Set</code> behaviour. * * @param object the object to add * @return true if object was added */ public boolean add(Object object) { // gets initial size final int sizeBefore = size(); // adds element if unique add(size(), object); // compares sizes to detect if collection changed return (sizeBefore != size()); }
/** * Adds an element to the end of the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the element is * always inserted. This may not happen with this implementation. * * @param coll the collection to add */ public boolean addAll(Collection coll) { return addAll(size(), coll); }
/** * Adds an element to the end of the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the element is * always inserted. This may not happen with this implementation. * * @param coll the collection to add */ public boolean addAll(Collection coll) { return addAll(size(), coll); }
/** * Adds an element to the end of the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the element is * always inserted. This may not happen with this implementation. * * @param coll the collection to add */ public boolean addAll(Collection coll) { return addAll(size(), coll); }
/** * Adds an element to the end of the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the element is * always inserted. This may not happen with this implementation. * * @param coll the collection to add */ public boolean addAll(Collection coll) { return addAll(size(), coll); }
/** * Adds an element to the end of the list if it is not already present. * <p> * <i>(Violation)</i> * The <code>List</code> interface makes the assumption that the element is * always inserted. This may not happen with this implementation. * * @param coll the collection to add */ public boolean addAll(Collection coll) { return addAll(size(), coll); }