/** * 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 method that performs validation. * <p> * This factory creates a transformer that just returns the input object when * the predicate is false. * * @param <T> input and output type for the transformer * @param predicate predicate to switch on * @param trueTransformer transformer used if true * @return the <code>if</code> transformer * @throws NullPointerException if either argument is null */ public static <T> Transformer<T, T> ifTransformer( final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (trueTransformer == null) { throw new NullPointerException("Transformer must not be null"); } return new IfTransformer<>(predicate, trueTransformer, NOPTransformer.<T>nopTransformer()); }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. The ordering is that of the iterator() * method on the collection. * * @param <T> the object type * @param transformers a collection of transformers to chain * @return the <code>chained</code> transformer * @throws NullPointerException if the transformers collection is null * @throws NullPointerException if any transformer in the collection is null */ @SuppressWarnings("unchecked") public static <T> Transformer<T, T> chainedTransformer( final Collection<? extends Transformer<? super T, ? extends T>> transformers) { if (transformers == null) { throw new NullPointerException("Transformer collection must not be null"); } if (transformers.size() == 0) { return NOPTransformer.<T>nopTransformer(); } // convert to array like this to guarantee iterator() ordering final Transformer<T, T>[] cmds = transformers.toArray(new Transformer[transformers.size()]); FunctorUtils.validate(cmds); return new ChainedTransformer<>(false, cmds); }
/** * 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); }
@Override public TransformIterator getTransformIterator(Query settings) { // The objects put into the pageQueue have already been transformed. // We will iterate over the pagequeue with the No-Op transformer return new TransformIterator(results.iterator(), NOPTransformer.nopTransformer()); }
CollectionUtils.collect( satisfyingBindings, nopTransformer(), new TreeSet<VarBindingDef>( byUsage)); },