Created
January 13, 2018 20:08
-
-
Save markus-k/4f27a1106cbb21e5c018b1f1e9f15721 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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