public class TokenVariable extends Object implements Token, Matchable
Variables follow the following expression:
var = varname [ "=" vardefault ] varname = (ALPHA / DIGIT)*(ALPHA / DIGIT / "." / "_" / "-" ) vardefault = *(unreserved / pct-encoded)
Constructor and Description |
---|
TokenVariable(String exp)
Creates a new variable token.
|
TokenVariable(Variable var)
Creates a new variable token.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Two tokens are equals if and only if their string expression is equal.
|
String |
expand(Parameters variables)
Expands this object to produce a URI fragment as defined by the URI Template specifications.
|
String |
expression()
The expression corresponding to this token.
|
Variable |
getVariable()
Returns the variable wrapped by this token.
|
int |
hashCode() |
boolean |
isResolvable()
Indicates whether this token can be resolved.
|
boolean |
match(String value)
Indicates whether this token matches the specified part of a URL.
|
Pattern |
pattern()
Returns a regular expression pattern corresponding to this object.
|
boolean |
resolve(String expanded,
Map<Variable,Object> values)
Resolves the specified expanded URI part for this token.
|
protected static String |
strip(String exp)
Removes the curly brackets from the specified expression.
|
String |
toString() |
protected static List<Variable> |
toVariables(String exp)
Returns the variables for a given expression containing a list of variables.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
expression, isResolvable
public TokenVariable(String exp) throws NullPointerException, URITemplateSyntaxException
exp
- The expression to create a new.NullPointerException
- If the specified expression is null
.URITemplateSyntaxException
- If the specified expression could not be parsed as a
variable.public TokenVariable(Variable var) throws NullPointerException
var
- The variable this token corresponds to.NullPointerException
- If the specified text is null
.public Variable getVariable()
public String expand(Parameters variables)
Expandable
expand
in interface Expandable
variables
- The list of parameters and their values for substitution.public boolean match(String value)
Matchable
public Pattern pattern()
Matchable
public boolean resolve(String expanded, Map<Variable,Object> values)
Token
The resolution process requires all variables referenced in the token to be mapped to the value that is present in the expanded URI data.
public boolean isResolvable()
A resolvable token contains variables which can be resolved. By default a token is resolvable if it can be matched.
isResolvable
in interface Token
true
if variables can be resolved from the specified pattern;
false
otherwise.public String expression()
Token
expression
in interface Token
public boolean equals(Object o)
protected static final String strip(String exp)
exp
- The expression to 'strip'.protected static final List<Variable> toVariables(String exp) throws URITemplateSyntaxException
exp
- An expression containing a comma separated list of variables.URITemplateSyntaxException
- If thrown by the Variable parse method.Copyright © 2016 Allette Systems. All rights reserved.