/** * 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 */ @Override public boolean add(final E 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 a collection of objects to the end of 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 coll the collection to add in iterator order * @return true if this collection changed */ @Override public boolean addAll(final Collection<? extends E> coll) { return addAll(size(), coll); }