Package com.google.api.pathtemplate
Class TemplatedResourceName
java.lang.Object
com.google.api.pathtemplate.TemplatedResourceName
Class for representing and working with resource names.
A resource name is represented by PathTemplate, an assignment to variables in the
template, and an optional endpoint. The ResourceName class implements the map interface
(unmodifiable) to work with the variable assignments, and has methods to reproduce the string
representation of the name, to construct new names, and to dereference names into resources.
As a resource name essentially represents a match of a path template against a string, it can be also used for other purposes than naming resources. However, not all provided methods may make sense in all applications.
Usage examples:
PathTemplate template = PathTemplate.create("shelves/*/books/*");
TemplatedResourceName resourceName = TemplatedResourceName.create(template, "shelves/s1/books/b1");
assert resourceName.get("$1").equals("b1");
assert resourceName.parentName().toString().equals("shelves/s1/books");
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents a resource name resolver which can be registered with this class. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Deprecated.booleancontainsKey(Object key) booleancontainsValue(Object value) static TemplatedResourceNamecreate(PathTemplate template, String path) Creates a new resource name based on given template and path.static TemplatedResourceNamecreate(PathTemplate template, Map<String, String> values) Creates a new resource name from a template and a value assignment for variables.static TemplatedResourceNamecreateFromFullName(PathTemplate template, String path) Creates a new resource name based on given template and path, where the path contains an endpoint.endpoint()Returns the endpoint of this resource name, or null if none is defined.entrySet()booleanbooleanChecks whether the resource name has an endpoint.inthashCode()booleanisEmpty()keySet()Returns the parent resource name.Deprecated.voidDeprecated.static voidSets the resource name resolver which is used by theresolve(Class, String)method.Deprecated.<T> TAttempts to resolve a resource name into a resource, by calling the associated API.intsize()booleanstartsWith(TemplatedResourceName parentName) Returns true of the resource name starts with the parent resource name, i.e.template()Gets the template associated with this resource name.toString()values()withEndpoint(String endpoint) Returns a resource name with specified endpoint.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Method Details
-
registerResourceNameResolver
Sets the resource name resolver which is used by theresolve(Class, String)method. By default, no resolver is registered. -
create
Creates a new resource name based on given template and path. The path must match the template, otherwise null is returned.- Throws:
ValidationException- if the path does not match the template.
-
create
Creates a new resource name from a template and a value assignment for variables.- Throws:
ValidationException- if not all variables in the template are bound.
-
createFromFullName
@Nullable public static TemplatedResourceName createFromFullName(PathTemplate template, String path) Creates a new resource name based on given template and path, where the path contains an endpoint. If the path does not match, null is returned. -
toString
-
equals
-
hashCode
public int hashCode() -
template
Gets the template associated with this resource name. -
hasEndpoint
public boolean hasEndpoint()Checks whether the resource name has an endpoint. -
endpoint
Returns the endpoint of this resource name, or null if none is defined. -
withEndpoint
Returns a resource name with specified endpoint. -
parentName
Returns the parent resource name. For example, if the name isshelves/s1/books/b1, the parent isshelves/s1/books. -
startsWith
Returns true of the resource name starts with the parent resource name, i.e. is a child of the parent. -
resolve
Attempts to resolve a resource name into a resource, by calling the associated API. The resource name must have an endpoint. An optional version can be specified to determine in which version of the API to call. -
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<String,String>
-
containsValue
- Specified by:
containsValuein interfaceMap<String,String>
-
get
-
put
Deprecated. -
remove
Deprecated. -
putAll
Deprecated. -
clear
Deprecated. -
keySet
-
values
-
entrySet
-