Class TemplatedResourceName (2.3.1)

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
NameDescription
templatePathTemplate
pathString
Returns
TypeDescription
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
NameDescription
templatePathTemplate
valuesMap<String,String>
Returns
TypeDescription
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
NameDescription
templatePathTemplate
pathString
Returns
TypeDescription
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
NameDescription
resolverTemplatedResourceName.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
NameDescription
resourceTypeClass<T>
versionString
Returns
TypeDescription
T

clear()

public void clear()

containsKey(Object key)

public boolean containsKey(Object key)
Parameter
NameDescription
keyObject
Returns
TypeDescription
boolean

containsValue(Object value)

public boolean containsValue(Object value)
Parameter
NameDescription
valueObject
Returns
TypeDescription
boolean

endpoint()

public String endpoint()

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

Returns
TypeDescription
String

entrySet()

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

equals(Object obj)

public boolean equals(Object obj)
Parameter
NameDescription
objObject
Returns
TypeDescription
boolean
Overrides

get(Object key)

public String get(Object key)
Parameter
NameDescription
keyObject
Returns
TypeDescription
String

hasEndpoint()

public boolean hasEndpoint()

Checks whether the resource name has an endpoint.

Returns
TypeDescription
boolean

hashCode()

public int hashCode()
Returns
TypeDescription
int
Overrides

isEmpty()

public boolean isEmpty()
Returns
TypeDescription
boolean

keySet()

public Set<String> keySet()
Returns
TypeDescription
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
TypeDescription
TemplatedResourceName

put(String key, String value)

public String put(String key, String value)
Parameters
NameDescription
keyString
valueString
Returns
TypeDescription
String

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

public void putAll(Map<? extends String,? extends String> m)
Parameter
NameDescription
mMap<? extends java.lang.String,? extends java.lang.String>

remove(Object key)

public String remove(Object key)
Parameter
NameDescription
keyObject
Returns
TypeDescription
String

size()

public int size()
Returns
TypeDescription
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
NameDescription
parentNameTemplatedResourceName
Returns
TypeDescription
boolean

template()

public PathTemplate template()

Gets the template associated with this resource name.

Returns
TypeDescription
PathTemplate

toString()

public String toString()
Returns
TypeDescription
String
Overrides

values()

public Collection<String> values()
Returns
TypeDescription
Collection<String>

withEndpoint(String endpoint)

public TemplatedResourceName withEndpoint(String endpoint)

Returns a resource name with specified endpoint.

Parameter
NameDescription
endpointString
Returns
TypeDescription
TemplatedResourceName