Example usage for org.apache.commons.collections4 Transformer transform

List of usage examples for org.apache.commons.collections4 Transformer transform

Introduction

In this page you can find the example usage for org.apache.commons.collections4 Transformer transform.

Prototype

O transform(I input);

Source Link

Document

Transforms the input object (leaving it unchanged) into some output object.

Usage

From source file:fr.gael.dhus.util.functional.FunctionalTools.java

/**
 * Compose 2 Transformers into 1.//from  w w w  . j av a 2s.  c  o  m
 * @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));
        }
    };
}

From source file:fr.landel.utils.commons.CollectionUtils2.java

/**
 * Transform an array into a set//w  w  w. j av a 2s .c  om
 * 
 * @param input
 *            the input array
 * @param transformer
 *            The transformer
 * @param <I>
 *            The input type
 * @param <O>
 *            The output type
 * @return The converted set
 */
public static <I, O> Set<O> transformIntoSet(final I[] input, final Transformer<I, O> transformer) {
    final Set<O> list = new HashSet<>();
    for (I in : input) {
        list.add(transformer.transform(in));
    }
    return list;
}

From source file:fr.landel.utils.commons.CollectionUtils2.java

/**
 * Transform an iterable into a set/* w  w w . j  a  v a 2  s  . c  om*/
 * 
 * @param input
 *            the input iterable
 * @param transformer
 *            The transformer
 * @param <I>
 *            The input type
 * @param <O>
 *            The output type
 * @return The converted set
 */
public static <I, O> Set<O> transformIntoSet(final Iterable<I> input, final Transformer<I, O> transformer) {
    final Set<O> list = new HashSet<>();
    for (I in : input) {
        list.add(transformer.transform(in));
    }
    return list;
}

From source file:fr.landel.utils.commons.CollectionUtils2.java

/**
 * Transform an array into an array//from  w w  w  .  j a v  a 2  s.c om
 * 
 * @param input
 *            the input array
 * @param transformer
 *            The transformer
 * @param <I>
 *            The input type
 * @param <O>
 *            The output type
 * @return The converted array
 */
public static <I, O> O[] transformIntoArray(final I[] input, final Transformer<I, O> transformer) {
    final List<O> list = new ArrayList<>();
    for (I in : input) {
        list.add(transformer.transform(in));
    }
    return CollectionUtils2.toArray(list);
}

From source file:fr.landel.utils.commons.CollectionUtils2.java

/**
 * Transform an iterable into an array//from ww w . j a v  a 2  s.c o  m
 * 
 * @param input
 *            the input iterable
 * @param transformer
 *            The transformer
 * @param <I>
 *            The input type
 * @param <O>
 *            The output type
 * @return The converted array
 */
public static <I, O> O[] transformIntoArray(final Iterable<I> input, final Transformer<I, O> transformer) {
    final List<O> list = new ArrayList<>();
    for (I in : input) {
        list.add(transformer.transform(in));
    }
    return CollectionUtils2.toArray(list);
}

From source file:fr.landel.utils.commons.CollectionUtils2.java

/**
 * Transform an array into a list/*  ww w  .  ja v a 2  s .  co  m*/
 * 
 * @param input
 *            the input array
 * @param transformer
 *            The transformer
 * @param <I>
 *            The input type
 * @param <O>
 *            The output type
 * @return The converted list
 */
public static <I, O> List<O> transformIntoList(final I[] input, final Transformer<I, O> transformer) {
    final List<O> list = new ArrayList<>();
    for (I in : input) {
        list.add(transformer.transform(in));
    }
    return list;
}

From source file:fr.landel.utils.commons.CollectionUtils2.java

/**
 * Transform an iterable into a list/*from  w  w w  .  ja  va 2s.  c om*/
 * 
 * @param input
 *            the input iterable
 * @param transformer
 *            The transformer
 * @param <I>
 *            The input type
 * @param <O>
 *            The output type
 * @return The converted list
 */
public static <I, O> List<O> transformIntoList(final Iterable<I> input, final Transformer<I, O> transformer) {
    final List<O> list = new ArrayList<>();
    for (I in : input) {
        list.add(transformer.transform(in));
    }
    return list;
}

From source file:com.link_intersystems.lang.reflect.MethodInvokingTransformerTest.java

@Test(expected = NullPointerException.class)
public void transformNullValue() {
    Transformer transformer = new MethodInvokingTransformer(charAtMethod, argumentResolver);
    transformer.transform(null);
}

From source file:com.link_intersystems.lang.reflect.MethodInvokingTransformerTest.java

@Test(expected = NullPointerException.class)
public void invokeInstanceMethodOnNull() {
    Transformer transformer = new MethodInvokingTransformer(charAtMethod, argumentResolver);
    transformer.transform(null);
}

From source file:com.link_intersystems.lang.reflect.MethodInvokingTransformerTest.java

@Test
public void invokeMethodWithNoArguments() {
    String testString = "HelloWorld";
    Method toStringMethod = MethodUtils.getAccessibleMethod(String.class, "toString", new Class<?>[0]);
    Transformer transformer = new MethodInvokingTransformer(toStringMethod);
    Object transform = transformer.transform(testString);
    assertNotNull(transform);/*from  ww  w  . j a va 2 s  . c  o  m*/
    assertTrue(transform instanceof String);
    String string = (String) transform;
    assertEquals("HelloWorld", string);
}