Class 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: a ValueOrExpression<Integer> could contain either the integer value 4444 or the expression "&{port}".
    • 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 not null.
        Type Parameters:
        T - type of value
        Parameters:
        value - The value which may be null
        Returns:
        the wrapper for a value, or null if a null 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, or false if it is a value
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object