public class TemplatedResourceName implements Map<String,String>
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");
Inheritance
Object >
TemplatedResourceName
Static Methods
create(PathTemplate template, String path)
public static TemplatedResourceName create(PathTemplate template, String path)
Creates a new resource name based on given template and path. The path must match the template,
otherwise null is returned.
create(PathTemplate template, Map<String,String> values)
public static TemplatedResourceName create(PathTemplate template, Map<String,String> values)
Creates a new resource name from a template and a value assignment for variables.
createFromFullName(PathTemplate template, String path)
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.
registerResourceNameResolver(TemplatedResourceName.Resolver resolver)
public static void registerResourceNameResolver(TemplatedResourceName.Resolver resolver)
Sets the resource name resolver which is used by the <xref uid="com.google.api.pathtemplate.TemplatedResourceName.
Methods
<T>resolve(Class<T> resourceType, String version)
public T <T>resolve(Class<T> resourceType, String version)
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.
Parameters |
---|
Name | Description |
resourceType | Class<T>
|
version | String
|
clear()
containsKey(Object key)
public boolean containsKey(Object key)
Parameter |
---|
Name | Description |
key | Object
|
containsValue(Object value)
public boolean containsValue(Object value)
Parameter |
---|
Name | Description |
value | Object
|
endpoint()
Returns the endpoint of this resource name, or null if none is defined.
entrySet()
public Set<Map.Entry<String,String>> entrySet()
equals(Object obj)
public boolean equals(Object obj)
Parameter |
---|
Name | Description |
obj | Object
|
Overrides
get(Object key)
public String get(Object key)
Parameter |
---|
Name | Description |
key | Object
|
hasEndpoint()
public boolean hasEndpoint()
Checks whether the resource name has an endpoint.
hashCode()
Returns |
---|
Type | Description |
int | |
Overrides
isEmpty()
keySet()
public Set<String> keySet()
parentName()
public TemplatedResourceName parentName()
Returns the parent resource name. For example, if the name is shelves/s1/books/b1
, the
parent is shelves/s1/books
.
put(String key, String value)
public String put(String key, String value)
putAll(Map<? extends String,? extends String> m)
public void putAll(Map<? extends String,? extends String> m)
Parameter |
---|
Name | Description |
m | Map<? extends java.lang.String,? extends java.lang.String>
|
remove(Object key)
public String remove(Object key)
Parameter |
---|
Name | Description |
key | Object
|
size()
Returns |
---|
Type | Description |
int | |
startsWith(TemplatedResourceName parentName)
public boolean startsWith(TemplatedResourceName parentName)
Returns true of the resource name starts with the parent resource name, i.e. is a child of the
parent.
template()
public PathTemplate template()
Gets the template associated with this resource name.
toString()
Overrides
values()
public Collection<String> values()
withEndpoint(String endpoint)
public TemplatedResourceName withEndpoint(String endpoint)
Returns a resource name with specified endpoint.
Parameter |
---|
Name | Description |
endpoint | String
|