Esempio n. 1
0
 @Test
 public void chainTest() {
   final AtomicInteger i = new AtomicInteger(0);
   ArrayBuilder<Task<String, String>> tasks = ArrayBuilder.list(Task.class);
   for (int n = 0; n < 10; n++)
     tasks.add(
         new Task<String, String>() {
           public String apply(String input, Chain<String, String> flow) {
             i.getAndIncrement();
             return flow.next(input);
           }
         });
   Chain<String, String> chain =
       Chain.<String, String>make()
           .via(tasks.build())
           .to(
               new Function<String, String>() {
                 public String apply(String input) {
                   i.getAndIncrement();
                   return input.toUpperCase(Locale.US);
                 }
               })
           .get();
   String v = chain.apply("a");
   assertEquals("A", v);
   assertEquals(11, i.get());
 }
Esempio n. 2
0
  @Test
  public void arrayBuilderTest() {
    // Set array builder (no duplicates)
    ArrayBuilder<String> ab = ArrayBuilder.set(String.class);
    String[] array = ab.add("a").add("a").add("b").add("c").build();
    assertEquals(3, array.length);
    assertEquals("a", array[0]);
    assertEquals("b", array[1]);
    assertEquals("c", array[2]);

    // List array (duplicates)
    ab = ArrayBuilder.list(String.class);
    array = ab.add("a").add("a").add("b").add("c").build();
    assertEquals(4, array.length);
    assertEquals("a", array[0]);
    assertEquals("a", array[1]);
    assertEquals("b", array[2]);
    assertEquals("c", array[3]);
  }