/** * Adds each object of the collection to the end of the list. * If {@link #isUnique uniqueness} is required, * duplicates will be {@link #getNonDuplicates removed} from the collection, * which could even result in an empty collection. * This implementation delegates to {@link #addAllUnique(Collection) addAllUnique(Collection)} * after uniqueness checking. * @param collection the collection of objects to be added. * @see #addAllUnique(Collection) */ @Override public boolean addAll(Collection<? extends E> collection) { if (isUnique()) { collection = getNonDuplicates(collection); } return addAllUnique(collection); }
/** * Throws an exception. * @exception UnsupportedOperationException always because it's not supported. */ @Override public void set(E1 object) { throw new UnsupportedOperationException(); }
/** * Adds the object at the end of the list * and returns whether the object was added; * if {@link #isUnique uniqueness} is required, * duplicates will be ignored and <code>false</code> will be returned. * This implementation delegates to {@link #addUnique(Object) addUnique(E)} * after uniqueness checking. * @param object the object to be added. * @return whether the object was added. * @see #addUnique(Object) */ @Override public boolean add(E object) { if (isUnique() && contains(object)) { return false; } else { addUnique(object); return true; } }
/** * Adds the object at the given index in the list. * If {@link #isUnique uniqueness} is required, * duplicates will be ignored. * This implementation delegates to {@link #addUnique(int, Object) addUnique(int, E)} * after uniqueness checking. * @param object the object to be added. * @exception IllegalArgumentException if {@link #isUnique uniqueness} is required, * and the object is a duplicate. * @see #addUnique(int, Object) */ @Override public void add(int index, E object) { int size = size(); if (index > size) throw new BasicIndexOutOfBoundsException(index, size); if (isUnique() && contains(object)) { throw new IllegalArgumentException("The 'no duplicates' constraint is violated"); } addUnique(index, object); }
/** * Adds each object of the collection at each successive index in the list * and returns whether any objects were added. * If {@link #isUnique uniqueness} is required, * duplicates will be {@link #getNonDuplicates removed} from the collection, * which could even result in an empty collection. * This implementation delegates to {@link #addAllUnique(int, Collection) addAllUnique(int, Collection)} * after uniqueness checking. * @param index the index at which to add. * @param collection the collection of objects to be added. * @return whether any objects were added. * @see #addAllUnique(int, Collection) */ @Override public boolean addAll(int index, Collection<? extends E> collection) { int size = size(); if (index > size) throw new BasicIndexOutOfBoundsException(index, size); if (isUnique()) { collection = getNonDuplicates(collection); } return addAllUnique(index, collection); }