Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created October 20, 2009 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumokmm/213998 to your computer and use it in GitHub Desktop.
Save fumokmm/213998 to your computer and use it in GitHub Desktop.
interface ReduceOp<E, T> {
void add(E e);
T value();
}
class CounterOp<E> implements ReduceOp<E, Integer> {
private int v;
public void add(E e){++v;}
public Integer value(){return v;}
}
class CollectionAggregationOp<E> implements ReduceOp<E, Collection<E>> {
private List<E> eList = new ArrayList<E>();
public void add(E e) {
eList.add(e)
}
public Collection<E> value() {
return eList;
}
}
op = new CounterOp<String>()
op.add('a')
op.add('b')
println op.value()
op2 = new CollectionAggregationOp<String>()
op2.add('a')
op2.add('b')
println op2.value()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment