Class Specification

  • All Implemented Interfaces:
    Serializable

    public final class Specification
    extends Object
    implements Serializable
    A specification defines a Schema, Protocol, SubProtocols, Path, and Query Parameters that define a resource, connection, etc. The specification form is as follows: SCHEMA:(PROTOCOL(:SUB-PROTOCOL)*)?(::PATH)?(;query=value) and example is: kv:mem:people defining an in-memory key-value store with the namespace "people" or kv:disk:people::~/people.db;readOnly=true defining a disk-based key-value store with the namespace "people" stored at ~/people.db and being accessed as read only. Note that the Path and Query Arguments can will be resolved against the current Config allowing for dynamic paths like ${BASE_DIR}/myFile for paths and parameter=${parameter.defaultValue} where ${BASE_DIR} and ${parameter.defaultValue} will be set via the Config.
    Author:
    David B. Bracewell
    See Also:
    Serialized Form
    • Method Detail

      • parse

        public static <T extends Specifiable> T parse​(String specification,
                                                      @NonNull
                                                      @NonNull Class<T> tClass)
        Parses the specification as a the given Specifiable type.
        Type Parameters:
        T - the Specifiable type parameter
        Parameters:
        specification - the specification string
        tClass - the Specifiable class
        Returns:
        the Specifiable
      • parse

        public static Specification parse​(String specificationString)
        Parses the specification string.
        Parameters:
        specificationString - the specification string
        Returns:
        the specification
      • getAllQueryValues

        public List<String> getAllQueryValues​(String parameter)
        Gets all query values associated with a given parameter
        Parameters:
        parameter - the parameter
        Returns:
        the query parameter values
      • getAllSubProtocol

        public List<String> getAllSubProtocol()
        Gets all subprotocol elements defined on the specification
        Returns:
        the list of sub-protocol elements
      • getQueryParameters

        public Set<Map.Entry<String,​String>> getQueryParameters()
        Gets the set of query parameter names and values set on the specification.
        Returns:
        the set of query parameter names and values set on the specification.
      • getQueryValue

        public String getQueryValue​(String parameter,
                                    String defaultValue)
        Gets the first query parameter value associated with a parameter or the default value if the query parameter is not defined.
        Parameters:
        parameter - the parameter
        defaultValue - the default value
        Returns:
        the query parameter value
      • getSubProtocol

        public String getSubProtocol​(int index)
        Gets the sub protocol at the given index or null if the index is invalid.
        Parameters:
        index - the index of the sub-protocol element
        Returns:
        the sub protocol element or null if the index is invalid
      • setQueryParameter

        public Specification setQueryParameter​(@NonNull
                                               @NonNull String name,
                                               @NonNull
                                               @NonNull Object value)