Package com.sap.cds

Interface CdsData

All Superinterfaces:
JSONizable, Map<String,Object>
All Known Subinterfaces:
Row

public interface CdsData extends Map<String,Object>, JSONizable
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().
  • Field Details

  • Method Details

    • create

      static CdsData create()
      Creates a new CdsData instance.
      Returns:
      an empty CdsData instance
    • create

      static CdsData create(Map<String,Object> backingMap)
      Returns a CdsData instance backed by the given map.
      Parameters:
      backingMap - the backing data map
      Returns:
      a CdsData instance backed by backingMap
    • get

      Object get(Object key)
      Returns the value to which the specified key is mapped. If no value is found, null is returned, see Map.get(Object). Path access to nested maps is deprecated, instead use getPath(String).
      Specified by:
      get in interface Map<String,Object>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this map contains no mapping for the key
    • getPath

      <T> T getPath(String path)
      Returns the value to which the specified path (see containsPath(java.lang.String)) is mapped. If no value is found, null is returned. Dots in the path are interpreted as separators, use get(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

      <T> T getPathOrDefault(String path, T defaultValue)
      Returns the value to which the specified path (see containsPath(java.lang.String)) is mapped, or defaultValue if this map contains no mapping for the path. Dots in the path are interpreted as separators, use Map.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 returned
      defaultValue - 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

      <T> T putPath(String path, T value)
      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 associated
      value - 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

      <T> T putPathIfAbsent(String path, T value)
      If the specified path (see containsPath(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 associated
      value - 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

      boolean containsPath(String path)
      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

      <T> T removePath(String path)
      Removes the mapping for a path (see containsPath(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

      default <T extends CdsData> T forRemoval()
      Marks this data instance for removal inside of a delta list.
      Returns:
      this data instance
    • forRemoval

      <T extends CdsData> T forRemoval(boolean remove)
      Marks or unmarks this data instance for removal inside of a delta 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 a delta list.
      Returns:
      true if this instance if marked for removal
    • getMetadata

      <T> T getMetadata(String key)
      Returns the metadata value to which the specified key is mapped. If no value is found, null is returned. Metadata key-value pairs are not stored in the Map.entrySet() of this Map.
      Type Parameters:
      T - the type of the associated metadata value
      Parameters:
      key - the key whose associated metadata value is to be returned
      Returns:
      the metadata value to which the specified key is mapped, or null if there was no mapping for the key
    • putMetadata

      <T> T putMetadata(String key, T value)
      Associates the specified metadata value with the specified key. Metadata key-value pairs are not stored in the Map.entrySet() of this Map.
      Type Parameters:
      T - the type of the associated metadata value
      Parameters:
      key - the key with which the specified metadata value is to be associated
      value - the metadata value to be associated with the specified key
      Returns:
      the previous metadata value associated with the key, or null if there was no mapping for the key