Class TemplatedResourceName (2.35.0)

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

Implements

Map<String,String>

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.

Parameters
Name Description
template PathTemplate
path String
Returns
Type Description
TemplatedResourceName

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.

Parameters
Name Description
template PathTemplate
values Map<String,String>
Returns
Type Description
TemplatedResourceName

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.

Parameters
Name Description
template PathTemplate
path String
Returns
Type Description
TemplatedResourceName

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.

Parameter
Name Description
resolver TemplatedResourceName.Resolver

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
Returns
Type Description
T

clear() (deprecated)

public void clear()

containsKey(Object key)

public boolean containsKey(Object key)
Parameter
Name Description
key Object
Returns
Type Description
boolean

containsValue(Object value)

public boolean containsValue(Object value)
Parameter
Name Description
value Object
Returns
Type Description
boolean

endpoint()

public String endpoint()

Returns the endpoint of this resource name, or null if none is defined.

Returns
Type Description
String

entrySet()

public Set<Map.Entry<String,String>> entrySet()
Returns
Type Description
Set<Entry<String,String>>

equals(Object obj)

public boolean equals(Object obj)
Parameter
Name Description
obj Object
Returns
Type Description
boolean
Overrides

get(Object key)

public String get(Object key)
Parameter
Name Description
key Object
Returns
Type Description
String

hasEndpoint()

public boolean hasEndpoint()

Checks whether the resource name has an endpoint.

Returns
Type Description
boolean

hashCode()

public int hashCode()
Returns
Type Description
int
Overrides

isEmpty()

public boolean isEmpty()
Returns
Type Description
boolean

keySet()

public Set<String> keySet()
Returns
Type Description
Set<String>

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.

Returns
Type Description
TemplatedResourceName

put(String key, String value) (deprecated)

public String put(String key, String value)
Parameters
Name Description
key String
value String
Returns
Type Description
String

putAll(Map<? extends String,? extends String> m) (deprecated)

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) (deprecated)

public String remove(Object key)
Parameter
Name Description
key Object
Returns
Type Description
String

size()

public int 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.

Parameter
Name Description
parentName TemplatedResourceName
Returns
Type Description
boolean

template()

public PathTemplate template()

Gets the template associated with this resource name.

Returns
Type Description
PathTemplate

toString()

public String toString()
Returns
Type Description
String
Overrides

values()

public Collection<String> values()
Returns
Type Description
Collection<String>

withEndpoint(String endpoint)

public TemplatedResourceName withEndpoint(String endpoint)

Returns a resource name with specified endpoint.

Parameter
Name Description
endpoint String
Returns
Type Description
TemplatedResourceName