Java Code Examples for org.apache.commons.collections4.Transformer#transform()
The following examples show how to use
org.apache.commons.collections4.Transformer#transform() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutableExpressionTree.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
/** * Creates a Node from a Transformer<Trio<?,?,?>,?>. * @param <T> Type of the Collection entry. * @param <R> Return type. * @param t a tri-transformer that accepts a <?,?,?> and returns a <?>. * @param sub1 first Node at `depth+1` in the tree. * @param sub2 second Node at `depth+1` in the tree. * @param sub3 third Node at `depth+1` in the tree. * @return a new Node. */ public static <T,R> Node<T,R> createNode(final Transformer<Trio<Object,Object,Object>,R> t, final Node<T,?> sub1, final Node<T,?> sub2, final Node<T,?> sub3) { return new Node<T,R>() { @Override public R exec(T element) { Object o1 = sub1.exec(element); Object o2 = sub2.exec(element); Object o3 = sub3.exec(element); return t.transform(new Trio<>(o1, o2, o3)); } }; }
Example 2
Source File: AggregateUtil.java From feilong-core with Apache License 2.0 | 6 votes |
/** * Convert value. * * @param <O> * the generic type * @param <T> * the generic type * @param obj * the obj * @param propertyName * the property name * @param propertyValueAndTransformerMap * the property name value converter map * @return the string * @since 1.10.7 */ private static <O, T> Object convertValue( O obj, String propertyName, Map<String, Transformer<Object, Object>> propertyValueAndTransformerMap){ T value = PropertyUtil.<T> getProperty(obj, propertyName); if (isNullOrEmpty(propertyValueAndTransformerMap)){ return value; } //--------------------------------------------------------------- Transformer<Object, Object> transformer = propertyValueAndTransformerMap.get(propertyName); if (null == transformer){ return value; } //--------------------------------------------------------------- return transformer.transform(value); }
Example 3
Source File: FunctionalTools.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** * Compose 2 Transformers into 1. * @param <A> Input type. * @param <B> Transition type. * @param <C> Output type. * @param first firstly invoked Transformer. * @param second secondly invoked Transformer. * @return {@code second.transform(first.transform(A))}. */ public static <A,B,C> Transformer<A,C> compose(Transformer<A,B> first, Transformer<? super B,C> second) { final Transformer<A,B> ffirst = first; final Transformer<? super B,C> fsecond = second; return new Transformer<A,C>() { @Override public C transform(A u) { return fsecond.transform(ffirst.transform(u)); } }; }
Example 4
Source File: ExecutableExpressionTree.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a dynamic leave from a Transformer. * @param <T> Type of the Collection entry. * @param <R> Return type. * @param p Transformer that provides us data from the collection entry. * @return a new Node. */ public static <T,R> Node<T,R> createLeave(final Transformer<T,R> p) { return new Node<T,R>() { @Override public R exec(T element) { return p.transform(element); } }; }
Example 5
Source File: ExecutableExpressionTree.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a Node from a Transformer. * @param <T> Type of the Collection entry. * @param <R> Return type. * @param t a transformer that accepts a <?> and returns a <?>. * @param sub Node at `depth+1` in the tree. * @return a new Node. */ public static <T,R> Node<T,R> createNode(final Transformer<Object,R> t, final Node<T,?> sub) { return new Node<T,R>() { @Override public R exec(T element) { return t.transform(sub.exec(element)); } }; }
Example 6
Source File: ExecutableExpressionTree.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a Node from a Transformer<Duo<?,?>,?>. * @param <T> Type of the Collection entry. * @param <R> Return type. * @param t a bi-transformer that accepts a <?,?> and returns a <?>. * @param sub1 first Node at `depth+1` in the tree, serves as first parameter for `t`. * @param sub2 second Node at `depth+1` in the tree. serves as second parameter for `t`. * @return a new Node. */ public static <T,R> Node<T,R> createNode(final Transformer<Duo<Object,Object>,R> t, final Node<T,?> sub1, final Node<T,?> sub2) { return new Node<T,R>() { @Override public R exec(T element) { Object o1 = sub1.exec(element); Object o2 = sub2.exec(element); return t.transform(new Duo<>(o1, o2)); } }; }
Example 7
Source File: ExecutableExpressionTree.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a Duo Node, it is a Node that takes a Duo<T,T> as input, * transforms `A` with `sub1`, `B` with `sub2` and return their * tranformation through given transformer `t`. * * @param <T> input type. * @param <R> return type. * @param t transformer for this Node. * @param sub1 first Node at `depth+1` in the tree, serves as first parameter for `t`. * @param sub2 second Node at `depth+1` in the tree, serves as second parameter for `t`. * @return a new Node. */ public static <T,R> Node<Duo<T,T>,R> createDuoNode(final Transformer<Duo<Object,Object>,R> t, final Node<T,?> sub1, final Node<T,?> sub2) { return new Node<Duo<T,T>,R>() { @Override public R exec(Duo<T, T> element) { Object o1 = sub1.exec(element.getA()); Object o2 = sub2.exec(element.getB()); return t.transform(new Duo<>(o1, o2)); } }; }