Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Stuff in the main method -
- List l = new ArrayList();
- for (int i = 0; i < 10; i++) {
- mobify.model.Stock s = new mobify.model.Stock();
- s.setIdStock(i);
- l.add(i);
- if(i==5){
- l.add(i);
- }
- if(i==8){
- l.remove(i);
- }
- }
- List<Object> objectCount = ToolsStack.objectCount(l);
- for (int i = 0; i < objectCount.size(); i++) {
- mobify.model.Stock object = (mobify.model.Stock) objectCount.get(i);
- System.out.println(object.getIdStock());
- }
- public static List<Object> objectCount(List a){
- HashMap<Integer, Object> hashXcounter = new HashMap<Integer, Object>();
- Map<Integer,Object> hashXObject = new HashMap<Integer, Object>();
- Map<Object, Integer> ordered = new HashMap<Object, Integer>();
- for (int i = 0; i < a.size(); i++) {
- Object object = a.get(i);
- if(hashXcounter.get(object.hashCode())!=null){
- hashXcounter.put(object.hashCode(), hashXcounter.get(object.hashCode()));
- }else{
- hashXcounter.put(object.hashCode(), 0);
- hashXObject.put(object.hashCode(), object);
- }
- }
- Collection l = hashXcounter.values();
- for(Map.Entry e: hashXcounter.entrySet()){
- Integer key = (Integer) e.getKey();
- Integer max = (Integer) Collections.max(l);
- ordered.put(hashXObject.get(key), max);
- l.remove(max);
- }
- return ((List)ordered.values());
- }
Add Comment
Please, Sign In to add comment