/** * Factory to create the predicate. * * @param <T> the type that the predicate queries * @param object the object to compare to * @return the predicate */ public static <T> Predicate<T> equalPredicate(final T object) { if (object == null) { return NullPredicate.nullPredicate(); } return new EqualPredicate<>(object); }
/** * Factory to create the predicate. * * @param <T> the type that the predicate queries * @param predicates the predicates to check, cloned, not null * @return the <code>one</code> predicate * @throws NullPointerException if the predicates array is null * @throws NullPointerException if any predicate in the array is null */ public static <T> Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates) { final Predicate<? super T>[] preds = FunctorUtils.validate(predicates); return new OnePredicate<>(preds); }
/** * Constructs a new empty <code>DefaultedMap</code> that decorates * a <code>HashMap</code>. * <p> * The object passed in will be returned by the map whenever an * unknown key is requested. * * @param defaultValue the default value to return when the key is not found */ public DefaultedMap(final V defaultValue) { this(ConstantTransformer.constantTransformer(defaultValue)); }
/** * Factory method that performs validation and copies the parameter array. * * @param <T> the object type * @param transformers the transformers to chain, copied, no nulls * @return the <code>chained</code> transformer * @throws NullPointerException if the transformers array is null * @throws NullPointerException if any transformer in the array is null */ public static <T> Transformer<T, T> chainedTransformer(final Transformer<? super T, ? extends T>... transformers) { FunctorUtils.validate(transformers); if (transformers.length == 0) { return NOPTransformer.<T>nopTransformer(); } return new ChainedTransformer<>(transformers); }
/** * Gets a transformer that returns the input object. * The input object should be immutable to maintain the * contract of Transformer (although this is not checked). * * @param <T> the input/output type * @return the transformer * @see NOPTransformer */ public static <T> Transformer<T, T> nopTransformer() { return NOPTransformer.nopTransformer(); }
/** * Factory to create the identity predicate. * * @param <T> the type that the predicate queries * @param object the object to compare to * @return the predicate */ public static <T> Predicate<T> identityPredicate(final T object) { if (object == null) { return NullPredicate.<T>nullPredicate(); } return new IdentityPredicate<>(object); }
/** * Gets the closures. * * @return a copy of the closures * @since 3.1 */ public Closure<? super E>[] getClosures() { return FunctorUtils.<E>copy(iClosures); }
/** * Gets a Closure that will do nothing. * This could be useful during testing as a placeholder. * * @see org.apache.commons.collections4.functors.NOPClosure * * @param <E> the type that the closure acts on * @return the closure */ public static <E> Closure<E> nopClosure() { return NOPClosure.<E>nopClosure(); }
/** * Gets a Factory that always throws an exception. * This could be useful during testing as a placeholder. * * @see org.apache.commons.collections4.functors.ExceptionFactory * * @param <T> the type that the factory creates * @return the factory */ public static <T> Factory<T> exceptionFactory() { return ExceptionFactory.<T>exceptionFactory(); }
/** * Gets a Predicate that always throws an exception. * This could be useful during testing as a placeholder. * * @param <T> the type that the predicate queries * @return the predicate * @see ExceptionPredicate */ public static <T> Predicate<T> exceptionPredicate() { return ExceptionPredicate.exceptionPredicate(); }
/** * Gets a Closure that always throws an exception. * This could be useful during testing as a placeholder. * * @see org.apache.commons.collections4.functors.ExceptionClosure * * @param <E> the type that the closure acts on * @return the closure */ public static <E> Closure<E> exceptionClosure() { return ExceptionClosure.<E>exceptionClosure(); }
/** * Creates a Predicate that checks if the input object is equal to the * specified object by identity. * * @param <T> the type that the predicate queries * @param value the value to compare against * @return the predicate * @see IdentityPredicate */ public static <T> Predicate<T> identityPredicate(final T value) { return IdentityPredicate.identityPredicate(value); }
/** * 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<>(); }
/** * Gets a transformer that always throws an exception. * This could be useful during testing as a placeholder. * * @param <I> the input type * @param <O> the output type * @return the transformer * @see ExceptionTransformer */ public static <I, O> Transformer<I, O> exceptionTransformer() { return ExceptionTransformer.exceptionTransformer(); }
/** * Gets a Transformer that expects an input Class object that it will instantiate. * * @param <T> the output type * @return the transformer * @see InstantiateTransformer */ public static <T> Transformer<Class<? extends T>, T> instantiateTransformer() { return InstantiateTransformer.instantiateTransformer(); }
/** * Gets a transformer that returns a <code>java.lang.String</code> * representation of the input object. This is achieved via the * <code>toString</code> method, <code>null</code> returns 'null'. * * @param <T> the input type * @return the transformer * @see StringValueTransformer */ public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); }
/** * Gets a Factory that will return null each time the factory is used. * This could be useful during testing as a placeholder. * * @see org.apache.commons.collections4.functors.ConstantFactory * @param <T> the "type" of null object the factory should return. * @return the factory */ public static <T> Factory<T> nullFactory() { return ConstantFactory.<T>constantFactory(null); }
/** * Factory to create the identity predicate. * * @param <T> the type that the predicate queries * @param object the object to compare to * @param equator the equator to use for comparison * @return the predicate * @since 4.0 */ public static <T> Predicate<T> equalPredicate(final T object, final Equator<T> equator) { if (object == null) { return NullPredicate.nullPredicate(); } return new EqualPredicate<>(object, equator); }
/** * Gets the predicates. * * @return a copy of the predicates * @since 3.1 */ public Predicate<? super I>[] getPredicates() { return FunctorUtils.<I>copy(iPredicates); }
/** * Gets the predicates. * * @return a copy of the predicates * @since 3.1 */ @Override public Predicate<? super T>[] getPredicates() { return FunctorUtils.<T>copy(iPredicates); }