org.ow2.bonita.util
Class Final<T>

java.lang.Object
  extended by org.ow2.bonita.util.Final<T>
Type Parameters:
T -
All Implemented Interfaces:
java.io.Serializable

public class Final<T>
extends java.lang.Object
implements java.io.Serializable

This class provides an efficient way --- using hardware instructions if available --- for holding a variable that can only be initialized once (aka: final variables). This class helps when it is not possible to declare a variable as final but still, you need it to be initialized only once (e.g: in a setter). Note that you cannot initialize a variable to null using this class. This class is thread safe.

Author:
Pierre Vigneras
See Also:
Serialized Form

Constructor Summary
Final()
           
 
Method Summary
 T get()
          Return the value of the initialized variable.
protected  T getValue()
          Return the current value of this variable.
 void init(T t)
          Initialize this variable to the given value.
 boolean isInitialized()
          Check the initialized status of this final variable.
protected  void setValue(T t)
          Set the value of this variable directly.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Final

public Final()
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getValue

protected T getValue()
Return the current value of this variable. No check is performed. May return null.

Returns:
the current value of this variable. No check is performed. May return null.

setValue

protected void setValue(T t)
Set the value of this variable directly. No check is perform. Multiple set is thus possible.

Parameters:
t - the value to set this variable to.

init

public void init(T t)
Initialize this variable to the given value. The given value should not be null.

Parameters:
t - the value
Throws:
java.lang.IllegalArgumentException - if the given value is null
java.lang.IllegalStateException - if the variable has already been set.

get

public T get()
Return the value of the initialized variable.

Returns:
the value of the initialized variable, or null if it has not been initialized yet.

isInitialized

public boolean isInitialized()
Check the initialized status of this final variable.

Returns:
true if this final variable has been initialized, false otherwise.


Copyright © 2009 OW2 Consortium. All Rights Reserved.