Class MapSort

java.lang.Object
dev.javatools.maputils.MapSort

public final class MapSort
extends java.lang.Object
This class has all the APIs needs to sort a Map.
 How to handle objects inside a list? Answer to that question is 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");
  • Method Summary

    Modifier and Type Method Description
    static java.util.Map getSortedMap​(java.util.Map input)
    Creates a new map that has all the fields from the input, sorts them and respond the newly created Map.
    static java.util.Map getSortedMap​(java.util.Map 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
  • Method Details

    • getSortedMap

      public static java.util.Map getSortedMap​(java.util.Map 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 static java.util.Map getSortedMap​(java.util.Map 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