| 26 | } |
| 27 | |
| 28 | class TrashBinList<T extends Trash> |
| 29 | extends ArrayList<TrashBin<? extends T>> { // [1] |
| 30 | @SuppressWarnings("unchecked") |
| 31 | public TrashBinList(Class<? extends T>... types) { |
| 32 | for(Class<? extends T> type : types) |
| 33 | add(new TrashBin<>(type)); |
| 34 | } |
| 35 | public boolean sort(T t) { |
| 36 | for(TrashBin<? extends T> ts : this) |
| 37 | if(ts.grab(t)) |
| 38 | return true; |
| 39 | return false; // TrashBin not found for t |
| 40 | } |
| 41 | public void sortBin(TrashBin<T> bin) { // [2] |
| 42 | for(T trash : bin) |
| 43 | if(!sort(trash)) |
| 44 | throw new RuntimeException( |
| 45 | "Bin not found for " + trash); |
| 46 | } |
| 47 | public void show() { |
| 48 | for(TrashBin<? extends T> tbin : this) { |
| 49 | String typeName = tbin.binType.getSimpleName(); |
| 50 | TrashValue.sum(tbin, typeName); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | public class RecycleC { |
| 56 | public static void main(String[] args) { |
nothing calls this directly
no outgoing calls
no test coverage detected