@Beta public class ResourceName extends Object implements Map<String,String>
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/*");
ResourceName resourceName = ResourceName.create(template, "shelves/s1/books/b1");
assert resourceName.get("$1").equals("b1");
assert resourceName.parentName().toString().equals("shelves/s1/books");
| Modifier and Type | Class and Description |
|---|---|
static interface |
ResourceName.Resolver
Represents a resource name resolver which can be registered with this class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Deprecated.
|
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
static ResourceName |
create(PathTemplate template,
Map<String,String> values)
Creates a new resource name from a template and a value assignment for variables.
|
static ResourceName |
create(PathTemplate template,
String path)
Creates a new resource name based on given template and path.
|
static ResourceName |
createFromFullName(PathTemplate template,
String path)
Creates a new resource name based on given template and path, where the path contains an
endpoint.
|
String |
endpoint()
Returns the endpoint of this resource name, or null if none is defined.
|
Set<Map.Entry<String,String>> |
entrySet() |
boolean |
equals(Object obj) |
String |
get(Object key) |
boolean |
hasEndpoint()
Checks whether the resource name has an endpoint.
|
int |
hashCode() |
boolean |
isEmpty() |
Set<String> |
keySet() |
ResourceName |
parentName()
Returns the parent resource name.
|
String |
put(String key,
String value)
Deprecated.
|
void |
putAll(Map<? extends String,? extends String> m)
Deprecated.
|
static void |
registerResourceNameResolver(ResourceName.Resolver resolver)
Sets the resource name resolver which is used by the
resolve(Class, String) method. |
String |
remove(Object key)
Deprecated.
|
<T> T |
resolve(Class<T> resourceType,
String version)
Attempts to resolve a resource name into a resource, by calling the associated API.
|
int |
size() |
boolean |
startsWith(ResourceName parentName)
Returns true of the resource name starts with the parent resource name, i.e.
|
PathTemplate |
template()
Gets the template associated with this resource name.
|
String |
toString() |
Collection<String> |
values() |
ResourceName |
withEndpoint(String endpoint)
Returns a resource name with specified endpoint.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllpublic static void registerResourceNameResolver(ResourceName.Resolver resolver)
resolve(Class, String) method.
By default, no resolver is registered.public static ResourceName create(PathTemplate template, String path)
ValidationException - if the path does not match the template.public static ResourceName create(PathTemplate template, Map<String,String> values)
ValidationException - if not all variables in the template are bound.@Nullable public static ResourceName createFromFullName(PathTemplate template, String path)
public boolean equals(Object obj)
public int hashCode()
public PathTemplate template()
public boolean hasEndpoint()
@Nullable public String endpoint()
public ResourceName withEndpoint(String endpoint)
public ResourceName parentName()
shelves/s1/books/b1, the
parent is shelves/s1/books.public boolean startsWith(ResourceName parentName)
public <T> T resolve(Class<T> resourceType, @Nullable String version)
public boolean containsKey(Object key)
containsKey in interface Map<String,String>public boolean containsValue(Object value)
containsValue in interface Map<String,String>@Deprecated public String put(String key, String value)
@Deprecated public String remove(Object key)
@Deprecated public void putAll(Map<? extends String,? extends String> m)
@Deprecated public void clear()