Advertisement
Guest User

Untitled

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