Class ResourcePathDeclaration
/users/{userId}.
You may obtain instances via the fromPath(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.
ResourcePathDeclaration instances must start with the / character and may contain placeholders denoted by single-mustache syntax.
For example, the ResourcePathDeclaration /users/{userId} has a placeholder named userId.
A ResourcePathDeclaration is intended for compile-time Resource Method HTTP URL path declarations.
The corresponding runtime type is ResourcePath and functionality is provided to check if the two "match" via matches(ResourcePath).
For example, a ResourcePathDeclaration /users/{userId} would match ResourcePath /users/123.
Please note the following restrictions on ResourcePathDeclaration structure:
1. It is not legal to use the same placeholder name more than once in a ResourcePathDeclaration.
For example:
/users/{userId}is valid resource path/users/{userId}/roles/{roleId}is valid resource path/users/{userId}/other/{userId}is an invalid resource path
/-delimited path component in which they reside.
For example:
/users/{userId}is a valid resource path/users/{userId}/detailsis a valid resource path/users/prefix{userId}is an invalid resource path
In addition to simple placeholders, this version supports a special "varargs" placeholder indicated by a trailing *
in the placeholder name. For example, /static/{filePath*}. When present, the varargs placeholder must appear only once
and as the last component in the path.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents a/-delimited part of aResourcePathDeclaration.static enumHow to interpret aResourcePathDeclaration.Componentof aResourcePathDeclaration- is it literal text or a placeholder? -
Method Summary
Modifier and TypeMethodDescriptionbooleanextractPlaceholders(@NonNull ResourcePath resourcePath) What is the mapping between this resource path declaration's placeholder names to the given resource path's placeholder values?static @NonNull ResourcePathDeclarationVends an instance that represents a compile-time path declaration, for example/users/{userId}.What are the/-delimited components of this resource path declaration?getPath()What is the string representation of this resource path declaration?Gets theResourcePathDeclaration.ComponentType.VARARGScomponent in this declaration, if any.inthashCode()Is this resource path declaration comprised of all "literal" components (that is, no placeholders)?matches(@NonNull ResourcePath resourcePath) Does this resource path declaration match the given resource path (taking placeholders/varargs into account, if present)?toString()
-
Method Details
-
fromPath
Vends an instance that represents a compile-time path declaration, for example/users/{userId}.- Parameters:
path- a compile-time path declaration that may include placeholders
-
getVarargsComponent
Gets theResourcePathDeclaration.ComponentType.VARARGScomponent in this declaration, if any.- Returns:
- the
ResourcePathDeclaration.ComponentType.VARARGScomponent in this declaration, orOptional.empty()if none exists.
-
matches
Does this resource path declaration match the given resource path (taking placeholders/varargs into account, if present)?For example, resource path declaration
/users/{userId}would match/users/123.- Parameters:
resourcePath- the resource path against which to match- Returns:
trueif the paths match,falseotherwise
-
extractPlaceholders
public @NonNull Map<@NonNull String, @NonNull String> extractPlaceholders(@NonNull ResourcePath resourcePath) What is the mapping between this resource path declaration's placeholder names to the given resource path's placeholder values?For example, placeholder extraction for resource path declaration
/users/{userId}and resource path/users/123would result in a value equivalent toMap.of("userId", "123").Resource path declaration placeholder values are automatically URL-decoded. For example, placeholder extraction for resource path declaration
/users/{userId}and resource path/users/ab%20cwould result in a value equivalent toMap.of("userId", "ab c").Varargs placeholders will combine all remaining path components (joined with @{code /}).
- Parameters:
resourcePath- runtime version of this resource path declaration, used to provide placeholder values- Returns:
- a mapping of placeholder names to values, or the empty map if there were no placeholders
- Throws:
IllegalArgumentException- if the provided resource path does not match this resource path declaration, i.e.matches(ResourcePath)isfalse
-
getPath
-
getComponents
What are the/-delimited components of this resource path declaration?- Returns:
- the components, or the empty list if this path is equal to
/
-
isLiteral
-
toString
-
equals
-
hashCode
-