freemarker.template
Class FastBoolean

java.lang.Object
  |
  +--freemarker.template.FastBoolean
All Implemented Interfaces:
java.io.Serializable, TemplateModel, TemplateNumberModel, TemplateScalarModel

public final class FastBoolean
extends java.lang.Object
implements TemplateScalarModel, TemplateNumberModel, java.io.Serializable

An unsynchronised, immutable variation of the SimpleScalar class to handle boolean values. This avoids the need for synchronization, since we no longer have any situations where the underlying value changes. This means that FastBoolean should be significantly faster in some cases.

As of 1.8, this class also implements the TemplateNumberModel interface, in order to simplify casting of boolean literals to numbers.

Note:
Unlike the other Fast classes, FastBoolean uses a factory method to create instances. This can dramatically reduce the amount of garbage generated by reusing the same objects when possible.

Since:
1.7.5
Version:
$Id: FastBoolean.java,v 1.16 2003/11/16 09:56:43 run2000 Exp $
See Also:
FastHash, FastList, FastScalar, FastNumber, Serialized Form

Field Summary
static FastBoolean FALSE
          Represents a false boolean expression.
static FastBoolean TRUE
          Represents a true boolean expression.
 
Method Summary
 long getAsNumber()
          Returns the boolean value as a long.
 java.lang.String getAsString()
          Returns the boolean value as a String.
static boolean getBoolean(java.lang.Object value)
          Returns true if the passed object is the TRUE instance.
static FastBoolean getInstance(boolean isTrue)
          Factory method for retrieving instances of a FastBoolean.
 boolean isEmpty()
          Is the model empty?
 java.lang.String toString()
          Retrieve the value of this object as a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE

public static final FastBoolean TRUE
Represents a true boolean expression.

FALSE

public static final FastBoolean FALSE
Represents a false boolean expression.
Method Detail

getAsString

public java.lang.String getAsString()
                             throws TemplateModelException
Returns the boolean value as a String.
Specified by:
getAsString in interface TemplateScalarModel
Returns:
the String value of this scalar.

getAsNumber

public long getAsNumber()
                 throws TemplateModelException
Returns the boolean value as a long.
Specified by:
getAsNumber in interface TemplateNumberModel
Returns:
the long value of this scalar.
Since:
1.8

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the model empty?
Specified by:
isEmpty in interface TemplateModel
Returns:
true if this object is empty, otherwise false

getInstance

public static FastBoolean getInstance(boolean isTrue)
Factory method for retrieving instances of a FastBoolean.
Parameters:
isTrue - true if we want a True instance, otherwise false to retrieve a False instance
Returns:
a True instance if isTrue is set, otherwise a False instance

getBoolean

public static boolean getBoolean(java.lang.Object value)
Returns true if the passed object is the TRUE instance.
Parameters:
value - the value to compare against the TRUE instance
Returns:
true if this is the TRUE instance, otherwise false

toString

public java.lang.String toString()
Retrieve the value of this object as a String.
Overrides:
toString in class java.lang.Object