Package com.gengoai.specification
Class Specification
- java.lang.Object
-
- com.gengoai.specification.Specification
-
- All Implemented Interfaces:
Serializable
public final class Specification extends Object implements Serializable
A specification defines aSchema
,Protocol
,SubProtocols
,Path
, andQuery 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" orkv: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 andparameter=${parameter.defaultValue}
where${BASE_DIR}
and${parameter.defaultValue}
will be set via the Config.- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Specification.SpecificationBuilder
Builder for Specifications
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>
getAllQueryValues(String parameter)
Gets all query values associated with a given parameterList<String>
getAllSubProtocol()
Gets all subprotocol elements defined on the specificationSet<Map.Entry<String,String>>
getQueryParameters()
Gets the set of query parameter names and values set on the specification.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.String
getSubProtocol(int index)
Gets the sub protocol at the given index or null if the index is invalid.static Specification
parse(String specificationString)
Parses the specification string.static <T extends Specifiable>
Tparse(String specification, @NonNull Class<T> tClass)
Parses the specification as a the givenSpecifiable
type.Specification
setQueryParameter(@NonNull String name, @NonNull Object value)
String
toString()
-
-
-
Method Detail
-
parse
public static <T extends Specifiable> T parse(String specification, @NonNull @NonNull Class<T> tClass)
Parses the specification as a the givenSpecifiable
type.- Type Parameters:
T
- the Specifiable type parameter- Parameters:
specification
- the specification stringtClass
- 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 parameterdefaultValue
- 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)
-
-