View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package cz.cuni.amis.utils;
6   
7   import java.util.ArrayList;
8   import java.util.Collection;
9   import java.util.List;
10  
11  /**
12   * Usefull for queriing sets of objects with some common property.
13   * Itarates all elements in the collection and returns 
14   * @author Ik
15   */
16  public abstract class Query<T> {
17  
18      protected abstract boolean filter(T o);
19  
20      public List<T> query(Collection<T> collection) {
21          List<T> result = new ArrayList<T>();
22          for (T o : collection) {
23              if (filter(o)) {
24                  result.add(o);
25              }
26          }
27          return result;
28      }
29  }