Class ResourcePath

java.lang.Object
com.soklet.core.ResourcePath

@ThreadSafe public class ResourcePath extends Object
An HTTP URL path used to resolve a Resource Method at runtime, such as /users/123.

You may obtain instances via the of(String) factory method.

Note: this type is not normally used by Soklet applications unless they support Server-Sent Events or choose to implement a custom ResourceMethodResolver.

The corresponding compile-time type for ResourcePath is ResourcePathDeclaration and functionality is provided to check if the two "match" via matches(ResourcePathDeclaration).

For example, a ResourcePath /users/123 would match ResourcePathDeclaration /users/{userId}.

Author:
Mark Allen
  • Method Details

    • of

      @Nonnull public static ResourcePath of(@Nonnull String path)
      Vends an instance that represents a runtime representation of a resource path, for example /users/123.

      This is in contrast to ResourcePathDeclaration, which represents compile-time path declarations that may include placeholders, e.g. /users/{userId}.

      Parameters:
      path - a runtime path which may not include placeholders
    • matches

      @Nonnull public Boolean matches(@Nonnull ResourcePathDeclaration resourcePathDeclaration)
      Does this resource path match the given resource path (taking placeholders into account, if present)?

      For example, resource path /users/123 would match the resource path declaration /users/{userId}.

      Parameters:
      resourcePathDeclaration - the resource path against which to match
      Returns:
      true if the paths match, false otherwise
    • extractPlaceholders

      What is the mapping between this resource path's placeholder values to the given resource path declaration's placeholder names?

      For example, placeholder extraction for resource path /users/123 and resource path declaration /users/{userId} would result in a value equivalent to Map.of("userId", "123").

      Resource path placeholder values are automatically URL-decoded. For example, placeholder extraction for resource path declaration /users/{userId} and resource path /users/ab%20c would result in a value equivalent to Map.of("userId", "ab c").

      Parameters:
      resourcePathDeclaration - compile-time resource path, used to provide placeholder names
      Returns:
      a mapping of placeholder names to values, or the empty map if there were no placeholders
      Throws:
      IllegalArgumentException - if the provided resource path declaration does not match this resource path, i.e. matches(ResourcePathDeclaration) is false
    • getPath

      What is the string representation of this resource path?
      Returns:
      the string representation of this resource path, which must start with /
    • getComponents

      What are the /-delimited components of this resource path?
      Returns:
      the components, or the empty list if this path is equal to /
    • toString

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

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

      public int hashCode()
      Overrides:
      hashCode in class Object