Class ResourceIdentifier
Each resource identifier consists of an arbitrary number of path segments. The first segment always contains the name of the endpoint that the resource belongs to.
The basic scheme is <endpoint>/[tenant]/[resource-id]
. The resource-id
usually represents a device identifier.
Examples:
- telemetry/DEFAULT_TENANT/4711
- telemetry
- telemetry/
- telemetry//
- telemetry//4711
- telemetry/DEFAULT_TENANT
- telemetry/DEFAULT_TENANT/
-
Method Summary
Modifier and TypeMethodDescriptionelementAt
(int index) Gets the element at a given index of the resource path.boolean
static ResourceIdentifier
Creates a resource identifier for an endpoint, a tenantId and a resourceId.static ResourceIdentifier
from
(ResourceIdentifier resourceIdentifier, String tenantId, String resourceId) Creates a resource identifier for an endpoint based on another resource identifier.static ResourceIdentifier
Creates a resource identifier from path segments.static ResourceIdentifier
fromString
(String resource) Creates a resource identifier from its string representation.Gets a string representation of this resource identifier's endpoint and tenantId.Gets the endpoint part of this identifier.Gets a string representation of the resource identifiers' parts without the base path.Gets the resourceId part of this identifier.String[]
Gets a copy of the full resource path of this identifier, including extended elements.Gets the tenant part of this identifier.boolean
Checks if this resource identifier contains the event endpoint.int
hashCode()
boolean
Checks if this resource identifier contains the telemetry endpoint.static boolean
Checks whether the given string is a valid resource identifier string representation.int
length()
Gets the number of elements in the resource path.String[]
toPath()
Gets this resource identifier as path segments.toString()
Gets a string representation of this resource identifier.
-
Method Details
-
isValid
Checks whether the given string is a valid resource identifier string representation.- Parameters:
resource
- the resource string to parse.- Returns:
true
if the given string is a valid resource identifier string.
-
fromString
Creates a resource identifier from its string representation.The given string is split up into segments using a forward slash as the separator. The first segment is used as the endpoint, the second segment is used as the tenant ID and the third segment (if present) is used as the resourceId part.
- Parameters:
resource
- the resource string to parse.- Returns:
- the resource identifier.
- Throws:
NullPointerException
- if the given string isnull
.IllegalArgumentException
- if the given string is empty or contains an empty first segment.
-
from
Creates a resource identifier for an endpoint, a tenantId and a resourceId.- Parameters:
endpoint
- the endpoint of the resource.tenantId
- the tenant identifier (may benull
).resourceId
- the resourceId part (may benull
).- Returns:
- the resource identifier.
- Throws:
NullPointerException
- if endpoint isnull
.IllegalArgumentException
- if endpoint is empty.
-
from
public static ResourceIdentifier from(ResourceIdentifier resourceIdentifier, String tenantId, String resourceId) Creates a resource identifier for an endpoint based on another resource identifier.It uses all data from the original resource identifier but sets the new tenantId and resourceId.
- Parameters:
resourceIdentifier
- original resource identifier to copy values from.tenantId
- the tenant identifier (may benull
).resourceId
- the resourceId part (may benull
).- Returns:
- the resource identifier.
- Throws:
NullPointerException
- if resourceIdentifier isnull
.
-
fromPath
Creates a resource identifier from path segments.- Parameters:
path
- the segments of the resource path.- Returns:
- the resource identifier.
- Throws:
NullPointerException
- if path isnull
.IllegalArgumentException
- if the path contains no segments or starts with an empty segment.
-
toPath
Gets this resource identifier as path segments.- Returns:
- the segments.
-
elementAt
Gets the element at a given index of the resource path.- Parameters:
index
- The index (starting from zero).- Returns:
- The element at the index.
- Throws:
ArrayIndexOutOfBoundsException
- if the resource path's length is shorter than the index.
-
length
public int length()Gets the number of elements in the resource path.- Returns:
- The resource path length.
-
getEndpoint
Gets the endpoint part of this identifier.- Returns:
- the endpoint (not
null
or empty).
-
getTenantId
Gets the tenant part of this identifier.- Returns:
- the tenantId or
null
if not set.
-
getResourceId
Gets the resourceId part of this identifier.E.g. for a resource telemetry/DEFAULT_TENANT/4711, the return value will be 4711.
- Returns:
- the resourceId or
null
if not set.
-
getResourcePath
Gets a copy of the full resource path of this identifier, including extended elements.- Returns:
- The full resource path.
-
toString
Gets a string representation of this resource identifier.The string representation consists of all path segments separated by a forward slash ("/").
-
getBasePath
Gets a string representation of this resource identifier's endpoint and tenantId.E.g. for a resource telemetry/DEFAULT_TENANT/4711, the return value will be telemetry/DEFAULT_TENANT.
- Returns:
- A string consisting of the properties separated by a forward slash.
-
getPathWithoutBase
Gets a string representation of the resource identifiers' parts without the base path.E.g. for a resource command_response/myTenant/deviceId/some/path, the return value will be deviceId/some/path.
If this resource identifier doesn't contain any additional path segments after the base path, an empty string is returned.
- Returns:
- A string with all parts after the base bath.
- See Also:
-
hasEventEndpoint
public boolean hasEventEndpoint()Checks if this resource identifier contains the event endpoint. -
hasTelemetryEndpoint
public boolean hasTelemetryEndpoint()Checks if this resource identifier contains the telemetry endpoint.- Returns:
true
if this resource's endpoint is either "telemetry" or "t".
-
equals
-
hashCode
public int hashCode()
-