document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.List;
  2. import java.util.Iterator;
  3. import java.util.HashSet;
  4. import java.util.ArrayList;
  5. import java.util.Comparator;
  6. import java.util.Collections;
  7.  
  8. class Bin implements BinInterface{
  9.  
  10. List<Garbage> lista = new ArrayList<Garbage>();
  11. HashSet<Garbage> set = new HashSet<Garbage>(lista);
  12.  
  13. List<Garbage> lista2 = new ArrayList<Garbage>(set);
  14.  
  15.  
  16. List<Glass> glass= new ArrayList<Glass>();
  17. List<Recyclable> recyclable = new ArrayList<Recyclable>();
  18. List<Radioactive> radioactive = new ArrayList<Radioactive>();
  19.  
  20.  
  21.  
  22.  
  23.  
  24. public <T extends Garbage> void toBin( T sth ){
  25. lista.add(sth);
  26.  
  27. }
  28.  
  29.  
  30. public List<Garbage> getSorted( WasteType wt ){
  31. switch(wt){
  32. case RECYCLABLE:
  33. lista2.clear();
  34. for ( Garbage g : lista ) {
  35. if ( g.getWasteType() == wt)
  36. recyclable.add((Recyclable)g);
  37. }
  38. Collections.sort(recyclable, new Sort_Recyclable());
  39. lista2.addAll(recyclable);
  40.  
  41.  
  42. break;
  43. case GLASS:
  44. lista2.clear();
  45. for ( Garbage g : lista ) {
  46. if ( g.getWasteType() == wt )
  47. glass.add((Glass)g);
  48. }
  49. //glass.forEach(e->System.out.println(e));
  50. Collections.sort(glass, new Sort_Glass());
  51. for(Glass g : glass)
  52. lista2.add(g);
  53.  
  54. break;
  55. case RADIOACTIVE:
  56. lista2.clear();
  57. for ( Garbage g : lista ) {
  58. if ( g.getWasteType() == wt )
  59. radioactive.add((Radioactive)g);
  60. }
  61.  
  62. Collections.sort(radioactive, new Sort_Radioactive());
  63. lista2.addAll(radioactive);
  64.  
  65. break;
  66.  
  67.  
  68. }
  69.  
  70.  
  71. //lista.clear();
  72. //lista=glass;
  73.  
  74.  
  75. //lista2.forEach(e->System.out.println(e));
  76. return lista2;
  77. }
  78. }
  79.  
  80.  
  81. class Sort_Glass implements Comparator<Garbage>
  82. {
  83. public int compare(Garbage x,Garbage y)
  84. {
  85.  
  86. double obj1=((Glass)x).getVolume();
  87. double obj2=((Glass)y).getVolume();
  88. if(obj1<obj2) return 1;
  89. if(obj1>obj2) return -1;
  90. else return 0;
  91. }
  92. }
  93.  
  94. class Sort_Recyclable implements Comparator<Garbage>
  95. {
  96. public int compare(Garbage x,Garbage y)
  97. {
  98.  
  99. double obj1=((Recyclable)x).getWeight();
  100. double obj2=((Recyclable)y).getWeight();
  101. if(obj1<obj2) return 1;
  102. if(obj1>obj2) return -1;
  103. else return 0;
  104. }
  105. }
  106.  
  107. class Sort_Radioactive implements Comparator<Garbage>
  108. {
  109. public int compare(Garbage x,Garbage y)
  110. {
  111.  
  112. double obj1=((Radioactive)x).getRadiativeFlux();
  113. double obj2=((Radioactive)y).getRadiativeFlux();
  114. if(obj1<obj2) return 1;
  115. if(obj1>obj2) return -1;
  116. else return 0;
  117. }
  118. }
');