Class SortMap

java.lang.Object
dev.javatools.map.SortMap

public class SortMap
extends java.lang.Object
This class has all the apis needs to sort a Map. How to use listKeys? If the Map has a list of objects and if you need to sort the list based on a field of an object, this feature will help. Here is how it works. Take the below Map as an example { "members": [ { "name": "John" "age": 22 } { "name": "Bob" "age": 18 } ] } If you need the sort the above Map based on the member name. You need to pass listKey.put("members[]", "name"); If you need the sort the above Map based on the member age. You need to pass listKey.put("members[]", "age");
  • Constructor Summary

    Constructors 
    Constructor Description
    SortMap()  
  • Method Summary

    Modifier and Type Method Description
    java.util.Map<java.lang.String,​java.lang.Object> getSortedMap​(java.util.Map<java.lang.String,​java.lang.Object> input)
    Creates a new map that has all the fields from the input, sorts them and respond the newly created Map.
    java.util.Map<java.lang.String,​java.lang.Object> getSortedMap​(java.util.Map<java.lang.String,​java.lang.Object> input, java.util.Map<java.lang.String,​java.lang.String> listKeys)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getSortedMap

      public java.util.Map<java.lang.String,​java.lang.Object> getSortedMap​(java.util.Map<java.lang.String,​java.lang.Object> input)
      Creates a new map that has all the fields from the input, sorts them and respond the newly created Map.
      Parameters:
      input - Map that needs to be sorted
      Returns:
      Map that is sorted on the keys
    • getSortedMap

      public java.util.Map<java.lang.String,​java.lang.Object> getSortedMap​(java.util.Map<java.lang.String,​java.lang.Object> input, java.util.Map<java.lang.String,​java.lang.String> listKeys)
      Parameters:
      input - Map that needs to be sorted
      listKeys - List of field names that needs to be sorted, see the class documentation for more details
      Returns:
      Map that is sorted on the keys