freemarker.template.expression
Class Ternary

java.lang.Object
  extended by freemarker.template.expression.Ternary
All Implemented Interfaces:
Expression, Operator, java.io.Serializable

public final class Ternary
extends java.lang.Object
implements Operator, java.io.Serializable

An expression that represents a conditional ternary operator. Most useful in conjunction with the lambda operator.

Since:
1.9
Version:
$Id: Ternary.java 1153 2013-04-15 10:59:37Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Constructor Summary
Ternary()
          Create a new Ternary expression.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determines whether this object is equal to the given object.
 TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
          Performs ternary evaluation.
 ExpressionBuilder.Precedence getPrecedence()
          Return the precedence for this operator to the caller.
 java.util.Set<ExpressionUtils.ExpressionType> getType()
          Determine the type of result that can be calculated by this expression.
 int hashCode()
          Returns the hash code for this operator.
 boolean isComplete()
          Is the Expression complete?
 boolean isConstant()
          Determine whether result calculated by this expression is a constant value.
 Expression resolveExpression()
          Resolves the current expression, possibly into a different expression object.
 void setElseExpression(Expression expr)
          Sets the expression to be evaluates if the test evaluates to false.
 void setIfExpression(Expression expr)
          Sets the expression to be evaluated if the test evaluates to true.
 void setTest(Expression expr)
          Sets the test expression for this ternary operator.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Ternary

public Ternary()
Create a new Ternary expression.

Method Detail

setTest

public void setTest(Expression expr)
Sets the test expression for this ternary operator.

Parameters:
expr - the expression to be tested to determine which result should be evaluated

setIfExpression

public void setIfExpression(Expression expr)
Sets the expression to be evaluated if the test evaluates to true.

Parameters:
expr - the expression to be evaluated if the test expression evaluates true

setElseExpression

public void setElseExpression(Expression expr)
Sets the expression to be evaluates if the test evaluates to false.

Parameters:
expr - the expressoin to be evaluated if the test expression evaluates false

getAsTemplateModel

public TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
                                 throws TemplateException
Performs ternary evaluation.

Specified by:
getAsTemplateModel in interface Expression
Parameters:
modelRoot - the template model that will be evaluated by the expression
Returns:
the result of the ternary evaluation
Throws:
TemplateException - the expression could not be evaluated for some reason

getType

public java.util.Set<ExpressionUtils.ExpressionType> getType()
Determine the type of result that can be calculated by this expression. This is in the form of an integer constant ored together from values in the ExpressionUtils class.

Specified by:
getType in interface Expression

isComplete

public boolean isComplete()
Is the Expression complete?

Specified by:
isComplete in interface Expression
Returns:
true if this Expression is complete, otherwise false

isConstant

public boolean isConstant()
Determine whether result calculated by this expression is a constant value.

Specified by:
isConstant in interface Expression

getPrecedence

public ExpressionBuilder.Precedence getPrecedence()
Return the precedence for this operator to the caller. Used for associating operators according to precedence.

Specified by:
getPrecedence in interface Operator
Returns:
an integer indicating the precedence of this operator

resolveExpression

public Expression resolveExpression()
                             throws TemplateException
Resolves the current expression, possibly into a different expression object. Situations where this may be used are:

Specified by:
resolveExpression in interface Expression
Throws:
TemplateException

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this expression

equals

public boolean equals(java.lang.Object o)
Determines whether this object is equal to the given object.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to be compared with
Returns:
true if the objects are equal, otherwise false

hashCode

public int hashCode()
Returns the hash code for this operator.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this object