Guest User

Untitled

a guest
Jan 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. Stuff in the main method -
  2.  
  3. List l = new ArrayList();
  4. for (int i = 0; i < 10; i++) {
  5. mobify.model.Stock s = new mobify.model.Stock();
  6. s.setIdStock(i);
  7. l.add(i);
  8. if(i==5){
  9. l.add(i);
  10. }
  11. if(i==8){
  12. l.remove(i);
  13. }
  14. }
  15. List<Object> objectCount = ToolsStack.objectCount(l);
  16. for (int i = 0; i < objectCount.size(); i++) {
  17. mobify.model.Stock object = (mobify.model.Stock) objectCount.get(i);
  18. System.out.println(object.getIdStock());
  19. }
  20.  
  21.  
  22.  
  23.  
  24. public static List<Object> objectCount(List a){
  25. HashMap<Integer, Object> hashXcounter = new HashMap<Integer, Object>();
  26. Map<Integer,Object> hashXObject = new HashMap<Integer, Object>();
  27.  
  28. Map<Object, Integer> ordered = new HashMap<Object, Integer>();
  29. for (int i = 0; i < a.size(); i++) {
  30. Object object = a.get(i);
  31. if(hashXcounter.get(object.hashCode())!=null){
  32. hashXcounter.put(object.hashCode(), hashXcounter.get(object.hashCode()));
  33. }else{
  34. hashXcounter.put(object.hashCode(), 0);
  35. hashXObject.put(object.hashCode(), object);
  36. }
  37. }
  38. Collection l = hashXcounter.values();
  39. for(Map.Entry e: hashXcounter.entrySet()){
  40. Integer key = (Integer) e.getKey();
  41. Integer max = (Integer) Collections.max(l);
  42. ordered.put(hashXObject.get(key), max);
  43. l.remove(max);
  44. }
  45.  
  46. return ((List)ordered.values());
  47. }
Add Comment
Please, Sign In to add comment