Package com.sodius.oslc.domain.config
Class ConfigContext
- java.lang.Object
-
- com.sodius.oslc.domain.config.ConfigContext
-
public class ConfigContext extends Object
Represents a configuration context, which is the URI of a configuration (defined by OSLC Config specification), that is set as aoslc_config.context
query parameter on a resource URI.The configuration context controls which version of a resource is desired. The context may either hold a configuration URI or be empty.
This class provides methods to extract a configuration context from a resource URI and to assign such context on other URIs.
- Since:
- 3.0.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description URI
apply(URI resource)
Combine the given resource URI and the configuration URI to obtain a versioned resource URI.Link
apply(Link resource)
Combine the given resource URI and the configuration URI to obtain a versioned resource URI.static ConfigContext
empty()
Creates a context in which no configuration is desired.boolean
equals(Object obj)
Indicates whether some other object is "equal to" this configuration context.static ConfigContext
from(URI versionedResourceUri)
Extract the configuration URI specified asoslc_config.context
query parameter, if any, from the versioned resource URI.static ConfigContext
from(Link versionedResourceUri)
Extract the configuration URI specified asoslc_config.context
query parameter, if any, from the versioned resource URI.URI
get()
If a configuration is present in thisConfigurationContext
, returns the value, otherwise throwsNoSuchElementException
.int
hashCode()
Returns the hash code value of the present configuration, if any, or 0 (zero) if no configuration is present.boolean
isPresent()
Returntrue
if there is a configuration present, otherwisefalse
.static ConfigContext
of(URI configuration)
Creates a context for the specified configuration.static ConfigContext
of(Link configuration)
Creates a context for the specified configuration.static ConfigContext
ofNullable(URI configuration)
Returns aConfigContext
describing the specified configuration, if non-null, otherwise returns an emptyConfigContext
.static ConfigContext
ofNullable(Link configuration)
Returns aConfigContext
describing the specified configuration, if non-null, otherwise returns an emptyConfigContext
.URI
orElse(URI other)
Return the configuration URI if present, otherwise returnother
.String
toString()
Returns a non-empty string representation of this context suitable for debugging.
-
-
-
Method Detail
-
empty
public static ConfigContext empty()
Creates a context in which no configuration is desired.- Returns:
- the configuration context.
-
of
public static ConfigContext of(URI configuration)
Creates a context for the specified configuration.- Parameters:
configuration
- the configuration, which must be non-null.- Returns:
- the configuration context.
- Throws:
NullPointerException
- if configuration is null
-
of
public static ConfigContext of(Link configuration)
Creates a context for the specified configuration.- Parameters:
configuration
- the configuration, which must be non-null.- Returns:
- the configuration context.
- Throws:
NullPointerException
- if configuration is null
-
ofNullable
public static ConfigContext ofNullable(URI configuration)
Returns aConfigContext
describing the specified configuration, if non-null, otherwise returns an emptyConfigContext
.- Parameters:
configuration
- the possibly-null configuration- Returns:
- a
ConfigContext
with a present configuration if the specified configuration is non-null, otherwise an emptyConfigContext
-
ofNullable
public static ConfigContext ofNullable(Link configuration)
Returns aConfigContext
describing the specified configuration, if non-null, otherwise returns an emptyConfigContext
.- Parameters:
configuration
- the possibly-null configuration- Returns:
- a
ConfigContext
with a present configuration if the specified configuration is non-null, otherwise an emptyConfigContext
-
from
public static ConfigContext from(URI versionedResourceUri)
Extract the configuration URI specified asoslc_config.context
query parameter, if any, from the versioned resource URI.- Parameters:
versionedResourceUri
- the resource URI with possibly a version information.- Returns:
- a context wrapping the configuration URI specified as query parameter,
empty
if none.
-
from
public static ConfigContext from(Link versionedResourceUri)
Extract the configuration URI specified asoslc_config.context
query parameter, if any, from the versioned resource URI.- Parameters:
versionedResourceUri
- the resource URI with possibly a version information.- Returns:
- a context wrapping the configuration URI specified as query parameter,
empty
if none.
-
hashCode
public int hashCode()
Returns the hash code value of the present configuration, if any, or 0 (zero) if no configuration is present.
-
equals
public boolean equals(Object obj)
Indicates whether some other object is "equal to" this configuration context. The other object is considered equal if:- it is also a
ConfigurationContext
and; - both instances have no configuration present or;
- the present configurations are "equal to" each other.
- it is also a
-
isPresent
public boolean isPresent()
Returntrue
if there is a configuration present, otherwisefalse
.- Returns:
true
if there is a configuration present, otherwisefalse
-
get
public URI get()
If a configuration is present in thisConfigurationContext
, returns the value, otherwise throwsNoSuchElementException
.- Returns:
- the non-null configuration held by this
Optional
- Throws:
NoSuchElementException
- if there is no configuration present- See Also:
isPresent()
-
orElse
public URI orElse(URI other)
Return the configuration URI if present, otherwise returnother
.- Parameters:
other
- the value to be returned if there is no configuration URI present, may be null- Returns:
- the configuration URI, if present, otherwise
other
-
apply
public URI apply(URI resource)
Combine the given resource URI and the configuration URI to obtain a versioned resource URI. The configuration URI is set asoslc_config.context
query parameter in the returned URI.If the configuration context is
empty()
, the resource URI is returned without anyoslc_config.context
query parameter.- Parameters:
resource
- the resource URI, which may not yet have a specified configuration URI.- Returns:
- the URI of the versioned resource, which includes the configuration URI as
oslc_config.context
query parameter.
-
apply
public Link apply(Link resource)
Combine the given resource URI and the configuration URI to obtain a versioned resource URI. The configuration URI is set asoslc_config.context
query parameter in the returned URI.If the configuration context is
empty()
, the resource URI is returned without anyoslc_config.context
query parameter.- Parameters:
resource
- the resource URI, which may not yet have a specified configuration URI.- Returns:
- the URI of the versioned resource, which includes the configuration URI as
oslc_config.context
query parameter.
-
-