/** * Factory to create the predicate. * * @param <T> the type that the predicate queries * @return the predicate * @throws IllegalArgumentException if the predicate is null */ public static <T> Predicate<T> uniquePredicate() { return new UniquePredicate<>(); }
/** * Constructs a new <code>UniqueFilterIterator</code>. * * @param iterator the iterator to use */ public UniqueFilterIterator(final Iterator<? extends E> iterator) { super(iterator, UniquePredicate.uniquePredicate()); }
/** * Creates a Predicate that returns true the first time an object is * encountered, and false if the same object is received * again. The comparison is by equals(). A <code>null</code> input object * is accepted and will return true the first time, and false subsequently * as well. * * @param <T> the type that the predicate queries * @return the predicate * @see UniquePredicate */ public static <T> Predicate<T> uniquePredicate() { // must return new instance each time return UniquePredicate.uniquePredicate(); }
/** * Factory method to create an ordered set using the supplied list to retain order. * <p> * A <code>HashSet</code> is used for the set behaviour. * <p> * NOTE: If the list contains duplicates, the duplicates are removed, * altering the specified list. * * @param <E> the element type * @param list the list to decorate, must not be null * @return a new ordered set * @throws NullPointerException if list is null * @since 4.0 */ public static <E> ListOrderedSet<E> listOrderedSet(final List<E> list) { if (list == null) { throw new NullPointerException("List must not be null"); } CollectionUtils.filter(list, UniquePredicate.uniquePredicate()); final Set<E> set = new HashSet<>(list); return new ListOrderedSet<>(set, list); }