Package com.sap.cds
Interface CdsData
- All Superinterfaces:
JSONizable
,Map<String,
Object>
- All Known Subinterfaces:
Row
Represents data of CDS objects, which can be accessed as a
Map<String, Object>
and hold additional metadata.
To simplify access to nested data representing deep structures, path access
is supported via containsPath(java.lang.String)
, putPath(java.lang.String, T)
, getPath(java.lang.String)
and removePath(java.lang.String)
. CdsData can conveniently be serialized to JSON using
JSONizable.toJson()
.-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsPath
(String path) Returns true if this map contains a mapping for the specified path.static CdsData
create()
Creates a newCdsData
instance.static CdsData
Returns aCdsData
instance backed by the given map.default <T extends CdsData>
TMarks this data instance for removal inside of adelta list
.<T extends CdsData>
TforRemoval
(boolean remove) Marks or unmarks this data instance for removal inside of adelta list
.Returns the value to which the specified key is mapped.<T> T
Returns the value to which the specified path (seecontainsPath(java.lang.String)
) is mapped.<T> T
getPathOrDefault
(String path, T defaultValue) Returns the value to which the specified path (seecontainsPath(java.lang.String)
) is mapped, or defaultValue if this map contains no mapping for the path.boolean
Indicates if this data instance is marked for removal inside of adelta list
.<T> T
Associates the specified value with the specified path in this map.<T> T
putPathIfAbsent
(String path, T value) If the specified path (seecontainsPath(java.lang.String)
) is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.<T> T
removePath
(String path) Removes the mapping for a path (seecontainsPath(java.lang.String)
) from this map if it is present (optional operation).Methods inherited from interface com.sap.cds.JSONizable
toJson
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Field Details
-
factory
-
-
Method Details
-
create
Creates a newCdsData
instance.- Returns:
- an empty CdsData instance
-
create
Returns aCdsData
instance backed by the given map.- Parameters:
backingMap
- the backing data map- Returns:
- a
CdsData
instance backed by backingMap
-
get
Returns the value to which the specified key is mapped. If no value is found, null is returned, seeMap.get(Object)
. Path access to nested maps is deprecated, instead usegetPath(String)
. -
getPath
Returns the value to which the specified path (seecontainsPath(java.lang.String)
) is mapped. If no value is found, null is returned. Dots in the path are interpreted as separators, useget(java.lang.Object)
to access values with keys that contain dots.- Type Parameters:
T
- the type of the associated value- Parameters:
path
- the path whose associated value is to be returned- Returns:
- the value to which the specified path is mapped, or null if this map contains no mapping for the path
-
getPathOrDefault
Returns the value to which the specified path (seecontainsPath(java.lang.String)
) is mapped, or defaultValue if this map contains no mapping for the path. Dots in the path are interpreted as separators, useMap.getOrDefault(java.lang.Object, V)
to access values with keys that contain dots.- Type Parameters:
T
- the type of the associated value- Parameters:
path
- the path whose associated value is to be returneddefaultValue
- the default mapping for the path- Returns:
- the value to which the specified path is mapped, or defaultValue if this map contains no mapping for the path
-
putPath
Associates the specified value with the specified path in this map. If the map previously contained a mapping for the path (containsPath(java.lang.String)
is true), the old value is replaced by the specified value. Creates nested maps along the path, if a path segment (except for the last segment) is not mapped.- Type Parameters:
T
- the type of the associated value- Parameters:
path
- the path with which the specified value is to be associatedvalue
- the value to be associated with the specified path- Returns:
- the previous value associated with the path, or null if there was no mapping for the path
-
putPathIfAbsent
If the specified path (seecontainsPath(java.lang.String)
) is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value. Creates nested maps along the path, if a path segment (except for the last segment) is not mapped.- Type Parameters:
T
- the type of the associated value- Parameters:
path
- the path with which the specified value is to be associatedvalue
- the value to be associated with the specified path- Returns:
- the previous value associated with the path, or null if there was no mapping for the path
-
containsPath
Returns true if this map contains a mapping for the specified path. A path consists of one or many segments separated by a dot, every path segment is used as key of a nested map.- Parameters:
path
- the path to a nested map's key whose presence is to be tested- Returns:
- true if this or the nested map addressed by the path contains a mapping for the specified key
-
removePath
Removes the mapping for a path (seecontainsPath(java.lang.String)
) from this map if it is present (optional operation). Returns the value previously associated with the path, or null if the map contained no mapping for the path. The map will not contain a mapping for the specified path once the call returns.- Parameters:
path
- the path whose mapping is to be removed from the map- Returns:
- the previous value associated with the path, or null if there was no mapping for the path.
-
forRemoval
Marks this data instance for removal inside of adelta list
.- Returns:
- this data instance
-
forRemoval
Marks or unmarks this data instance for removal inside of adelta list
.- Parameters:
remove
- true to mark for removal, false to unmark- Returns:
- this data instance
-
isForRemoval
boolean isForRemoval()Indicates if this data instance is marked for removal inside of adelta list
.- Returns:
- true if this instance if marked for removal
-