Package org.uncommons.maths.number
Class AdjustableNumberGenerator<T extends java.lang.Number>
- java.lang.Object
-
- org.uncommons.maths.number.AdjustableNumberGenerator<T>
-
- Type Parameters:
T
- The type of number generated by this number generator.
- All Implemented Interfaces:
NumberGenerator<T>
public class AdjustableNumberGenerator<T extends java.lang.Number> extends java.lang.Object implements NumberGenerator<T>
Implementation ofNumberGenerator
that works similarly toConstantGenerator
but allows the returned value to be changed after instantiation. The most useful application of this type of number generator is to permit runtime re-configuration of objects that rely onNumberGenerator
s for their parameters. This can be achieved by creating UI components (e.g. sliders and spinners) that invokesetValue(Number)
when their state changes.
-
-
Constructor Summary
Constructors Constructor Description AdjustableNumberGenerator(T value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
nextValue()
void
setValue(T value)
Change the value that is returned by this generator.
-
-
-
Field Detail
-
lock
private final java.util.concurrent.locks.ReadWriteLock lock
-
value
private T extends java.lang.Number value
-
-
Constructor Detail
-
AdjustableNumberGenerator
public AdjustableNumberGenerator(T value)
- Parameters:
value
- The initial value returned by all invocations ofnextValue()
(until it is modified by a call tosetValue(Number)
.
-
-
Method Detail
-
setValue
public void setValue(T value)
Change the value that is returned by this generator.- Parameters:
value
- The new value to return.
-
nextValue
public T nextValue()
- Specified by:
nextValue
in interfaceNumberGenerator<T extends java.lang.Number>
- Returns:
- The next value from the generator.
-
-