Example #1
0
 public void testChainedIterables() {
   final List<List<Integer>> data = new ArrayList<List<Integer>>();
   final List<Integer> result = new ArrayList<Integer>();
   for (int i = 0; i < TEST_SEQS; i++) {
     List<Integer> l = createSequentialList(TEST_SEQ_SIZE);
     data.add(l);
     result.addAll(l);
   }
   Iterable<Integer> i = Iterators.chained(data);
   assertEquals(result, i);
   // Next try, didn't work in prev version
   i = Iterators.chained(data);
   assertEquals(result, i);
 }
Example #2
0
 public void testFilteredIterables() {
   final List<Integer> data = createSequentialList(TEST_SEQ_SIZE);
   final List<Integer> expected = new LinkedList<Integer>();
   final List<Integer> filtered = new LinkedList<Integer>();
   for (Integer i = 0; i < data.size(); i++) {
     Integer x = data.get(i);
     if (i % 2 == 0) {
       expected.add(x);
     } else {
       filtered.add(x);
     }
   }
   final Iterable<Integer> res =
       Iterators.filter(
           data,
           new Comparable<Integer>() {
             public int compareTo(Integer i) {
               return filtered.contains(i) ? 0 : -1;
             }
           });
   assertEquals(expected, res);
 }