Class ODataResourcePath

java.lang.Object
com.sap.cloud.sdk.datamodel.odata.client.expression.ODataResourcePath

public final class ODataResourcePath extends Object
A class that assembles resource references into a URL path. References can be entity sets, entities by key, properties, functions, actions and special endpoints like the metadata endpoint. E.g. the following resource path identifies a function invocation on the a navigational property of the entity identified by 'val':

Entity(key='val')/NavigationProperty/Model.Function(1)/ResultProperty.

Of the result only the property ResultProperty is accessed.

  • Constructor Details

    • ODataResourcePath

      public ODataResourcePath()
  • Method Details

    • of

      @Nonnull public static ODataResourcePath of(@Nonnull String segment)
      Convenience method for new ODataResourcePath().addSegment(segment). It creates a new resource path for the given path string.
      Parameters:
      segment - The string identifying the resource e.g. EntityName
      Returns:
      A new ODataResourcePath.
    • of

      @Nonnull public static ODataResourcePath of(@Nonnull String segment, @Nonnull AbstractODataParameters segmentParameter)
      Convenience method for new ODataResourcePath().addSegment(segment, segmentParameter). It creates a new resource path for the given path string and parameters.
      Parameters:
      segment - The string identifying the resource e.g. EntityName
      segmentParameter - The parameters to be included in this segment e.g. (key1='val',key2=123)
      Returns:
      A new ODataResourcePath.
    • addSegment

      @Nonnull public ODataResourcePath addSegment(@Nonnull String segment)
      Add a navigation to the path.
      Parameters:
      segment - The navigation to add. Any slashes will be encoded and not treated as segment separators.
      Returns:
      This builder instance.
    • addSegment

      @Nonnull public ODataResourcePath addSegment(@Nonnull String segment, @Nullable AbstractODataParameters parameters)
      Add a navigation with a parameters or function or action call to the path.
      Parameters:
      segment - The unencoded navigation or function or action reference to add. Any slashes will be encoded and not treated as segment separators.
      parameters - The unencoded parameters or parameters to add.
      Returns:
      This builder instance.
    • addParameterToLastSegment

      @Nonnull public ODataResourcePath addParameterToLastSegment(@Nonnull AbstractODataParameters parameters)
      Add a path parameter to the last segment. Can only be applied if the last segment added to this builder did not contain any parameters.
      Parameters:
      parameters - The unencoded parameters to add.
      Returns:
      This builder instance.
      Throws:
      IllegalStateException - When the current path is empty or the last segment already contains a parameter.
    • toEncodedPathString

      @Nonnull public String toEncodedPathString()
      Encodes the path segments and assembles them together. The returned path will always start with a leading forward slash and ends without any trailing slashes.
      Returns:
      The encoded path.
    • toEncodedPathString

      @Nonnull public String toEncodedPathString(@Nonnull UriEncodingStrategy strategy)
      Encodes the path segments and assembles them together. The returned path will always start with a leading forward slash and ends without any trailing slashes.
      Parameters:
      strategy - The URI encoding strategy.
      Returns:
      The encoded path.
    • toString

      @Nonnull public String toString()
      Builds the path segments to a full URL path.
      Overrides:
      toString in class Object
      Returns:
      The unencoded URL path.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getSegments

      @Nonnull public List<io.vavr.Tuple2<String,AbstractODataParameters>> getSegments()
      The current path as a list of its individual path segments.