Package org.apache.lucene.util
Class SetOnce<T>
- java.lang.Object
-
- org.apache.lucene.util.SetOnce<T>
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class SetOnce<T> extends java.lang.Object implements java.lang.Cloneable
A convenient class which offers a semi-immutable object wrapper implementation which allows one to set the value of an object exactly once, and retrieve it many times. Ifset(Object)
is called more than once,SetOnce.AlreadySetException
is thrown and the operation will fail.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SetOnce.AlreadySetException
Thrown whenset(Object)
is called more than once.
-
Constructor Summary
Constructors Constructor Description SetOnce()
A default constructor which does not set the internal object, and allows setting it by callingset(Object)
.SetOnce(T obj)
Creates a new instance with the internal object set to the given object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SetOnce<T>
clone()
T
get()
Returns the object set byset(Object)
.void
set(T obj)
Sets the given object.
-
-
-
Constructor Detail
-
SetOnce
public SetOnce()
A default constructor which does not set the internal object, and allows setting it by callingset(Object)
.
-
SetOnce
public SetOnce(T obj)
Creates a new instance with the internal object set to the given object. Note that any calls toset(Object)
afterwards will result inSetOnce.AlreadySetException
- Throws:
SetOnce.AlreadySetException
- if called more than once- See Also:
set(Object)
-
-
Method Detail
-
set
public final void set(T obj)
Sets the given object. If the object has already been set, an exception is thrown.
-
get
public final T get()
Returns the object set byset(Object)
.
-
-