/** * 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); }
/** * Factory method to create a SetList using the supplied list to retain order. * <p> * If the list contains duplicates, these are removed (first indexed one * kept). A <code>HashSet</code> is used for the set behaviour. * * @param <E> the element type * @param list the list to decorate, must not be null * @return a new {@link SetUniqueList} * @throws NullPointerException if list is null * @since 4.0 */ public static <E> SetUniqueList<E> setUniqueList(final List<E> list) { if (list == null) { throw new NullPointerException("List must not be null"); } if (list.isEmpty()) { return new SetUniqueList<>(list, new HashSet<E>()); } final List<E> temp = new ArrayList<>(list); list.clear(); final SetUniqueList<E> sl = new SetUniqueList<>(list, new HashSet<E>()); sl.addAll(temp); return sl; }