package com.gamingmesh.jobs.stuff;

import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.gamingmesh.jobs.container.LogAmounts;

public class Sorting {
    public static Map<String, Integer> sortDESC(Map<String, Integer> unsortMap) {

	// Convert Map to List
	List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(unsortMap.entrySet());

	// Sort list with comparator, to compare the Map values
	Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
	    @Override
	    public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
		return (o2.getValue()).compareTo(o1.getValue());
	    }
	});

	// Convert sorted map back to a Map
	Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
	for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
	    Map.Entry<String, Integer> entry = it.next();
	    sortedMap.put(entry.getKey(), entry.getValue());
	}
	return sortedMap;
    }

    public static Map<String, Double> sortDoubleDESC(Map<String, Double> unsortMap) {

	// Convert Map to List
	List<Map.Entry<String, Double>> list = new LinkedList<Map.Entry<String, Double>>(unsortMap.entrySet());

	// Sort list with comparator, to compare the Map values
	Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
	    @Override
	    public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
		return (o2.getValue()).compareTo(o1.getValue());
	    }
	});

	// Convert sorted map back to a Map
	Map<String, Double> sortedMap = new LinkedHashMap<String, Double>();
	for (Iterator<Map.Entry<String, Double>> it = list.iterator(); it.hasNext();) {
	    Map.Entry<String, Double> entry = it.next();
	    sortedMap.put(entry.getKey(), entry.getValue());
	}
	return sortedMap;
    }

    public static Map<LogAmounts, Double> sortDoubleDESCByLog(Map<LogAmounts, Double> unsortMap) {

	// Convert Map to List
	List<Map.Entry<LogAmounts, Double>> list = new LinkedList<Map.Entry<LogAmounts, Double>>(unsortMap.entrySet());

	// Sort list with comparator, to compare the Map values
	Collections.sort(list, new Comparator<Map.Entry<LogAmounts, Double>>() {
	    @Override
	    public int compare(Map.Entry<LogAmounts, Double> o1, Map.Entry<LogAmounts, Double> o2) {
		return (o2.getValue()).compareTo(o1.getValue());
	    }
	});

	// Convert sorted map back to a Map
	Map<LogAmounts, Double> sortedMap = new LinkedHashMap<LogAmounts, Double>();
	for (Iterator<Map.Entry<LogAmounts, Double>> it = list.iterator(); it.hasNext();) {
	    Map.Entry<LogAmounts, Double> entry = it.next();
	    sortedMap.put(entry.getKey(), entry.getValue());
	}
	return sortedMap;
    }

    public static Map<String, Integer> sortASC(Map<String, Integer> unsortMap) {

	// Convert Map to List
	List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(unsortMap.entrySet());

	// Sort list with comparator, to compare the Map values
	Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
	    @Override
	    public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
		return (o1.getValue()).compareTo(o2.getValue());
	    }
	});

	// Convert sorted map back to a Map
	Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
	for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
	    Map.Entry<String, Integer> entry = it.next();
	    sortedMap.put(entry.getKey(), entry.getValue());
	}
	return sortedMap;
    }
}

@@ -478,34 +478,8 @@
 ist%3C
-Map.Entry%3CString, Integer%3E
 %3E(un
@@ -492,32 +492,32 @@
 p.entrySet());%0D%0A
+
 %0D%0A%09// Sort list 
@@ -891,39 +891,24 @@
 nkedHashMap%3C
-String, Integer
 %3E();%0D%0A%09for (
@@ -1297,33 +1297,8 @@
 ist%3C
-Map.Entry%3CString, Double%3E
 %3E(un
@@ -1710,30 +1710,16 @@
 HashMap%3C
-String, Double
 %3E();%0D%0A%09f
@@ -2127,37 +2127,8 @@
 ist%3C
-Map.Entry%3CLogAmounts, Double%3E
 %3E(un
@@ -2556,34 +2556,16 @@
 HashMap%3C
-LogAmounts, Double
 %3E();%0D%0A%09f
@@ -2960,34 +2960,8 @@
 ist%3C
-Map.Entry%3CString, Integer%3E
 %3E(un
@@ -3317,32 +3317,32 @@
  back to a Map%0D%0A
+
 %09Map%3CString, Int
@@ -3377,31 +3377,16 @@
 HashMap%3C
-String, Integer
 %3E();%0D%0A%09f

Update Sorting.java