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 expressionThis 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 classExpression.BuilderBuilder 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.Buildercontinuation(VarSpec... varSpec)Creates a newExpression.Builderto create an expression using form-style query continuation expansion according to section 3.2.9.booleanequals(Object obj)static Expression.Builderfragment(VarSpec... varSpec)Creates a newExpression.Builderto create an expression with a fragment operator according to section 3.2.4.PatterngetMatchPattern()Returns a string that contains a regular expression that matches the URI template expression.OperatorgetOperator()Get theOperatorvalue for this expression.StringgetReplacementPattern()Get the replacementToken.StringgetValue()Returns the value of this componentList<VarSpec>getVarSpecs()Get the varSpecs.inthashCode()static Expression.Builderlabel(VarSpec... varSpec)Creates a newExpression.Builderto create an expression using label expansion according to section 3.2.5.static Expression.Buildermatrix(VarSpec... varSpec)Creates a newExpression.Builderto create an expression using path-style parameter (a.k.a.static Expression.Builderpath(VarSpec... varSpec)Creates a newExpression.Builderto create an expression using path expansion according to section 3.2.6.static Expression.Builderquery(VarSpec... varSpec)Creates a newExpression.Builderto create an expression using form-style query string expansion according to section 3.2.8.static Expression.Builderreserved(VarSpec... varSpec)Creates a newExpression.Builderto create an expression that will use reserved expansion according to section 3.2.3.static Expression.Buildersimple(VarSpec... varSpec)Creates a newExpression.Builderto create a simple expression according to section 3.2.2.StringtoString()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.Builderto 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.Builderto 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.Builderto 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.Builderto 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.Builderto 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.Builderto 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.Builderto 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.Builderto 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:
getMatchPatternin classUriTemplateComponent- Returns:
- the match pattern
-
getReplacementPattern
public String getReplacementPattern()
Get the replacementToken.- Returns:
- the replacementToken.
-
getOperator
public Operator getOperator()
Get theOperatorvalue for this expression.- Returns:
- the operator value.
-
toString
public String toString()
Returns the string representation of the expression.- Overrides:
toStringin classObject- See Also:
Object.toString()
-
getValue
public String getValue()
Returns the value of this component- Specified by:
getValuein classUriTemplateComponent- Returns:
- the string value of this component.
-
-