MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / TrashBinList

Class TrashBinList

patterns/recyclec/RecycleC.java:28–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28class TrashBinList<T extends Trash>
29extends 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
55public class RecycleC {
56 public static void main(String[] args) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected