freemarker.template
Class FastBoolean

java.lang.Object
  extended by freemarker.template.FastBoolean
All Implemented Interfaces:
TemplateModel, TemplateNumberModel, TemplateObjectModel, TemplateScalarModel, java.io.Serializable

public final class FastBoolean
extends java.lang.Object
implements TemplateScalarModel, TemplateNumberModel, TemplateObjectModel, 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 1101 2013-04-01 04:17:32Z run2000 $
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.Object getAsObject()
          Return the model as a Boolean object.
 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.
Throws:
TemplateModelException

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.
Throws:
TemplateModelException
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
Throws:
TemplateModelException

getAsObject

public java.lang.Object getAsObject()
                             throws TemplateModelException
Return the model as a Boolean object. This is for the benefit of the reflection library.

Specified by:
getAsObject in interface TemplateObjectModel
Returns:
Boolean.TRUE if this object is true, otherwise Boolean.FALSE
Throws:
TemplateModelException - the object could not be returned

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