Package org.forgerock.opendj.config
Class ValueOrExpression<T>
- java.lang.Object
-
- org.forgerock.opendj.config.ValueOrExpression<T>
-
- Type Parameters:
T
- type of value that can be held
public final class ValueOrExpression<T> extends Object
Wraps either a value of a given type or an expression string containing at least one token.Token(s) in an expression must use the pattern:
&{some.token}
Example: aValueOrExpression<Integer>
could contain either the integer value 4444 or the expression "&{port}".
-
-
Field Summary
Fields Modifier and Type Field Description static String
TOKEN_END
The marker of end for a commons-config token.static String
TOKEN_START
The marker of start for a commons-config token.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
containsExpression(String expression)
Validates the expression, checking it has at least one token.boolean
equals(Object obj)
String
getExpression()
Returns the expression if any.T
getValue()
Returns the value if any.T
getValueOrThrowIfExpression()
Returns the value or throws if no value is available.int
hashCode()
boolean
isExpression()
Indicates if this wraps an expression.static <T> ValueOrExpression<T>
newExpression(String expression)
Creates an expression.static ValueOrExpression<String>
newFileExpression(String filePath)
Creates an expression corresponding to a file path.static <T> ValueOrExpression<T>
newValue(T value)
Creates a value.static <T> ValueOrExpression<T>
newValueOrNull(T value)
Creates a new ValueOrExpression that wraps the provided value if the value is notnull
.String
toString()
-
-
-
Field Detail
-
TOKEN_START
public static final String TOKEN_START
The marker of start for a commons-config token.- See Also:
- Constant Field Values
-
TOKEN_END
public static final String TOKEN_END
The marker of end for a commons-config token.- See Also:
- Constant Field Values
-
-
Method Detail
-
newExpression
public static <T> ValueOrExpression<T> newExpression(String expression)
Creates an expression.- Type Parameters:
T
- type of value- Parameters:
expression
- The expression- Returns:
- the wrapper for an expression
- Throws:
NullPointerException
- if provided expression is null
-
newFileExpression
public static ValueOrExpression<String> newFileExpression(String filePath)
Creates an expression corresponding to a file path.- Parameters:
filePath
- The file path to use in the expression- Returns:
- the wrapper for an expression
-
newValue
public static <T> ValueOrExpression<T> newValue(T value)
Creates a value.- Type Parameters:
T
- type of value- Parameters:
value
- The actual value- Returns:
- the wrapper for a value
- Throws:
NullPointerException
- if provided value is null
-
newValueOrNull
public static <T> ValueOrExpression<T> newValueOrNull(T value)
Creates a new ValueOrExpression that wraps the provided value if the value is notnull
.- Type Parameters:
T
- type of value- Parameters:
value
- The value which may benull
- Returns:
- the wrapper for a value, or
null
if anull
value is provided
-
containsExpression
public static boolean containsExpression(String expression)
Validates the expression, checking it has at least one token.- Parameters:
expression
- The expression to validate- Returns:
true
if the expression is valid,false
otherwise
-
getExpression
public String getExpression()
Returns the expression if any.- Returns:
- the wrapped expression or
null
if there is no expression
-
getValue
public T getValue()
Returns the value if any.- Returns:
- the wrapped value or
null
if there is no value
-
getValueOrThrowIfExpression
public T getValueOrThrowIfExpression() throws ExpressionException
Returns the value or throws if no value is available.- Returns:
- the wrapped value, which is never
null
- Throws:
ExpressionException
- if this expression does not contain a value
-
isExpression
public boolean isExpression()
Indicates if this wraps an expression.- Returns:
true
if this is an expression, orfalse
if it is a value
-
-