View Javadoc

1   // BSD License (http://www.galagosearch.org/license)
2   package org.galagosearch.tupleflow;
3   
4   import java.io.IOException;
5   import java.util.Comparator;
6   
7   /***
8    *
9    * @author trevor
10   */
11  public class Unique<T> implements Processor<T> {
12      Comparator<T> sameObject;
13      T last;
14      Processor<T> processor;
15  
16      /*** Creates a new instance of Unique */
17      public Unique(Comparator<T> sameObject, Processor<T> processor) {
18          this.sameObject = sameObject;
19          this.last = null;
20          this.processor = processor;
21      }
22  
23      public void process(T object) throws IOException {
24          if (last != null && 0 == sameObject.compare(object, last)) {
25              return;
26          }
27          processor.process(object);
28          last = object;
29      }
30  
31      public void close() throws IOException {
32          last = null;
33          processor.close();
34      }
35  }