コード例 #1
0
ファイル: QQueryBase.java プロジェクト: KMenant/TP-SIO-2
  private Iterator4 checkDuplicates(CompositeIterator4 executeAllCandidates) {
    return Iterators.filter(
        executeAllCandidates,
        new Predicate4() {
          private TreeInt ids = new TreeInt(0);

          public boolean match(Object current) {
            int id = ((Integer) current).intValue();
            if (ids.find(id) != null) {
              return false;
            }
            ids = (TreeInt) ids.add(new TreeInt(id));
            return true;
          }
        });
  }
コード例 #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);
 }