Class 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 a oslc_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 as oslc_config.context query parameter, if any, from the versioned resource URI.
      static ConfigContext from​(Link versionedResourceUri)
      Extract the configuration URI specified as oslc_config.context query parameter, if any, from the versioned resource URI.
      URI get()
      If a configuration is present in this ConfigurationContext, returns the value, otherwise throws NoSuchElementException.
      int hashCode()
      Returns the hash code value of the present configuration, if any, or 0 (zero) if no configuration is present.
      boolean isPresent()
      Return true if there is a configuration present, otherwise false.
      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 a ConfigContext describing the specified configuration, if non-null, otherwise returns an empty ConfigContext.
      static ConfigContext ofNullable​(Link configuration)
      Returns a ConfigContext describing the specified configuration, if non-null, otherwise returns an empty ConfigContext.
      URI orElse​(URI other)
      Return the configuration URI if present, otherwise return other.
      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 a ConfigContext describing the specified configuration, if non-null, otherwise returns an empty ConfigContext.
        Parameters:
        configuration - the possibly-null configuration
        Returns:
        a ConfigContext with a present configuration if the specified configuration is non-null, otherwise an empty ConfigContext
      • ofNullable

        public static ConfigContext ofNullable​(Link configuration)
        Returns a ConfigContext describing the specified configuration, if non-null, otherwise returns an empty ConfigContext.
        Parameters:
        configuration - the possibly-null configuration
        Returns:
        a ConfigContext with a present configuration if the specified configuration is non-null, otherwise an empty ConfigContext
      • from

        public static ConfigContext from​(URI versionedResourceUri)
        Extract the configuration URI specified as oslc_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 as oslc_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.
        Overrides:
        hashCode in class Object
        Returns:
        hash code value of the present configuration or 0 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.
        Overrides:
        equals in class Object
        Parameters:
        obj - an object to be tested for equality
        Returns:
        true if the other object is "equal to" this object otherwise false
      • isPresent

        public boolean isPresent()
        Return true if there is a configuration present, otherwise false.
        Returns:
        true if there is a configuration present, otherwise false
      • get

        public URI get()
        If a configuration is present in this ConfigurationContext, returns the value, otherwise throws NoSuchElementException.
        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 return other.
        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 as oslc_config.context query parameter in the returned URI.

        If the configuration context is empty(), the resource URI is returned without any oslc_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 as oslc_config.context query parameter in the returned URI.

        If the configuration context is empty(), the resource URI is returned without any oslc_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.
      • toString

        public String toString()
        Returns a non-empty string representation of this context suitable for debugging.
        Overrides:
        toString in class Object
        Returns:
        the string representation of this instance