本文整理汇总了Java中org.apache.commons.collections4.Transformer类的典型用法代码示例。如果您正苦于以下问题:Java Transformer类的具体用法?Java Transformer怎么用?Java Transformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transformer类属于org.apache.commons.collections4包,在下文中一共展示了Transformer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: iterator
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
@Override
public Iterator<Entry<K, V>> iterator() {
return new LazyIteratorChain<Entry<K, V>>() {
final Collection<K> keysCol = new ArrayList<K>(getMap().keySet());
final Iterator<K> keyIterator = keysCol.iterator();
@Override
protected Iterator<? extends Entry<K, V>> nextIterator(int count) {
if (!keyIterator.hasNext()) {
return null;
}
final K key = keyIterator.next();
final Transformer<V, Entry<K, V>> entryTransformer = new Transformer<V, Entry<K, V>>() {
@Override
public Entry<K, V> transform(final V input) {
return new MultiValuedMapEntry(key, input);
}
};
return new TransformIterator<V, Entry<K, V>>(new ValuesIterator(key), entryTransformer);
}
};
}
示例2: visitUnary
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
@Override
public Object visitUnary(UnaryExpression ue, UnaryOperator operator, Object operand)
{
// operand is a Node<?> (Expression Tree)
// Returns an instance of Transformer<?> (functional java) as a Node<?> (Expression Tree)
Transformer trans;
switch (operator)
{
case NOT: trans = Transformers.not(); break;
case MINUS: trans = Transformers.minus(); break;
default:
throw new UnsupportedOperationException("Unsupported operator: " + operator.toUriLiteral());
}
ExecutableExpressionTree.Node param = ExecutableExpressionTree.Node.class.cast(operand);
return ExecutableExpressionTree.Node.createNode(trans, param);
}
示例3: gt
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** gt, greater than. */
public static Transformer<Duo<Object, Object>, Boolean> gt()
{
return new Transformer<Duo<Object, Object>, Boolean>()
{
@Override
public Boolean transform(Duo<Object, Object> d)
{
if (involvesNumbers(d))
{
return Number.class.cast(d.getA()).doubleValue() >
Number.class.cast(d.getB()).doubleValue();
}
if (involvesDates(d))
{
Duo<Calendar, Calendar> duo = asDuoOfCalendar(d);
return duo.getA().after(duo.getB());
}
throw new IllegalStateException(notComparableMsg(d));
}
};
}
示例4: ge
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** ge, greater or equals than. */
public static Transformer<Duo<Object, Object>, Boolean> ge()
{
return new Transformer<Duo<Object, Object>, Boolean>()
{
@Override
public Boolean transform(Duo<Object, Object> u)
{
if (involvesNumbers(u))
{
return Number.class.cast(u.getA()).doubleValue() >=
Number.class.cast(u.getB()).doubleValue();
}
if (involvesDates(u))
{
Duo<Calendar, Calendar> duo = asDuoOfCalendar(u);
return duo.getA().after(duo.getB()) || duo.getA().equals(duo.getB());
}
throw new IllegalStateException(notComparableMsg(u));
}
};
}
示例5: substringof
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** substringof. */
public static Transformer<Duo<String, String>, Boolean> substringof()
{
return new Transformer<Duo<String, String>, Boolean>()
{
@Override
public Boolean transform(Duo<String, String> u)
{
if (u == null || u.getA() == null)
{
return false;
}
return u.getA().contains(u.getB());
}
};
}
示例6: transformedCollection
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/**
* Factory method to create a transforming collection that will transform
* existing contents of the specified collection.
* <p>
* If there are any elements already in the collection being decorated, they
* will be transformed by this method.
* Contrast this with {@link #transformingCollection(Collection, Transformer)}.
*
* @param <E> the type of the elements in the collection
* @param collection the collection to decorate, must not be null
* @param transformer the transformer to use for conversion, must not be null
* @return a new transformed Collection
* @throws NullPointerException if collection or transformer is null
* @since 4.0
*/
public static <E> TransformedCollection<E> transformedCollection(final Collection<E> collection,
final Transformer<? super E, ? extends E> transformer) {
final TransformedCollection<E> decorated = new TransformedCollection<E>(collection, transformer);
// null collection & transformer are disallowed by the constructor call above
if (collection.size() > 0) {
@SuppressWarnings("unchecked") // collection is of type E
final E[] values = (E[]) collection.toArray(); // NOPMD - false positive for generics
collection.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
}
}
return decorated;
}
示例7: indexof
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** indexof. */
public static Transformer<Duo<String, String>, Integer> indexof()
{
return new Transformer<Duo<String, String>, Integer>()
{
@Override
public Integer transform(Duo<String, String> u)
{
if (u == null || u.getA() == null)
{
return -1;
}
return u.getA().indexOf(u.getB());
}
};
}
示例8: substring2
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** substring(string, int, int). */
public static Transformer<Trio<String, Integer, Integer>, String> substring2()
{
return new Transformer<Trio<String, Integer, Integer>, String>()
{
@Override
public String transform(Trio<String, Integer, Integer> u)
{
if (u == null || u.getA() == null)
{
return null;
}
return u.getA().substring(u.getB(), u.getC() - u.getB());
}
};
}
示例9: switchTransformer
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/**
* Factory method that performs validation and copies the parameter arrays.
*
* @param <I> the input type
* @param <O> the output type
* @param predicates array of predicates, cloned, no nulls
* @param transformers matching array of transformers, cloned, no nulls
* @param defaultTransformer the transformer to use if no match, null means return null
* @return the <code>chained</code> transformer
* @throws NullPointerException if array is null
* @throws NullPointerException if any element in the array is null
*/
@SuppressWarnings("unchecked")
public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer) {
FunctorUtils.validate(predicates);
FunctorUtils.validate(transformers);
if (predicates.length != transformers.length) {
throw new IllegalArgumentException("The predicate and transformer arrays must be the same size");
}
if (predicates.length == 0) {
return (Transformer<I, O>) (defaultTransformer == null ? ConstantTransformer.<I, O>nullTransformer() :
defaultTransformer);
}
return new SwitchTransformer<I, O>(predicates, transformers, defaultTransformer);
}
示例10: compose
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/**
* 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));
}
};
}
示例11: eq
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** eq, equals. */
public static Transformer<Duo<Object, Object>, Boolean> eq()
{
return new Transformer<Duo<Object, Object>, Boolean>()
{
@Override
public Boolean transform(Duo<Object, Object> d)
{
if (d.getA() == null || d.getB() == null)
{
return d.getA() == d.getB();
}
// subclasses of Number reimplement #equals(o) to compare instance types
if (involvesNumbers(d))
{
return Number.class.cast(d.getA()).doubleValue() ==
Number.class.cast(d.getB()).doubleValue();
}
// dates can be instances of Date or Calendar
if (involvesDates(d))
{
Duo<Calendar, Calendar> duo = asDuoOfCalendar(d);
return duo.getA().equals(duo.getB());
}
return d.getA().equals(d.getB());
}
};
}
示例12: and
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** and. */
public static Transformer<Duo<Boolean, Boolean>, Boolean> and()
{
return new Transformer<Duo<Boolean, Boolean>, Boolean>()
{
@Override
public Boolean transform(Duo<Boolean, Boolean> u)
{
return u.getA() && u.getB();
}
};
}
示例13: or
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** or. */
public static Transformer<Duo<Boolean, Boolean>, Boolean> or()
{
return new Transformer<Duo<Boolean, Boolean>, Boolean>()
{
@Override
public Boolean transform(Duo<Boolean, Boolean> u)
{
return u.getA() || u.getB();
}
};
}
示例14: ifTransformer
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/**
* 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<T, T>(predicate, trueTransformer, NOPTransformer.<T>nopTransformer());
}
示例15: sub
import org.apache.commons.collections4.Transformer; //导入依赖的package包/类
/** sub. */
public static Transformer<Duo<Number, Number>, Number> sub()
{
return new Transformer<Duo<Number, Number>, Number>()
{
@Override
public Number transform(Duo<Number, Number> u)
{
return u.getA().doubleValue() - u.getB().doubleValue();
}
};
}