org.apache.commons.collections4.TransformerUtils Java Examples
The following examples show how to use
org.apache.commons.collections4.TransformerUtils.
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: MapUtilsUnitTest.java From tutorials with MIT License | 5 votes |
@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 #2
Source File: CollectIterableTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * 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 #3
Source File: CollectIterableTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * 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 #4
Source File: CollectIterableTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * 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 #5
Source File: CollectIteratorTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * 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 #6
Source File: GroupWithTransformerAndPredicateTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * 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 #7
Source File: GroupWithTransformerAndPredicateTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * 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
Source File: GroupWithTransformerAndPredicateTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * Test group null collection. */ @Test public void testGroupNullCollection(){ assertEquals( emptyMap(), group( null, BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.LESS), TransformerUtils.constantTransformer(5))); }
Example #9
Source File: GroupWithTransformerAndPredicateTest.java From feilong-core with Apache License 2.0 | 5 votes |
/** * Test group empty collection. */ @Test public void testGroupEmptyCollection(){ assertEquals( emptyMap(), group( new ArrayList<>(), BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.LESS), TransformerUtils.constantTransformer(5))); }
Example #10
Source File: CollectIteratorTest.java From feilong-core with Apache License 2.0 | 4 votes |
/** * Test collect null iterator. */ @Test public void testCollectNullIterator(){ assertEquals(null, CollectionsUtil.collect((Iterator<Long>) null, TransformerUtils.stringValueTransformer())); }
Example #11
Source File: GroupWithTransformerTest.java From feilong-core with Apache License 2.0 | 4 votes |
/** * Test group empty collection. */ @Test public void testGroupEmptyCollection(){ assertEquals(emptyMap(), group(new ArrayList<>(), TransformerUtils.constantTransformer(5))); }
Example #12
Source File: GroupWithTransformerTest.java From feilong-core with Apache License 2.0 | 4 votes |
/** * Test group null collection. */ @Test public void testGroupNullCollection(){ assertEquals(emptyMap(), group(null, TransformerUtils.constantTransformer(5))); }
Example #13
Source File: CollectIteratorTest.java From feilong-core with Apache License 2.0 | 4 votes |
/** * Test collect empty iterator. */ @Test public void testCollectEmptyIterator(){ assertEquals(emptyList(), CollectionsUtil.collect((new ArrayList<Long>()).iterator(), TransformerUtils.stringValueTransformer())); }
Example #14
Source File: LayoutPositions.java From ghidra with Apache License 2.0 | 4 votes |
private void setVertexLocations(Map<V, Point2D> newVertexLocations) { this.vertexLocations = TransformedMap.transformedMap(newVertexLocations, TransformerUtils.nopTransformer(), TransformerUtils.cloneTransformer()); }
Example #15
Source File: CollectIterableTest.java From feilong-core with Apache License 2.0 | 4 votes |
/** * Test collect empty iterable. */ @Test public void testCollectEmptyIterable(){ assertEquals(emptyList(), CollectionsUtil.collect(new ArrayList<Long>(), TransformerUtils.stringValueTransformer())); }
Example #16
Source File: CollectIterableTest.java From feilong-core with Apache License 2.0 | 4 votes |
/** * Test collect null iterable. */ @Test public void testCollectNullIterable(){ assertEquals(null, CollectionsUtil.collect((List<Long>) null, TransformerUtils.stringValueTransformer())); }
Example #17
Source File: LayoutPositions.java From ghidra with Apache License 2.0 | 4 votes |
private void setEdgeArticulations(Map<E, List<Point2D>> newEdgeArticulations) { this.edgeArticulations = TransformedMap.transformedMap(newEdgeArticulations, TransformerUtils.nopTransformer(), TransformerUtils.cloneTransformer()); }