Java 类org.apache.commons.collections4.TransformerUtils 实例源码

项目:apt    文件:CreateLTSTest.java   
@Test
public void createABAndBAWithConstantPV() {
    Transformer<ParikhVector, ParikhVector> constantTransformer =
        TransformerUtils.constantTransformer(new ParikhVector());
    CreateLTS create = new CreateLTS(constantTransformer);
    create.addWord(Arrays.asList("a", "b"));
    create.addWord(Arrays.asList("b", "a"));
    TransitionSystem ts = create.getTransitionSystem();

    assertThat(ts, not(sameInstance(create.getTransitionSystem())));
    assertThat(ts.getNodes(), hasSize(1));
    assertThat(ts.getEdges(), hasSize(2));
    assertThat(ts.getInitialState(), not(nullValue()));

    assertThat(ts.getAlphabet(), containsInAnyOrder("a", "b"));

    State s0 = ts.getInitialState();
    assertThat(s0.getPostsetNodesByLabel("a"), hasSize(1));
    assertThat(s0.getPostsetNodesByLabel("b"), hasSize(1));
}
项目:feilong-core    文件:CollectIterableTest.java   
/**
 * 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));
}
项目:feilong-core    文件:CollectIterableTest.java   
/**
 * 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("张飞", "关羽", "刘备"));
}
项目:feilong-core    文件:CollectIterableTest.java   
/**
 * 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"));
}
项目:feilong-core    文件:CollectIteratorTest.java   
/**
 * 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));
}
项目:feilong-core    文件:GroupWithTransformerAndPredicateTest.java   
/**
 * Test group null collection.
 */
@Test
public void testGroupNullCollection(){
    assertEquals(
                    emptyMap(),
                    group(
                                    null,
                                    BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.LESS),
                                    TransformerUtils.constantTransformer(5)));
}
项目:feilong-core    文件:GroupWithTransformerAndPredicateTest.java   
/**
 * Test group empty collection.
 */
@Test
public void testGroupEmptyCollection(){
    assertEquals(
                    emptyMap(),
                    group(
                                    new ArrayList<>(),
                                    BeanPredicateUtil.comparatorPredicate("age", 20, Criterion.LESS),
                                    TransformerUtils.constantTransformer(5)));
}
项目:feilong-core    文件:GroupWithTransformerAndPredicateTest.java   
/**
 * 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))));
}
项目:feilong-core    文件:GroupWithTransformerAndPredicateTest.java   
/**
 * 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)));
}
项目:feilong-core    文件:CollectIterableTest.java   
/**
 * Test collect null iterable.
 */
@Test
public void testCollectNullIterable(){
    assertEquals(null, CollectionsUtil.collect((List<Long>) null, TransformerUtils.stringValueTransformer()));
}
项目:feilong-core    文件:CollectIterableTest.java   
/**
 * Test collect empty iterable.
 */
@Test
public void testCollectEmptyIterable(){
    assertEquals(emptyList(), CollectionsUtil.collect(new ArrayList<Long>(), TransformerUtils.stringValueTransformer()));
}
项目:feilong-core    文件:CollectIteratorTest.java   
/**
 * Test collect null iterator.
 */
@Test
public void testCollectNullIterator(){
    assertEquals(null, CollectionsUtil.collect((Iterator<Long>) null, TransformerUtils.stringValueTransformer()));
}
项目:feilong-core    文件:CollectIteratorTest.java   
/**
 * Test collect empty iterator.
 */
@Test
public void testCollectEmptyIterator(){
    assertEquals(emptyList(), CollectionsUtil.collect((new ArrayList<Long>()).iterator(), TransformerUtils.stringValueTransformer()));
}
项目:feilong-core    文件:GroupWithTransformerTest.java   
/**
 * Test group null collection.
 */
@Test
public void testGroupNullCollection(){
    assertEquals(emptyMap(), group(null, TransformerUtils.constantTransformer(5)));
}
项目:feilong-core    文件:GroupWithTransformerTest.java   
/**
 * Test group empty collection.
 */
@Test
public void testGroupEmptyCollection(){
    assertEquals(emptyMap(), group(new ArrayList<>(), TransformerUtils.constantTransformer(5)));
}