Class MapUpdate

java.lang.Object
dev.javatools.maputils.MapUpdate

public class MapUpdate
extends java.lang.Object
You can add, update, delete any element in the map by specifying the path in the following format.

 Example 1:
  person.address.zip - will perform operations on the element at that location in the map.
  Map
      person: address
          address : zip
              zip : <value> -- Performs the operation this field
 Example 2:
  person.address[2].zip - will perform operations on the element at that location in the map.
  Map
      person: address[]
          address[1]: .....
          address[2] : zip
              zip : <value> -- Performs the operation this field
 
  • Constructor Summary

    Constructors 
    Constructor Description
    MapUpdate()  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.Object get​(java.lang.String mapPath, java.util.Map map)
    Currently it has the basic implementation.
    static void set​(java.lang.String mapPath, java.util.Map sourceMap, java.lang.Object value)
    Possible values for destination path 1.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • get

      public static java.lang.Object get​(java.lang.String mapPath, java.util.Map map)
      Currently it has the basic implementation. It can set a value at a specific map path If there is a list in the path, you need to specify it as []
        Example:
        name.friends[].address.city
        The above path will get the first friend's city address.
       
      TODO: Need to handle objects inside the list, similar to the "set" method implementation.
      Parameters:
      mapPath - path to the field in Map.
      map - Source map that needs to be searched
      Returns:
      the value at the path specified will be returned, if the path des not exist, it will return null.
    • set

      public static void set​(java.lang.String mapPath, java.util.Map sourceMap, java.lang.Object value)
       Possible values for destination path
       1. name - field at the root level
       2. primaryAddress.street - field in an inner object
       3. associatedAddresses[] - add an (any)object to a list, object will be added at the end of the list
       4. associatedAddresses[1] - will add associated object at location 1 in the list,
          if there is an object that is already existing at that location in that list, then it will be overwritten}
       5. associatedAddresses[{state=CA}].street street - address will be updated with the value where associatedAddresses state is california
       5. associatedAddresses[{state:CA}, {zip:94599}].street - street address will be updated with the value where associatedAddresses state is california and zip is 94599
       6. friends[{name=Art Venere}].age - updates the age of a friend whos name is "Art Venere"
       7. friends[{name=Art Venere}].primaryAddress.street
       8. friends[{name=Art Venere}].associatedAddresses[] {associated address of the friend should be added at the end of the list, if exists, override}
       9. friends[{name=Art Venere}].associatedAddresses[{state=CA}].street
       10. friends[{name=Art Venere}].associatedAddresses[{state=CA},{city:Irving}].street
       Current implementation will assume that the map has 1. map or 2. list or any terminal object (String/Integer/..) as the value for any given key.
       Current implementation does not support Set or custom objects in the Map for this operation.
       

      Parameters:
      mapPath - Path in the Map
      sourceMap - the map that needs to be updated
      value - the alue that needs to be updated with in the path specified.