Advertisement
wjsl

Sample Accumulo Counter

Jul 14th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. public class Counter extends WrappingIterator {
  2.     Key top_key;
  3.     Value top_value;
  4.  
  5.     @Override
  6.     public boolean hasTop() {
  7.         return top_key != null;
  8.     }
  9.  
  10.     @Override
  11.     public Key getTopKey() {
  12.         return this.top_key;
  13.     }
  14.  
  15.     @Override
  16.     public Value getTopValue() {
  17.         return this.top_value;
  18.     }
  19.  
  20.     @Override
  21.     public void next() {
  22.         top_key = null;
  23.         long count = 0L;
  24.         while(this.source.hasTop()) {
  25.             top_key = this.source.getTopKey();
  26.             Value v = this.source.getTopValue();
  27.             MyObject thing = deserialize(v.get());
  28.             count += thing.count();
  29.         this.source.next();
  30.         }
  31.         this.top_value = new Value(Long.toString(count).getBytes());
  32.     }
  33.  
  34.     @Override
  35.     public Counter deepCopy(IteratorEnvironment env) {
  36.         Counter c = new Counter();
  37.         c.setSource(getSource().deepCopy(env));
  38.         return c;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement