Package dev.javatools.maputils
Class MapProperty
java.lang.Object
dev.javatools.maputils.MapProperty
public class MapProperty
extends java.lang.Object
Path format examples
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.
-
Constructor Summary
Constructors Constructor Description MapProperty() -
Method Summary
Modifier and Type Method Description static java.lang.Objectget(java.lang.String fieldPath, java.util.Map sourceMap)Currently it has the basic implementation.
-
Constructor Details
-
MapProperty
public MapProperty()
-
-
Method Details
-
get
public static java.lang.Object get(java.lang.String fieldPath, java.util.Map sourceMap)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:
fieldPath- path to the field in Map.sourceMap- 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.
-