Advertisement
Guest User

Untitled

a guest
Jul 15th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. package iterators;
  2.  
  3. import org.apache.accumulo.core.data.ByteSequence;
  4. import org.apache.accumulo.core.data.Key;
  5. import org.apache.accumulo.core.data.Range;
  6. import org.apache.accumulo.core.data.Value;
  7. import org.apache.accumulo.core.iterators.IteratorEnvironment;
  8. import org.apache.accumulo.core.iterators.WrappingIterator;
  9.  
  10. import java.io.IOException;
  11. import java.util.Collection;
  12.  
  13. public class Counter extends WrappingIterator {
  14.     Key top_key;
  15.     Value top_value;
  16.  
  17.     @Override
  18.     public boolean hasTop() {
  19.         return top_key != null;
  20.     }
  21.  
  22.     @Override
  23.     public Key getTopKey() {
  24.         return this.top_key;
  25.     }
  26.  
  27.     @Override
  28.     public Value getTopValue() {
  29.         return this.top_value;
  30.     }
  31.  
  32.     @Override
  33.     public void next() throws IOException {
  34.         top_key = null;
  35.         long count = 0L;
  36.         while (this.getSource().hasTop()) {
  37.             top_key = this.getSource().getTopKey();
  38.             Value v = this.getSource().getTopValue();
  39.             //MyPojo pojo = (MyPojo) SerializationUtils.deserialize(v.get());
  40.             //count += pojo.count;
  41.             count++;
  42.             this.getSource().next();
  43.         }
  44.         this.top_value = new Value(Long.toString(count).getBytes());
  45.     }
  46.  
  47.     @Override
  48.     public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException {
  49.         this.getSource().seek(range, columnFamilies, inclusive);
  50.         next();
  51.     }
  52.  
  53.     @Override
  54.     public Counter deepCopy(IteratorEnvironment env) {
  55.         Counter c = new Counter();
  56.         c.setSource(getSource().deepCopy(env));
  57.         return c;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement