public class Variable extends Object
foo - An untyped variable named 'foo' bar - An untyped variable named 'bar' ping:foo - A variable named 'foo' typed 'ping' ping:foo=1 - A variable named 'foo' typed 'ping' which default value is '1' foo=pong - An untyped variable named 'foo' which default value is 'pong'Variables only appear in the context of the a template expansion. Expansion rule (4.4.1):
"In a variable ('var') expansion, if the variable is defined then substitute the value of
the variable, otherwise substitute the default value.
If no default value is given then substitute with the empty string."
Syntax for variables:
var = [ vartype ":" ] varname [ "=" vardefault ]
vars = var [ *("," var) ]
vartype = (ALPHA / DIGIT)* (ALPHA / DIGIT / "." / "_" / "-" )
varname = (ALPHA / DIGIT)* (ALPHA / DIGIT / "." / "_" / "-" )
vardefault = *(unreserved / pct-encoded)
| Modifier and Type | Class and Description |
|---|---|
static class |
Variable.Form
Indicate that the variable's value should be processed as a list ("@") or an associative array ("%").
|
static class |
Variable.Modifier
Indicate that the variable's value should be processed as a list ("@") or an associative array ("%").
|
static class |
Variable.Reserved
Used for reserved variable names.
|
| Modifier and Type | Field and Description |
|---|---|
protected static Pattern |
VALID_VALUE
The pattern for a valid normalised variable value: any unreserved character or an escape
sequence.
|
| Constructor and Description |
|---|
Variable(String name)
Creates a new untyped variable.
|
Variable(String name,
String def)
Creates a new untyped variable.
|
Variable(String name,
String def,
VariableType type)
Creates a new variable.
|
Variable(String name,
String def,
VariableType type,
Variable.Form form)
Creates a new variable.
|
Variable(Variable.Reserved reserved)
Creates a new untyped reserved variable.
|
| Modifier and Type | Method and Description |
|---|---|
String |
defaultValue()
Returns the default value for this variable.
|
boolean |
equals(Object o) |
Variable.Form |
form()
Returns the form of this variable.
|
int |
hashCode() |
static boolean |
isValidName(String name)
Indicates whether the variable has a valid name according to the specifications.
|
static boolean |
isValidValue(String value)
Indicates whether the variable has a valid value according to the specifications.
|
String |
name()
Returns the name of this variable.
|
protected String |
namePatternString()
Returns the name of this variable as a regular expression pattern string for use in a regular
expression.
|
static Variable |
parse(String exp)
Parses the given expression and returns the corresponding instance.
|
String |
toString() |
VariableType |
type()
Returns the implementation type of this variable.
|
String |
value(Parameters parameters)
Returns the expanded value of this variable.
|
String[] |
values(Parameters parameters)
Returns the expanded value of this variable.
|
protected static final Pattern VALID_VALUE
public Variable(Variable.Reserved reserved) throws NullPointerException, IllegalArgumentException
reserved - The name of the variable.NullPointerException - If the specified name is null.IllegalArgumentException - If the specified name is an empty string.public Variable(String name) throws NullPointerException, IllegalArgumentException
name - The name of the variable.NullPointerException - If the specified name is null.IllegalArgumentException - If the specified name is an empty string.public Variable(String name, String def) throws NullPointerException, IllegalArgumentException
name - The name of the variable.def - The default value for the variable.NullPointerException - If the specified name is null.IllegalArgumentException - If the specified name is an empty string.public Variable(String name, String def, VariableType type) throws NullPointerException, IllegalArgumentException
name - The name of the variable.def - The default value for the variable.type - The type of the variable.NullPointerException - If the specified name is null.IllegalArgumentException - If the specified name is an empty string.public Variable(String name, String def, VariableType type, Variable.Form form) throws NullPointerException, IllegalArgumentException
name - The name of the variable.def - The default value for the variable.type - The type of the variable.NullPointerException - If the specified name is null.IllegalArgumentException - If the specified name is an empty string.public Variable.Form form()
null.public String name()
null.public String defaultValue()
null.public VariableType type()
null if the variable is untyped.public String value(Parameters parameters)
parameters - The parameters.public String[] values(Parameters parameters)
parameters - The parameters.public static Variable parse(String exp) throws URITemplateSyntaxException
exp - The expression to parse.URITemplateSyntaxException - If the expression cannot be parsedpublic static boolean isValidName(String name)
name - The name of the variable.true if the name is valid; false otherwise.public static boolean isValidValue(String value)
value - The value of the variable.true if the name is not valid; false otherwise.protected String namePatternString()
Copyright © 2021. All rights reserved.