Class ResourceIdentifier
java.lang.Object
com.palantir.ri.ResourceIdentifier
Defines a common format for wrapping existing unique identifiers to provide additional context. This class
provides utility method:
#of(String) to parse an existing identifier or the ability to generate new
identifiers by using provided context with method #of(String, String, String).
Resource identifier specification:
Resource Identifiers contain 4 components, prefixed by a format identifier ri and separated with periods:
ri.<service>.<instance>.<type>.<locator>
- Service: a string that represents the service (or application) that namespaces the rest of the identifier.
Must conform with regex pattern
[a-z][a-z0-9\-]* - Instance: an optionally empty string that represents a specific service cluster, to allow disambiguation of
artifacts from different service clusters. Must conform to regex pattern
([a-z0-9][a-z0-9\-]*)? - Type: a service-specific resource type to namespace a group of locators. Must conform to regex pattern
[a-z][a-z0-9\-]* - Locator: a string used to uniquely locate the specific resource. Must conform to regex pattern
[a-zA-Z0-9\-\._]+
-
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares the specified object with this identifier for equality.Returns the instance component.Returns the locator component.Returns the service component.getType()Returns the type component.inthashCode()Returns the hash code value for identifier.booleanhasInstance(String instance) Compares the instance component of this identifier with the given instance.booleanhasLocator(String locator) Compares the locator component of this identifier with the given locator.booleanhasService(String service) Compares the service component of this identifier with the given service.booleanCompares the type component of this identifier with the given type.static booleanChecks if the input string is a valid resource identifier as defined in the specification.static booleanisValidInstance(String instance) Checks if the input string is a valid instance as defined in the specification.static booleanisValidLocator(String locator) Checks if the input string is a valid locator as defined in the specification.static booleanisValidService(String service) Checks if the input string is a valid service as defined in the specification.static booleanisValidType(String type) Checks if the input string is a valid type as defined in the specification.static ResourceIdentifierGenerates a new resource identifier object from each of the 4 input components.static ResourceIdentifierof(@Safe String service, @Safe String instance, @Safe String type, String firstLocatorComponent, String... locatorComponents) Generates a new resource identifier object from each of the input components.static ResourceIdentifierGenerates a new resource identifier object from the input string.toString()Returns a string representation of this ResourceIdentifier.static ResourceIdentifierSame asof(String).
-
Method Details
-
getService
Returns the service component.- Returns:
- the service component from this identifier
-
getInstance
Returns the instance component.- Returns:
- the instance component from this identifier
-
getType
Returns the type component.- Returns:
- the type component from this identifier
-
getLocator
Returns the locator component.- Returns:
- the locator component from this identifier
-
hasService
Compares the service component of this identifier with the given service. Returnstrueif and only if the service component this identifier is equal to the given service.- Parameters:
service- the service to be compared for equality with the service component of this identifier- Returns:
trueif the service component of this identifier is equal to the given service,falseotherwise
-
hasInstance
Compares the instance component of this identifier with the given instance. Returnstrueif and only if the instance component this identifier is equal to the given instance.- Parameters:
instance- the instance to be compared for equality with the instance component of this identifier- Returns:
trueif the instance component of this identifier is equal to the given instance,falseotherwise
-
hasType
Compares the type component of this identifier with the given type. Returnstrueif and only if the type component this identifier is equal to the given type.- Parameters:
type- the type to be compared for equality with the type component of this identifier- Returns:
trueif the type component of this identifier is equal to the given type,falseotherwise
-
hasLocator
Compares the locator component of this identifier with the given locator. Returnstrueif and only if the locator component this identifier is equal to the given locator.- Parameters:
locator- the locator to be compared for equality with the locator component of this identifier- Returns:
trueif the locator component of this identifier is equal to the given locator,falseotherwise
-
toString
Returns a string representation of this ResourceIdentifier. The string representation follows the format specification using the "ri" header followed by the 4 components separated by periods. -
hashCode
-
equals
Compares the specified object with this identifier for equality. Returnstrueif and only if the specified object is also a resource identifier and contain exactly the same values for all 4 components. -
isValid
Checks if the input string is a valid resource identifier as defined in the specification.- Parameters:
rid- the input string to be checked- Returns:
trueif and only if the input satisfy the resource identifier specification,falseotherwise.
-
isValidService
Checks if the input string is a valid service as defined in the specification.- Parameters:
service- the input string to be checked- Returns:
trueif and only if the input satisfy the service specification,falseotherwise.
-
isValidInstance
Checks if the input string is a valid instance as defined in the specification.- Parameters:
instance- the input string to be checked- Returns:
trueif and only if the input satisfy the instance specification,falseotherwise.
-
isValidType
Checks if the input string is a valid type as defined in the specification.- Parameters:
type- the input string to be checked- Returns:
trueif and only if the input satisfy the type specification,falseotherwise.
-
isValidLocator
Checks if the input string is a valid locator as defined in the specification.- Parameters:
locator- the input string to be checked- Returns:
trueif and only if the input satisfy the locator specification,falseotherwise.
-
valueOf
Same asof(String). Included to support JAX-RS query and path parameters -
of
Generates a new resource identifier object from the input string. This method will validate that the input is a valid resource identifier string as defined by the specification prior to creating the object.- Parameters:
rid- the input string to be converted to a resource identifier- Returns:
- a resource identifier object representing the input string
- Throws:
IllegalArgumentException- if the input string is not a valid resource identifier
-
of
public static ResourceIdentifier of(@Safe @Safe String service, @Safe @Safe String instance, @Safe @Safe String type, String locator) Generates a new resource identifier object from each of the 4 input components. Each component must satisfy the requirements as defined by the specification.- Parameters:
service- input representing the service componentinstance- input representing the instance componenttype- input representing the type componentlocator- input representing the locator component- Returns:
- a resource identifier object representing the input components
- Throws:
IllegalArgumentException- if any of the inputs do not satisfy the resource identifier specification
-
of
public static ResourceIdentifier of(@Safe @Safe String service, @Safe @Safe String instance, @Safe @Safe String type, String firstLocatorComponent, String... locatorComponents) Generates a new resource identifier object from each of the input components. The locator component is produced by joining together locatorComponent and locatorComponents with the default separator.- Parameters:
service- input representing the service componentinstance- input representing the instance componenttype- input representing the type componentfirstLocatorComponent- the first part of the locator componentlocatorComponents- the remaining locator components- Returns:
- a resource identifier object representing the input components
- Throws:
IllegalArgumentException- if any of the inputs do not satisfy the resource identifier specification
-