I have implemented a LinkedHashMap to store map entries sorted by a specific business rule, and then sending it to the client. However, I am facing an issue where my AJAX response is always sorted by the map key instead of the business rule.
Here is the code for my sorting function:
protected Map<Long, String> sortWarehousesMap(Map<Long, String> warehousesMapTemp) {
List<Map.Entry<Long, String>> entries = new ArrayList<Map.Entry<Long, String>>(warehousesMapTemp.entrySet());
Collections.sort(entries, new Comparator<Map.Entry<Long, String>>() {
public int compare(Map.Entry<Long, String> a, Map.Entry<Long, String> b) {
return a.getValue().compareTo(b.getValue());
}
});
Map<Long, String> sortedWarehousesMapTemp = new LinkedHashMap<Long, String>();
for (Map.Entry<Long, String> entry : entries) {
sortedWarehousesMapTemp.put(entry.getKey(), entry.getValue());
}
return sortedWarehousesMapTemp;
}
I would appreciate any help or insights into what may be causing the issue in my code.