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.contextquery 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 URIapply(URI resource)Combine the given resource URI and the configuration URI to obtain a versioned resource URI.Linkapply(Link resource)Combine the given resource URI and the configuration URI to obtain a versioned resource URI.static ConfigContextempty()Creates a context in which no configuration is desired.booleanequals(Object obj)Indicates whether some other object is "equal to" this configuration context.static ConfigContextfrom(URI versionedResourceUri)Extract the configuration URI specified asoslc_config.contextquery parameter, if any, from the versioned resource URI.static ConfigContextfrom(Link versionedResourceUri)Extract the configuration URI specified asoslc_config.contextquery parameter, if any, from the versioned resource URI.URIget()If a configuration is present in thisConfigurationContext, returns the value, otherwise throwsNoSuchElementException.inthashCode()Returns the hash code value of the present configuration, if any, or 0 (zero) if no configuration is present.booleanisPresent()Returntrueif there is a configuration present, otherwisefalse.static ConfigContextof(URI configuration)Creates a context for the specified configuration.static ConfigContextof(Link configuration)Creates a context for the specified configuration.static ConfigContextofNullable(URI configuration)Returns aConfigContextdescribing the specified configuration, if non-null, otherwise returns an emptyConfigContext.static ConfigContextofNullable(Link configuration)Returns aConfigContextdescribing the specified configuration, if non-null, otherwise returns an emptyConfigContext.URIorElse(URI other)Return the configuration URI if present, otherwise returnother.StringtoString()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 aConfigContextdescribing the specified configuration, if non-null, otherwise returns an emptyConfigContext.- Parameters:
configuration- the possibly-null configuration- Returns:
- a
ConfigContextwith a present configuration if the specified configuration is non-null, otherwise an emptyConfigContext
-
ofNullable
public static ConfigContext ofNullable(Link configuration)
Returns aConfigContextdescribing the specified configuration, if non-null, otherwise returns an emptyConfigContext.- Parameters:
configuration- the possibly-null configuration- Returns:
- a
ConfigContextwith 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.contextquery 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,
emptyif none.
-
from
public static ConfigContext from(Link versionedResourceUri)
Extract the configuration URI specified asoslc_config.contextquery 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,
emptyif 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
ConfigurationContextand; - both instances have no configuration present or;
- the present configurations are "equal to" each other.
- it is also a
-
isPresent
public boolean isPresent()
Returntrueif there is a configuration present, otherwisefalse.- Returns:
trueif 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.contextquery parameter in the returned URI.If the configuration context is
empty(), the resource URI is returned without anyoslc_config.contextquery 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.contextquery 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.contextquery parameter in the returned URI.If the configuration context is
empty(), the resource URI is returned without anyoslc_config.contextquery 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.contextquery parameter.
-
-