/** * Evaluates the predicate returning the opposite to the stored predicate. * * @param object the input object * @return true if predicate returns false */ @Override public boolean evaluate(final T object) { return !iPredicate.evaluate(object); }
/** * Evaluates the predicate returning the result of the decorated predicate * once a null check is performed. * * @param object the input object * @return true if decorated predicate returns true or input is null */ @Override public boolean evaluate(final T object) { if (object == null) { return true; } return iPredicate.evaluate(object); }
/** * Evaluates the predicate returning the result of the decorated predicate * once a null check is performed. * * @param object the input object * @return true if decorated predicate returns true, false if input is null */ @Override public boolean evaluate(final T object) { if (object == null) { return false; } return iPredicate.evaluate(object); }
/** * Evaluates the predicate returning true if any predicate returns true. * * @param object the input object * @return true if any decorated predicate return true */ @Override public boolean evaluate(final T object) { for (final Predicate<? super T> iPredicate : iPredicates) { if (iPredicate.evaluate(object)) { return true; } } return false; }
/** * Evaluates the predicate returning true if all predicates return true. * * @param object the input object * @return true if all decorated predicates return true */ @Override public boolean evaluate(final T object) { for (final Predicate<? super T> iPredicate : iPredicates) { if (!iPredicate.evaluate(object)) { return false; } } return true; }
/** * Evaluates the predicate returning false if any stored predicate returns false. * * @param object the input object * @return true if none of decorated predicates return true */ @Override public boolean evaluate(final T object) { for (final Predicate<? super T> iPredicate : iPredicates) { if (iPredicate.evaluate(object)) { return false; } } return true; }
/** * Evaluates the predicate returning true if only one decorated predicate * returns true. * * @param object the input object * @return true if only one decorated predicate returns true */ @Override public boolean evaluate(final T object) { boolean match = false; for (final Predicate<? super T> iPredicate : iPredicates) { if (iPredicate.evaluate(object)) { if (match) { return false; } match = true; } } return match; }
/** * Transforms the input to result by calling a predicate. * * @param input the input object to transform * @return the transformed result */ @Override public Boolean transform(final T input) { return Boolean.valueOf(iPredicate.evaluate(input)); }
/** * Validates a key value pair. * * @param key the key to validate * @param value the value to validate * @throws IllegalArgumentException if invalid */ protected void validate(final K key, final V value) { if (keyPredicate != null && keyPredicate.evaluate(key) == false) { throw new IllegalArgumentException("Cannot add key - Predicate rejected it"); } if (valuePredicate != null && valuePredicate.evaluate(value) == false) { throw new IllegalArgumentException("Cannot add value - Predicate rejected it"); } }
/** * Validates the object being added to ensure it matches the predicate. * <p> * The predicate itself should not throw an exception, but return false to * indicate that the object cannot be added. * * @param object the object being added * @throws IllegalArgumentException if the add is invalid */ protected void validate(final E object) { if (predicate.evaluate(object) == false) { throw new IllegalArgumentException("Cannot add Object '" + object + "' - Predicate '" + predicate + "' rejected it"); } }
/** * Override to validate an object set into the map via <code>setValue</code>. * * @param value the value to validate * @return the value itself * @throws IllegalArgumentException if invalid * @since 3.1 */ @Override protected V checkSetValue(final V value) { if (valuePredicate.evaluate(value) == false) { throw new IllegalArgumentException("Cannot set value - Predicate rejected it"); } return value; }
/** * Set nextObject to the next object. If there are no more * objects then return false. Otherwise, return true. */ private boolean setNextObject() { while (iterator.hasNext()) { final E object = iterator.next(); if (predicate.evaluate(object)) { nextObject = object; nextObjectSet = true; return true; } } return false; }
/** * Adds the item to the builder. * <p> * If the predicate is true, it is added to the list of accepted elements, * otherwise it is added to the rejected list. * * @param item the element to add * @return the PredicatedCollectionBuilder. */ public Builder<E> add(final E item) { if (predicate.evaluate(item)) { accepted.add(item); } else { rejected.add(item); } return this; }
/** * Selects all elements from input collection which match the given * predicate and adds them to outputCollection. * <p> * If the input collection or predicate is null, there is no change to the * output collection. * * @param <O> the type of object the {@link Iterable} contains * @param <R> the type of the output {@link Collection} * @param inputCollection the collection to get the input from, may be null * @param predicate the predicate to use, may be null * @param outputCollection the collection to output into, may not be null if the inputCollection * and predicate or not null * @return the outputCollection */ public static <O, R extends Collection<? super O>> R select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection) { if (inputCollection != null && predicate != null) { for (final O item : inputCollection) { if (predicate.evaluate(item)) { outputCollection.add(item); } } } return outputCollection; }
/** * Selects all elements from inputCollection which don't match the given * predicate and adds them to outputCollection. * <p> * If the input predicate is <code>null</code>, no elements are added to * <code>outputCollection</code>. * * @param <O> the type of object the {@link Iterable} contains * @param <R> the type of the output {@link Collection} * @param inputCollection the collection to get the input from, may be null * @param predicate the predicate to use, may be null * @param outputCollection the collection to output into, may not be null if the inputCollection * and predicate or not null * @return outputCollection */ public static <O, R extends Collection<? super O>> R selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate, final R outputCollection) { if (inputCollection != null && predicate != null) { for (final O item : inputCollection) { if (!predicate.evaluate(item)) { outputCollection.add(item); } } } return outputCollection; }
/** * Finds the first index in the given List which matches the given predicate. * <p> * If the input List or predicate is null, or no element of the List * matches the predicate, -1 is returned. * * @param <E> the element type * @param list the List to search, may be null * @param predicate the predicate to use, may be null * @return the first index of an Object in the List which matches the predicate or -1 if none could be found */ public static <E> int indexOf(final List<E> list, final Predicate<E> predicate) { if (list != null && predicate != null) { for (int i = 0; i < list.size(); i++) { final E item = list.get(i); if (predicate.evaluate(item)) { return i; } } } return -1; }
/** * Evaluates the predicate returning the result of the decorated predicate * once the input has been transformed * * @param object the input object which will be transformed * @return true if decorated predicate returns true */ @Override public boolean evaluate(final T object) { final T result = iTransformer.transform(object); return iPredicate.evaluate(result); }
private <T extends Abi.Entry> T find(Class<T> resultClass, final Abi.Entry.Type type, final Predicate<T> searchPredicate) { return (T) CollectionUtils.find(this, entry -> entry.type == type && searchPredicate.evaluate((T) entry)); }