2015-05-18 23:05:20 -07:00
|
|
|
|
//: patterns/recycleap/RecycleAP.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-05-05 11:20:13 -07:00
|
|
|
|
// Recycling with RTTI and Prototypes.
|
|
|
|
|
package patterns.recycleap;
|
|
|
|
|
import patterns.trash.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
public class RecycleAP {
|
|
|
|
|
public static void main(String[] args) {
|
2015-05-18 23:05:20 -07:00
|
|
|
|
ArrayList<Trash> bin = new ArrayList<>();
|
2015-05-05 11:20:13 -07:00
|
|
|
|
// Fill up the Trash bin:
|
|
|
|
|
ParseTrash.fillBin("Trash.dat", bin);
|
2015-05-27 23:30:19 -07:00
|
|
|
|
List<Glass> glassBin = new ArrayList<>();
|
|
|
|
|
List<Paper> paperBin = new ArrayList<>();
|
|
|
|
|
List<Aluminum> alBin = new ArrayList<>();
|
2015-05-05 11:20:13 -07:00
|
|
|
|
// Sort the Trash:
|
2015-05-27 23:30:19 -07:00
|
|
|
|
for(Trash t : bin) {
|
|
|
|
|
// RTTI to discover Trash type:
|
2015-05-05 11:20:13 -07:00
|
|
|
|
if(t instanceof Aluminum)
|
2015-05-27 23:30:19 -07:00
|
|
|
|
alBin.add((Aluminum)t);
|
2015-05-05 11:20:13 -07:00
|
|
|
|
if(t instanceof Paper)
|
2015-05-27 23:30:19 -07:00
|
|
|
|
paperBin.add((Paper)t);
|
2015-05-05 11:20:13 -07:00
|
|
|
|
if(t instanceof Glass)
|
2015-05-27 23:30:19 -07:00
|
|
|
|
glassBin.add((Glass)t);
|
2015-05-05 11:20:13 -07:00
|
|
|
|
}
|
|
|
|
|
Trash.sumValue(alBin);
|
|
|
|
|
Trash.sumValue(paperBin);
|
|
|
|
|
Trash.sumValue(glassBin);
|
|
|
|
|
Trash.sumValue(bin);
|
|
|
|
|
}
|
|
|
|
|
} ///:~
|