Created
October 20, 2009 04:37
-
-
Save fumokmm/213998 to your computer and use it in GitHub Desktop.
ReduceOp via http://h.hatena.ne.jp/v593kdrg/9258648984710531177
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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