Package com.palantir.ri
Class ResourceIdentifier
- java.lang.Object
-
- com.palantir.ri.ResourceIdentifier
-
public final class ResourceIdentifier extends java.lang.ObjectDefines 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\-\._]+
- Service: a string that represents the service (or application) that namespaces the rest of the identifier.
Must conform with regex pattern
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Compares the specified object with this identifier for equality.java.lang.StringgetInstance()Returns the instance component.java.lang.StringgetLocator()Returns the locator component.java.lang.StringgetService()Returns the service component.java.lang.StringgetType()Returns the type component.inthashCode()Returns the hash code value for identifier.static booleanisValid(java.lang.String rid)Checks if the input string is a valid resource identifier as defined in the specification.static booleanisValidInstance(java.lang.String instance)Checks if the input string is a valid instance as defined in the specification.static booleanisValidLocator(java.lang.String locator)Checks if the input string is a valid locator as defined in the specification.static booleanisValidService(java.lang.String service)Checks if the input string is a valid service as defined in the specification.static booleanisValidType(java.lang.String type)Checks if the input string is a valid type as defined in the specification.static ResourceIdentifierof(java.lang.String rid)Generates a new resource identifier object from the input string.static ResourceIdentifierof(java.lang.String service, java.lang.String instance, java.lang.String type, java.lang.String locator)Generates a new resource identifier object from each of the 4 input components.static ResourceIdentifierof(java.lang.String service, java.lang.String instance, java.lang.String type, java.lang.String firstLocatorComponent, java.lang.String... locatorComponents)Generates a new resource identifier object from each of the input components.java.lang.StringtoString()Returns a string representation of this ResourceIdentifier.static ResourceIdentifiervalueOf(java.lang.String rid)Same asof(String).
-
-
-
Method Detail
-
getService
public java.lang.String getService()
Returns the service component.- Returns:
- the service component from this identifier
-
getInstance
public java.lang.String getInstance()
Returns the instance component.- Returns:
- the instance component from this identifier
-
getType
public java.lang.String getType()
Returns the type component.- Returns:
- the type component from this identifier
-
getLocator
public java.lang.String getLocator()
Returns the locator component.- Returns:
- the locator component from this identifier
-
toString
public java.lang.String 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.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of this identifier
-
hashCode
public int hashCode()
Returns the hash code value for identifier. The hash code is calculated using the JavaObjects.hash(Object...)method over each of the 4 components.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value for this identifier
-
equals
public boolean equals(java.lang.Object obj)
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.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to be compared for equality with this identifier- Returns:
trueif the specified object is equal to this identifier,falseotherwise
-
isValid
public static boolean isValid(java.lang.String rid)
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
public static boolean isValidService(java.lang.String service)
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
public static boolean isValidInstance(java.lang.String instance)
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
public static boolean isValidType(java.lang.String type)
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
public static boolean isValidLocator(java.lang.String locator)
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
public static ResourceIdentifier valueOf(java.lang.String rid)
Same asof(String). Included to support JAX-RS query and path parameters
-
of
public static ResourceIdentifier of(java.lang.String rid)
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:
java.lang.IllegalArgumentException- if the input string is not a valid resource identifier
-
of
public static ResourceIdentifier of(java.lang.String service, java.lang.String instance, java.lang.String type, java.lang.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:
java.lang.IllegalArgumentException- if any of the inputs do not satisfy the resource identifier specification
-
of
public static ResourceIdentifier of(java.lang.String service, java.lang.String instance, java.lang.String type, java.lang.String firstLocatorComponent, java.lang.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:
java.lang.IllegalArgumentException- if any of the inputs do not satisfy the resource identifier specification
-
-