Package com.damnhandy.uri.template
Class Expression
- java.lang.Object
-
- com.damnhandy.uri.template.UriTemplateComponent
-
- com.damnhandy.uri.template.Expression
-
- All Implemented Interfaces:
Serializable
public class Expression extends UriTemplateComponent
An Expression represents the text between '{' and '}', including the enclosing braces, as defined in Section 2 of RFC6570.
http://www.example.com/foo{?query,number} \___________/ ^ | | The expression
This class models this representation and adds helper functions for replacement and reverse matching.
- Since:
- 2.0
- Version:
- $Revision: 1.1 $
- Author:
- Ryan J. McDonough
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Expression.Builder
Builder class for creating anExpression
.
-
Constructor Summary
Constructors Constructor Description Expression(Operator op, List<VarSpec> varSpecs)
Create a new ExpressionExpression(String rawExpression, int startPosition)
Create a new Expression.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Expression.Builder
continuation(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using form-style query continuation expansion according to section 3.2.9.boolean
equals(Object obj)
static Expression.Builder
fragment(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression with a fragment operator according to section 3.2.4.Pattern
getMatchPattern()
Returns a string that contains a regular expression that matches the URI template expression.Operator
getOperator()
Get theOperator
value for this expression.String
getReplacementPattern()
Get the replacementToken.String
getValue()
Returns the value of this componentList<VarSpec>
getVarSpecs()
Get the varSpecs.int
hashCode()
static Expression.Builder
label(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using label expansion according to section 3.2.5.static Expression.Builder
matrix(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using path-style parameter (a.k.a.static Expression.Builder
path(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using path expansion according to section 3.2.6.static Expression.Builder
query(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using form-style query string expansion according to section 3.2.8.static Expression.Builder
reserved(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression that will use reserved expansion according to section 3.2.3.static Expression.Builder
simple(VarSpec... varSpec)
Creates a newExpression.Builder
to create a simple expression according to section 3.2.2.String
toString()
Returns the string representation of the expression.-
Methods inherited from class com.damnhandy.uri.template.UriTemplateComponent
getEndPosition, getStartPosition
-
-
-
-
Constructor Detail
-
Expression
public Expression(String rawExpression, int startPosition) throws MalformedUriTemplateException
Create a new Expression.- Parameters:
rawExpression
-startPosition
-- Throws:
MalformedUriTemplateException
-
Expression
public Expression(Operator op, List<VarSpec> varSpecs)
Create a new Expression- Parameters:
op
-varSpecs
-- Throws:
MalformedUriTemplateException
-
-
Method Detail
-
simple
public static Expression.Builder simple(VarSpec... varSpec)
Creates a newExpression.Builder
to create a simple expression according to section 3.2.2. Calling:String exp = Expression.simple(var("var")).build().toString();
Will return the following expression:
{var}
- Returns:
-
reserved
public static Expression.Builder reserved(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression that will use reserved expansion according to section 3.2.3. Calling:String exp = Expression.reserved().var("var").build().toString();
Will return the following expression:
{+var}
- Returns:
-
fragment
public static Expression.Builder fragment(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression with a fragment operator according to section 3.2.4. Calling:String exp = Expression.fragment().var("var").build().toString();
Will return the following expression:
{#var}
- Returns:
-
label
public static Expression.Builder label(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using label expansion according to section 3.2.5. Calling:String exp = Expression.label(var("var")).build().toString();
Will return the following expression:
{.var}
- Returns:
-
path
public static Expression.Builder path(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using path expansion according to section 3.2.6. Calling:String exp = Expression.path().var("var").build().toString();
Will return the following expression:
{/var}
- Returns:
-
matrix
public static Expression.Builder matrix(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using path-style parameter (a.k.a. matrix parameter) expansion according to section 3.2.7. Calling:String exp = Expression.matrix().var("var").build().toString();
Will return the following expression:
{;var}
- Returns:
- the builder
-
query
public static Expression.Builder query(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using form-style query string expansion according to section 3.2.8. Calling:String exp = Expression.query().var("var").build().toString();
Will return the following expression:
{?var}
- Returns:
-
continuation
public static Expression.Builder continuation(VarSpec... varSpec)
Creates a newExpression.Builder
to create an expression using form-style query continuation expansion according to section 3.2.9. Calling:String exp = Expression.continuation().var("var").build().toString();
Will return the following expression:
{&var}
- Returns:
-
getMatchPattern
public Pattern getMatchPattern()
Returns a string that contains a regular expression that matches the URI template expression.- Specified by:
getMatchPattern
in classUriTemplateComponent
- Returns:
- the match pattern
-
getReplacementPattern
public String getReplacementPattern()
Get the replacementToken.- Returns:
- the replacementToken.
-
getOperator
public Operator getOperator()
Get theOperator
value for this expression.- Returns:
- the operator value.
-
toString
public String toString()
Returns the string representation of the expression.- Overrides:
toString
in classObject
- See Also:
Object.toString()
-
getValue
public String getValue()
Returns the value of this component- Specified by:
getValue
in classUriTemplateComponent
- Returns:
- the string value of this component.
-
-