freemarker.template.expression
Class ListRange

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

public final class ListRange
extends java.lang.Object
implements Expression, java.io.Serializable

An expression that represents a indexModel of list values. The from and to expressions are held until evaluation time, then a FastListRange is created. A simple FastIndexedIterator is used to iterate over the values.

Since:
1.8
Version:
$Id: ListRange.java 1153 2013-04-15 10:59:37Z run2000 $
See Also:
Serialized Form

Constructor Summary
ListRange(Expression fromRange, Expression toRange)
          Constructor that takes from and to values in the form of expressions.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determines whether this object is equal to the given object.
 TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
          Retrieve the list range as a template model.
 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()
          Do we have from and to values?
 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.
 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

ListRange

public ListRange(Expression fromRange,
                 Expression toRange)
Constructor that takes from and to values in the form of expressions. The expressions are evaluated at template run time and converted into values usable by the FastListRange.

Parameters:
fromRange - the start of the range, as an expression
toRange - the end of the range, as an expression
Throws:
java.lang.NullPointerException - fromRange or toRange are null
java.lang.IllegalArgumentException - the expressions cannot be evaluated as numbers
Method Detail

getAsTemplateModel

public TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
                                 throws TemplateException
Retrieve the list range as a template model.

Specified by:
getAsTemplateModel in interface Expression
Parameters:
modelRoot - the model from which to evaluate the range of the list
Returns:
a new FastListRange representing the range list
Throws:
TemplateException - the new range could not be created

isComplete

public boolean isComplete()
Do we have from and to values?

Specified by:
isComplete in interface Expression
Returns:
true if both from and to values are specified, otherwise false

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

isConstant

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

Specified by:
isConstant in interface Expression

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

resolveExpression

public Expression resolveExpression()
                             throws TemplateException
Resolves the current expression, possibly into a different expression object. This is loosely equivalent to the serialization protocol's readResolve method. Situations where this may be used are:

Specified by:
resolveExpression in interface Expression
Throws:
TemplateException