freemarker.template
Class FastListRange

java.lang.Object
  extended by freemarker.template.FastListRange
All Implemented Interfaces:
TemplateIndexedModel, TemplateListModel2, TemplateModel, java.io.Serializable

public final class FastListRange
extends java.lang.Object
implements TemplateListModel2, TemplateIndexedModel, java.io.Serializable

A simple list model that represents a range of values. For memory conservation, we store the from and to values only. For a range that iterates backwards, set the toValue to be lower than the fromValue.

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

Constructor Summary
FastListRange(long fromValue, long toValue)
          Constructor that takes from and to values to represent the indexModel of values.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tests this object for equality with the given object.
 TemplateModel getAtIndex(long index)
          Get the value at the specified index.
 int hashCode()
          Return the hash value for this object.
 boolean isEmpty()
          Is the range empty?
 void releaseIterator(TemplateIteratorModel iterator)
          Reclaim the iterator.
 TemplateIteratorModel templateIterator()
          Get a new iterator for this template model.
 java.lang.String toString()
          Return the string value of this list range.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastListRange

public FastListRange(long fromValue,
                     long toValue)
Constructor that takes from and to values to represent the indexModel of values. Both from and to values are inclusive.

Parameters:
fromValue - the start of the range
toValue - the end of the range
Method Detail

isEmpty

public boolean isEmpty()
Is the range empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
false, because there is always at least one value in the range

getAtIndex

public TemplateModel getAtIndex(long index)
                         throws TemplateModelException
Get the value at the specified index.

Specified by:
getAtIndex in interface TemplateIndexedModel
Parameters:
index - the index of the item we're after
Returns:
a new FastNumber containing the value at the given index
Throws:
TemplateModelException - the index was out of bounds

templateIterator

public TemplateIteratorModel templateIterator()
Get a new iterator for this template model.

Specified by:
templateIterator in interface TemplateListModel2
Returns:
an iterator to use over the values in this range

releaseIterator

public void releaseIterator(TemplateIteratorModel iterator)
Reclaim the iterator. In this case we don't do anything, since we don't pool iterators in this implementation.

Specified by:
releaseIterator in interface TemplateListModel2
Parameters:
iterator - the iterator to be reclaimed

toString

public java.lang.String toString()

Return the string value of this list range. The values typically look like this:

 [ {fromValue} .. {toValue} ]
 

Overrides:
toString in class java.lang.Object
Returns:
a String representing this range

equals

public boolean equals(java.lang.Object o)
Tests this object for equality with 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()
Return the hash value for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code corresponding to the object's value