/** * Returns a predicate that evaluates to {@code true} if all or none of the * component predicates evaluate to {@code true}. The components are * evaluated in order, and evaluation will end if a predicate result * fails to match the first predicate's result. * * @param <T> the type of values evaluated by the predicates. * @param first initial component predicate to be evaluated. * @param second additional component predicate to be evaluated. * @return a predicate that evaluates to {@code true} if all or none of the * component predicates evaluate to {@code true} */ public static <T, P extends Predicate<? super T>> Predicate<T> xor(final Predicate<T> first, final P second) { if(null != first && first == second) { return alwaysFalse(); } Objects.requireNonNull(first); Objects.requireNonNull(second); return new Predicate<T>() { @Override public boolean test(final T t) { //noinspection ConstantConditions return first.test(t) ^ second.test(t); } }; }
/** * Returns a predicate who's result matches * {@code Objects.equals(target, t)}. * * @param <T> the type of predicate values. * @param target The target value to be compared for equality. * @return a predicate who's result matches {@code Objects.equals(target, t)} */ public static <T> Predicate<T> isEqual(final T target) { if (null == target) return Predicates.isNull(); return new Predicate<T>() { @Override public boolean test(final T t) { return target.equals(t); } }; }
/** * Returns a predicate that evaluates to {@code true} if any of the * component predicates evaluate to {@code true}. The components are * evaluated in order, and evaluation will end upon the first * {@code true} predicate. * * @param <T> the type of values evaluated by the predicates. * @param components The predicates to be evaluated. A copy is made of the * components. * @return A predicate who's result is {@code true} if any component * predicate's result is {@code true}. */ static <T, P extends Predicate<? super T>> Predicate<T> or(final P first, final Iterable<P> components) { final List<P> predicates = safeCopyOf(first, components); return new Predicate<T>() { @Override public boolean test(final T t) { for (final P predicate : predicates) { if (predicate.test(t)) { return true; } } return false; } }; }
public Iterable<R> where(final Predicate<? super R> filter) { if (this.selector != null) { return new WhereSelectIterableIterator<>(this, filter, null); } return new WhereSelectIterableIterator<>( this.source, Predicates.and((Predicate<T>) this.filter, (Predicate<T>) filter), null ); }
Predicates.or( Predicates.<AstNode>instanceOf(MethodDeclaration.class), Predicates.<AstNode>instanceOf(LambdaExpression.class)
body.contains(nextBlock) && nextBlock.getBody().get(0) == nextLabel.get() && !CollectionUtilities.any(nextBlock.getBody(), Predicates.instanceOf(BasicBlock.class))) {
public static List<MethodReference> findMethods( final TypeReference type, final Predicate<? super MethodReference> filter) { return findMethods(type, filter, false); }
public static <T extends MemberReference> Predicate<T> matchNameAndSignature(final String name, final String signature) { return Predicates.and(MetadataFilters.<T>matchName(name), matchSignature(signature)); } }
Predicates.or( Predicates.<AstNode>instanceOf(MethodDeclaration.class), Predicates.<AstNode>instanceOf(LambdaExpression.class)
body.contains(nextBlock) && nextBlock.getBody().get(0) == nextLabel.get() && !CollectionUtilities.any(nextBlock.getBody(), Predicates.instanceOf(BasicBlock.class))) {
public static List<MethodReference> findMethods( final TypeReference type, final Predicate<? super MethodReference> filter) { return findMethods(type, filter, false); }
public Iterable<R> where(final Predicate<? super R> filter) { if (this.selector != null) { return new WhereSelectIterableIterator<>(this, filter, null); } return new WhereSelectIterableIterator<>( this.source, Predicates.and((Predicate<T>) this.filter, (Predicate<T>) filter), null ); }
/** * Returns a predicate that evaluates to {@code true} if all of the * component predicates evaluate to {@code true}. The components are * evaluated in order, and evaluation will end upon the first * {@code false} predicate. * * @param <T> the type of values evaluated by the predicates. * @param components The predicates to be evaluated. * @return A predicate who's result is {@code true} iff all component * predicates are {@code true}. */ static <T, P extends Predicate<? super T>> Predicate<T> and(final P first, final Iterable<P> components) { final List<P> predicates = safeCopyOf(first, components); return new Predicate<T>() { @Override public boolean test(final T t) { for (final P predicate : predicates) { if (!predicate.test(t)) { return false; } } return true; } }; }
Predicates.or( Predicates.<AstNode>instanceOf(MethodDeclaration.class), Predicates.<AstNode>instanceOf(LambdaExpression.class)
mode == NameResolveMode.TYPE && any(results, Predicates.instanceOf(TypeReference.class))) {
public static List<MethodReference> findMethods( final TypeReference type, final Predicate<? super MethodReference> filter) { return findMethods(type, filter, false); }
/** * Returns a predicate who's result matches * {@code Objects.equals(target, t)}. * * @param <T> the type of predicate values. * @param target The target value to be compared for equality. * @return a predicate who's result matches {@code Objects.equals(target, t)} */ public static <T> Predicate<T> isEqual(final T target) { if (null == target) return Predicates.isNull(); return new Predicate<T>() { @Override public boolean test(final T t) { return target.equals(t); } }; }
/** * Returns a predicate that evaluates to {@code true} if all or none of the * component predicates evaluate to {@code true}. The components are * evaluated in order, and evaluation will end if a predicate result * fails to match the first predicate's result. * * @param <T> the type of values evaluated by the predicates. * @param first initial component predicate to be evaluated. * @param second additional component predicate to be evaluated. * @return a predicate that evaluates to {@code true} if all or none of the * component predicates evaluate to {@code true} */ public static <T, P extends Predicate<? super T>> Predicate<T> xor(final Predicate<T> first, final P second) { if(null != first && first == second) { return alwaysFalse(); } Objects.requireNonNull(first); Objects.requireNonNull(second); return new Predicate<T>() { @Override public boolean test(final T t) { //noinspection ConstantConditions return first.test(t) ^ second.test(t); } }; }
public Iterable<R> where(final Predicate<? super R> filter) { if (this.selector != null) { return new WhereSelectIterableIterator<>(this, filter, null); } return new WhereSelectIterableIterator<>( this.source, Predicates.and((Predicate<T>) this.filter, (Predicate<T>) filter), null ); }
/** * Returns a predicate that evaluates to {@code true} if any of the * component predicates evaluate to {@code true}. The components are * evaluated in order, and evaluation will end upon the first * {@code true} predicate. * * @param <T> the type of values evaluated by the predicates. * @param components The predicates to be evaluated. A copy is made of the * components. * @return A predicate who's result is {@code true} if any component * predicate's result is {@code true}. */ static <T, P extends Predicate<? super T>> Predicate<T> or(final P first, final Iterable<P> components) { final List<P> predicates = safeCopyOf(first, components); return new Predicate<T>() { @Override public boolean test(final T t) { for (final P predicate : predicates) { if (predicate.test(t)) { return true; } } return false; } }; }