复制代码
- //:DynaTrash.java
- //UsingaHashtableofVectorsandRTTI
- //toautomaticallysorttrashinto
- //vectors.Thissolution,despitethe
- //useofRTTI,isextensible.
- packagec16.dynatrash;
- importc16.trash.*;
- importjava.util.*;
- //GenericTypeMapworksinanysituation:
- classTypeMap{
- privateHashtablet=newHashtable();
- publicvoidadd(Objecto){
- Classtype=o.getClass();
- if(t.containsKey(type))
- ((Vector)t.get(type)).addElement(o);
- else{
- Vectorv=newVector();
- v.addElement(o);
- t.put(type,v);
- }
- }
- publicVectorget(Classtype){
- return(Vector)t.get(type);
- }
- publicEnumerationkeys(){returnt.keys();}
- //Returnshandletoadapterclasstoallow
- //callbacksfromParseTrash.fillBin():
- publicFillablefiller(){
- //Anonymousinnerclass:
- returnnewFillable(){
- publicvoidaddTrash(Trasht){add(t);}
- };
- }
- }
- publicclassDynaTrash{
- publicstaticvoidmain(String[]args){
- TypeMapbin=newTypeMap();
- ParseTrash.fillBin("Trash.dat",bin.filler());
- Enumerationkeys=bin.keys();
- while(keys.hasMoreElements())
- Trash.sumValue(
- bin.get((Class)keys.nextElement()));
- }
- }///:~
复制代码
- Enumerationkeys=bin.keys();
- while(keys.hasMoreElements())
- Trash.sumValue(
- bin.get((Class)keys.nextElement()));
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |