Beispiel #1
0
 /**
  * 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<E>(list, new HashSet<E>());
   }
   final List<E> temp = new ArrayList<E>(list);
   list.clear();
   final SetUniqueList<E> sl = new SetUniqueList<E>(list, new HashSet<E>());
   sl.addAll(temp);
   return sl;
 }