/** * Decorates the given queue with validating behavior using the predicate. All accepted elements * are appended to the queue. If the queue already contains elements, they are validated. * <p> * The builder is not modified by this method, so it is possible to create more collections * or add more elements afterwards. Further changes will not propagate to the returned queue. * * @param queue the queue to decorate, must not be null * @return the decorated queue. * @throws NullPointerException if queue is null * @throws IllegalArgumentException if queue contains invalid elements */ public Queue<E> createPredicatedQueue(final Queue<E> queue) { if (queue == null) { throw new NullPointerException("queue must not be null"); } final PredicatedQueue<E> predicatedQueue = PredicatedQueue.predicatedQueue(queue, predicate); predicatedQueue.addAll(accepted); return predicatedQueue; }