Class VdmObject<ObjectT>

java.lang.Object
com.sap.cloud.sdk.datamodel.odata.helper.VdmObject<ObjectT>
Type Parameters:
ObjectT - The type of the implementing object.
Direct Known Subclasses:
VdmComplex, VdmEntity

public abstract class VdmObject<ObjectT> extends Object
Superclass of all entities which contains common elements such as a generic representation of custom fields.
  • Field Details

    • changedOriginalFields

      @Nonnull protected final transient Map<String,Object> changedOriginalFields
      A mapping of the OData field name to the original value.

      This should be updated via rememberChangedField(String, Object) on every set call of a property.

  • Constructor Details

    • VdmObject

      public VdmObject()
  • Method Details

    • getCustomFieldNames

      @Nonnull public Set<String> getCustomFieldNames()
      Returns the names of all custom fields of this object.
      Returns:
      The names of the custom fields of this object.
    • getCustomFields

      @Nonnull public Map<String,Object> getCustomFields()
      Returns all custom field names and values of this object.
      Returns:
      All names & values of custom fields as a map.
    • setCustomField

      public void setCustomField(@Nonnull String customFieldName, @Nullable Object value)
      Sets the value of a single custom field.
      Parameters:
      customFieldName - Name of the custom field.
      value - Value of the custom field.
    • setCustomField

      public <FieldT> void setCustomField(@Nonnull EntityField<ObjectT,FieldT> customField, @Nullable FieldT value)
      Sets the value of a single custom field. If the EntityField passed as parameter holds a TypeConverter, the value will be converted before it's stored.
      Type Parameters:
      FieldT - The type of the custom field to set.
      Parameters:
      customField - Name of the custom field, represented as an EntityField object.
      value - Value of the custom field.
    • hasCustomField

      public boolean hasCustomField(@Nonnull String customFieldName)
      Checks whether this object contains a custom field with the given name.
      Parameters:
      customFieldName - Name of the custom field to check for
      Returns:
      true if this entity has a custom field with the given name, false otherwise.
    • hasCustomField

      public boolean hasCustomField(@Nonnull EntityField<ObjectT,?> customField)
      Checks whether this object contains a value for the given custom field.
      Parameters:
      customField - Custom field to check for, represented as an EntityField object.
      Returns:
      true if this object has a custom field with the name of the given field, false otherwise.
    • getCustomField

      @Nullable public <FieldT> FieldT getCustomField(@Nonnull String customFieldName) throws NoSuchEntityFieldException
      This method allows for retrieval of custom fields that are added to the underlying OData services.
      Type Parameters:
      FieldT - The type of the returned field.
      Parameters:
      customFieldName - Name of the field returned by the underlying OData service.
      Returns:
      The value of the custom field. Actual type will depend on the type configured in the underlying OData service.
      Throws:
      NoSuchEntityFieldException - if no field with the given name could be found.
    • getCustomField

      @Nullable public <FieldT> FieldT getCustomField(@Nonnull EntityField<ObjectT,FieldT> customField) throws NoSuchEntityFieldException
      This method allows for retrieval of custom fields that are added to the underlying OData services. If the EntityField passed as parameter holds a TypeConverter, the value will be converted before it's returned.
      Type Parameters:
      FieldT - The type of the returned field.
      Parameters:
      customField - Field returned by the underlying OData service.
      Returns:
      The value of the custom field. Actual type will depend on the type configured in the underlying OData service.
      Throws:
      NoSuchEntityFieldException - if no field with the given name could be found.
    • getType

      @Nonnull public abstract Class<ObjectT> getType()
      Returns the class of this object.
      Returns:
      The class of this object.
    • getKey

      @Nonnull protected Map<String,Object> getKey()
      Returns the compound key of this object.
      Returns:
      The compound key of this object.
    • fromMap

      protected void fromMap(Map<String,Object> values)
      Sets the values of all custom fields contained in the given values.

      Afterwards, marks all fields as unchanged.

      Parameters:
      values - The map of custom fields to set.
    • toMapOfCustomFields

      @Nonnull protected Map<String,Object> toMapOfCustomFields()
      Returns a map of all custom fields contained in this object.
      Returns:
      A map of all custom fields contained in this object.
    • getSetOfCustomFields

      @Nonnull protected Set<String> getSetOfCustomFields()
      Returns a set of all custom field names contained in this object.
      Returns:
      A set of all custom field names contained in this object.
    • toMapOfFields

      @Nonnull protected Map<String,Object> toMapOfFields()
      Returns a map of all fields contained in this object.
      Returns:
      A map of all fields contained in this object.
    • getSetOfFields

      @Nonnull protected Set<String> getSetOfFields()
      Returns a set of all field names contained in this object.
      Returns:
      A set of all field names contained in this object.
    • toMapOfNavigationProperties

      @Nonnull protected Map<String,Object> toMapOfNavigationProperties()
      Returns a map of all navigation properties contained in this object.
      Returns:
      A map of all navigation properties contained in this object.
    • getSetOfNavigationProperties

      @Nonnull protected Set<String> getSetOfNavigationProperties()
      Returns a set of all navigation property names contained in this object.
      Returns:
      A set of all navigation property names contained in this object.
    • toMap

      @Nonnull protected Map<String,Object> toMap()
      Returns a map of all fields, navigation properties, and custom fields contained in this object.
      Returns:
      A map of all fields, navigation properties, and custom fields contained in this object.
    • getChangedFields

      @Nonnull public Map<String,Object> getChangedFields()
      Returns map of all fields which have been changed on this entity along with their updated values.
      Returns:
      Map containing all changed fields with their current value.
    • rememberChangedField

      protected void rememberChangedField(@Nonnull String fieldName, @Nullable Object valueBeforeChange)
      Remembers the original value of a changed field.
      Parameters:
      fieldName - The name of the field that is changed.
      valueBeforeChange - The original value before the change.
    • resetChangedFields

      public void resetChangedFields()
      Resets the map of all fields which have been changed on this entity.

      After calling this method, no field is considered changed, until you change the value of fields on this entity afterwards.

    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(@Nullable Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object