Skip to content

Instantly share code, notes, and snippets.

@markus-k
Created January 13, 2018 20:08
Show Gist options
  • Save markus-k/4f27a1106cbb21e5c018b1f1e9f15721 to your computer and use it in GitHub Desktop.
Save markus-k/4f27a1106cbb21e5c018b1f1e9f15721 to your computer and use it in GitHub Desktop.
package a4;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import thingy.Item;
public class CollectorC implements Collector_I {
private ArrayList<Item> input;
public CollectorC() {
input = new ArrayList<>();
}
@Override
public Collection<Item> process(Item item) {
input.add(item);
HashSet<Item> testSet = new HashSet<>();
testSet.addAll(input);
if (testSet.size() >= 5) {
for (Item i: testSet) {
input.remove(i);
}
return testSet;
} else {
return null;
}
}
@Override
public void reset() {
input.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment