|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Number net.lucidviews.util.VariableNumber
public abstract class VariableNumber
An abstract base class for Number
s that can change their value.
The mandate of a VariableNumber
is to provide a number object
that can change value, thereby removing the need to instantiate a new object
each time the underlying value is changed.
However, it is important to respect the immutability of an object for
encapsulation purposes.
When a software module has created a variable number
(using its variable nature to alter its value during some processing
algorithm, say) it may want to expose that number externally. At this point
the number needs to lose its variability, to prevent other software modules
changing its value.
It is for this reason the variable number class provides the functionality
to secure the number, closing the object to any further change. Effectively
making it read-only.
Field Summary | |
---|---|
private boolean |
secure
Flag set once the value has been fixed, effectively making the number immutable. |
Constructor Summary | |
---|---|
VariableNumber()
|
Method Summary | |
---|---|
boolean |
isSecure()
Check if the value of this number has been secured. |
void |
secure()
Secure the value of this number. |
void |
setValue(byte value)
Set the value of this number. |
void |
setValue(double value)
Set the value of this number. |
void |
setValue(float value)
Set the value of this number. |
void |
setValue(int value)
Set the value of this number. |
void |
setValue(long value)
Set the value of this number. |
void |
setValue(short value)
Set the value of this number. |
protected void |
setValueInternal(byte value)
An internal set command. |
protected abstract void |
setValueInternal(double value)
An internal set command. |
protected abstract void |
setValueInternal(float value)
An internal set command. |
protected abstract void |
setValueInternal(int value)
An internal set command. |
protected abstract void |
setValueInternal(long value)
An internal set command. |
protected void |
setValueInternal(short value)
An internal set command. |
protected void |
verifyNotSecure()
Check the secure flag, throwing an exception if the number is not in a variable state. |
Methods inherited from class java.lang.Number |
---|
byteValue, doubleValue, floatValue, intValue, longValue, shortValue |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private boolean secure
Constructor Detail |
---|
public VariableNumber()
Method Detail |
---|
public void secure()
setValue
methods will cause an exception.
setValue(int)
,
setValue(long)
,
setValue(float)
,
setValue(double)
,
setValue(short)
,
setValue(byte)
public boolean isSecure()
setValue
methods.
true
if the value of this number can no longer be
changedsetValue(int)
,
setValue(long)
,
setValue(float)
,
setValue(double)
,
setValue(short)
,
setValue(byte)
protected void verifyNotSecure()
IllegalStateException
- if this number is no longer in a variable
statepublic final void setValue(int value)
value
- the new value for this number
IllegalStateException
- if this number is no longer in a variable
statesecure
,
secure()
public final void setValue(long value)
value
- the new value for this number
IllegalStateException
- if this number is no longer in a variable
statesecure
,
secure()
public final void setValue(float value)
value
- the new value for this number
IllegalStateException
- if this number is no longer in a variable
statesecure
,
secure()
public final void setValue(double value)
value
- the new value for this number
IllegalStateException
- if this number is no longer in a variable
statesecure
,
secure()
public final void setValue(short value)
value
- the new value for this number
IllegalStateException
- if this number is no longer in a variable
statesecure
,
secure()
public final void setValue(byte value)
value
- the new value for this number
IllegalStateException
- if this number is no longer in a variable
statesecure
,
secure()
protected abstract void setValueInternal(int value)
value
- the new value for this numberprotected abstract void setValueInternal(long value)
value
- the new value for this numberprotected abstract void setValueInternal(float value)
value
- the new value for this numberprotected abstract void setValueInternal(double value)
value
- the new value for this numberprotected void setValueInternal(short value)
value
- the new value for this numberprotected void setValueInternal(byte value)
value
- the new value for this number
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |