net.lucidviews.util
Class NotNull<T>

java.lang.Object
  extended by net.lucidviews.util.NotNull<T>
Type Parameters:
T - the type of variable being wrapped

public class NotNull<T>
extends Object

A wrapper class for maintaining a variable in a not-null state.

The wrapper class will perform checks to ensure the variable is never set to null.
Performing the null pointer check when a value is set removes the need to check for a null pointer when the value is used/accessed.
It also ensures that any process fails early (at the time when an inappropriate value is computed/assigned) rather than allowing the program to continue until the value is accessed.

Since:
1.3
Version:
$Revision: 1.1.2.2 $
Author:
Stephen Battey

Field Summary
protected  T value
          The current value.
 
Constructor Summary
NotNull(T value)
          Create a variable that is always guaranteed not null.
 
Method Summary
 T getValue()
          Get the value.
static
<T> NotNull<T>
instance(T value)
          Create a NotNull variable using an initial value.
 void setValue(T value)
          Change the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

value

protected T value
The current value.

Constructor Detail

NotNull

public NotNull(T value)
Create a variable that is always guaranteed not null.
If the initial value is null an IllegalNullValueException will be thrown.

Parameters:
value - the initial value, which can't be null
Method Detail

instance

public static <T> NotNull<T> instance(T value)
Create a NotNull variable using an initial value.
This is just a convenience method for creating new instances of the NotNull class.

Type Parameters:
T - the type of variable being wrapped
Parameters:
value - the initial value, which can't be null
Returns:
a NotNull wrapper around the original value

setValue

public void setValue(T value)
Change the value.
If the new value is null an IllegalNullValueException will be thrown.

Parameters:
value - the new value, which can't be null

getValue

public T getValue()
Get the value.
The return value is guaranteed not to be null.

Returns:
the value