A line of code speaks a thousand words :-)
Suppose you want to store a counter with each unique element in set (so that it resembles multiset a little). Suppose you have multiple threads raging around. Well, if it seemed like problem, now I hope it does not.
First, let"s take care of counting:
```
public final class Counter implements Aggregator {
@Override
public Integer aggregate(Integer value, Integer current) {
if (value == null)
return current + 1;
return current + value;
}
@Override
public Integer initial() {
return 1;
}
}
```
And plug your counter into this set:
AggregatedSet
set = new AggregatedSet(new Counter());set.add("A"); //treat it like set.add("A"); //now, it"s set.add("A", 2); //
Voila!
Let"s say we