Package com.google.api.pathtemplate
Class TemplatedResourceName
- java.lang.Object
-
- com.google.api.pathtemplate.TemplatedResourceName
-
public class TemplatedResourceName extends Object 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. TheResourceNameclass 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 Classes Modifier and Type Class Description static interfaceTemplatedResourceName.ResolverRepresents a resource name resolver which can be registered with this class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()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.Stringendpoint()Returns the endpoint of this resource name, or null if none is defined.Set<Map.Entry<String,String>>entrySet()booleanequals(Object obj)Stringget(Object key)booleanhasEndpoint()Checks whether the resource name has an endpoint.inthashCode()booleanisEmpty()Set<String>keySet()TemplatedResourceNameparentName()Returns the parent resource name.Stringput(String key, String value)Deprecated.voidputAll(Map<? extends String,? extends String> m)Deprecated.static voidregisterResourceNameResolver(TemplatedResourceName.Resolver resolver)Sets the resource name resolver which is used by theresolve(Class, String)method.Stringremove(Object key)Deprecated.<T> Tresolve(Class<T> resourceType, String version)Attempts 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.PathTemplatetemplate()Gets the template associated with this resource name.StringtoString()Collection<String>values()TemplatedResourceNamewithEndpoint(String endpoint)Returns a resource name with specified endpoint.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
registerResourceNameResolver
public static void registerResourceNameResolver(TemplatedResourceName.Resolver resolver)
Sets the resource name resolver which is used by theresolve(Class, String)method. By default, no resolver is registered.
-
create
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.- Throws:
ValidationException- if the path does not match the template.
-
create
public static TemplatedResourceName create(PathTemplate template, Map<String,String> values)
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.
-
equals
public boolean equals(Object obj)
-
hashCode
public int hashCode()
-
template
public PathTemplate template()
Gets the template associated with this resource name.
-
hasEndpoint
public boolean hasEndpoint()
Checks whether the resource name has an endpoint.
-
endpoint
@Nullable public String endpoint()
Returns the endpoint of this resource name, or null if none is defined.
-
withEndpoint
public TemplatedResourceName withEndpoint(String endpoint)
Returns a resource name with specified endpoint.
-
parentName
public TemplatedResourceName parentName()
Returns the parent resource name. For example, if the name isshelves/s1/books/b1, the parent isshelves/s1/books.
-
startsWith
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.
-
resolve
public <T> T resolve(Class<T> resourceType, @Nullable 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.
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<String,String>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<String,String>
-
put
@Deprecated public String put(String key, String value)
Deprecated.
-
remove
@Deprecated public String remove(Object key)
Deprecated.
-
putAll
@Deprecated public void putAll(Map<? extends String,? extends String> m)
Deprecated.
-
clear
@Deprecated public void clear()
Deprecated.
-
-