Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
Add Comment
Please, Sign In to add comment