Java Code Examples for org.apache.commons.collections4.TransformerUtils

The following examples show how to use org.apache.commons.collections4.TransformerUtils. These examples are extracted from open source projects. 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 Project: feilong-core   Source File: CollectIterableTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test collect.
 */
@Test
public void testCollect(){
    List<String> list = toList("xinge", "feilong1", "feilong2", "feilong2");

    Transformer<String, Object> nullTransformer = TransformerUtils.nullTransformer();
    List<Object> collect = CollectionsUtil.collect(list, nullTransformer);

    Object[] objects = { null, null, null, null };
    assertThat(collect, hasItems(objects));
}
 
Example 2
Source Project: feilong-core   Source File: CollectIterableTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test collect 2.
 */
@Test
public void testCollect2(){
    List<User> list = toList(//
                    new User("张飞", 23),
                    new User("关羽", 24),
                    new User("刘备", 25));

    Transformer<User, String> invokerTransformer = TransformerUtils.invokerTransformer("getName");
    assertThat(CollectionsUtil.collect(list, invokerTransformer), hasItems("张飞", "关羽", "刘备"));
}
 
Example 3
Source Project: feilong-core   Source File: CollectIterableTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test collect3.
 */
@Test
public void testCollect3(){
    List<User> list = toList(//
                    new User("张飞", 23),
                    new User("关羽", 24),
                    new User("刘备", 25));

    List<String> collect1 = CollectionsUtil.collect(list, TransformerUtils.constantTransformer("jintian"));
    assertThat(collect1, hasItems("jintian", "jintian", "jintian"));
}
 
Example 4
Source Project: feilong-core   Source File: CollectIteratorTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test collect iterator.
 */
@Test
public void testCollectIterator(){
    List<String> list = toList("xinge", "feilong1", "feilong2", "feilong2");

    Transformer<String, Object> nullTransformer = TransformerUtils.nullTransformer();
    List<Object> collect = CollectionsUtil.collect(list.iterator(), nullTransformer);

    Object[] objects = { null, null, null, null };
    assertThat(collect, hasItems(objects));
}
 
Example 5
/**
 * Test group null collection.
 */
@Test
public void testGroupNullCollection(){
    assertEquals(
                    emptyMap(),
                    group(
                                    null,
                                    BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.LESS),
                                    TransformerUtils.constantTransformer(5)));
}
 
Example 6
/**
 * Test group empty collection.
 */
@Test
public void testGroupEmptyCollection(){
    assertEquals(
                    emptyMap(),
                    group(
                                    new ArrayList<>(),
                                    BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.LESS),
                                    TransformerUtils.constantTransformer(5)));
}
 
Example 7
/**
 * Test group null predicate.
 */
@Test
public void testGroupNullPredicate(){
    User zhangfei28 = new User("张飞", 28);
    User liubei32 = new User("刘备", 32);
    User liubei30 = new User("刘备", 30);
    List<User> list = toList(zhangfei28, liubei32, liubei30);

    Map<Integer, List<User>> map = CollectionsUtil.group(list, null, TransformerUtils.<User, Integer> constantTransformer(5));

    assertEquals(1, map.size());
    assertThat(map, allOf(hasEntry(5, toList(zhangfei28, liubei32, liubei30))));
}
 
Example 8
/**
 * Test group not predicate.
 */
@Test
public void testGroupNotPredicate(){
    List<User> list = toList(new User("张飞", 10), new User("刘备", 10));
    Predicate<User> comparatorPredicate = BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.EQUAL);
    assertEquals(emptyMap(), CollectionsUtil.group(list, comparatorPredicate, TransformerUtils.<User, Integer> constantTransformer(5)));
}
 
Example 9
Source Project: tutorials   Source File: MapUtilsUnitTest.java    License: MIT License 5 votes vote down vote up
@Test
public void whenCreateLazyMap_theMapIsCreated() {
    Map<Integer, String> intStrMap = MapUtils.lazyMap(new HashMap<Integer, String>(), TransformerUtils.stringValueTransformer());

    assertThat(intStrMap, is(anEmptyMap()));

    intStrMap.get(1);
    intStrMap.get(2);
    intStrMap.get(3);

    assertThat(intStrMap, is(aMapWithSize(3)));
}
 
Example 10
Source Project: ghidra   Source File: LayoutPositions.java    License: Apache License 2.0 4 votes vote down vote up
private void setVertexLocations(Map<V, Point2D> newVertexLocations) {
	this.vertexLocations = TransformedMap.transformedMap(newVertexLocations,
		TransformerUtils.nopTransformer(), TransformerUtils.cloneTransformer());
}
 
Example 11
Source Project: ghidra   Source File: LayoutPositions.java    License: Apache License 2.0 4 votes vote down vote up
private void setEdgeArticulations(Map<E, List<Point2D>> newEdgeArticulations) {
	this.edgeArticulations = TransformedMap.transformedMap(newEdgeArticulations,
		TransformerUtils.nopTransformer(), TransformerUtils.cloneTransformer());
}
 
Example 12
Source Project: feilong-core   Source File: CollectIterableTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test collect null iterable.
 */
@Test
public void testCollectNullIterable(){
    assertEquals(null, CollectionsUtil.collect((List<Long>) null, TransformerUtils.stringValueTransformer()));
}
 
Example 13
Source Project: feilong-core   Source File: CollectIterableTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test collect empty iterable.
 */
@Test
public void testCollectEmptyIterable(){
    assertEquals(emptyList(), CollectionsUtil.collect(new ArrayList<Long>(), TransformerUtils.stringValueTransformer()));
}
 
Example 14
Source Project: feilong-core   Source File: CollectIteratorTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test collect null iterator.
 */
@Test
public void testCollectNullIterator(){
    assertEquals(null, CollectionsUtil.collect((Iterator<Long>) null, TransformerUtils.stringValueTransformer()));
}
 
Example 15
Source Project: feilong-core   Source File: CollectIteratorTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test collect empty iterator.
 */
@Test
public void testCollectEmptyIterator(){
    assertEquals(emptyList(), CollectionsUtil.collect((new ArrayList<Long>()).iterator(), TransformerUtils.stringValueTransformer()));
}
 
Example 16
Source Project: feilong-core   Source File: GroupWithTransformerTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test group null collection.
 */
@Test
public void testGroupNullCollection(){
    assertEquals(emptyMap(), group(null, TransformerUtils.constantTransformer(5)));
}
 
Example 17
Source Project: feilong-core   Source File: GroupWithTransformerTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test group empty collection.
 */
@Test
public void testGroupEmptyCollection(){
    assertEquals(emptyMap(), group(new ArrayList<>(), TransformerUtils.constantTransformer(5)));
}