![]() |
Synthia
Generic and flexible data structure generator
|
Picker that returns the first value fetched from another picker, and then null afterwards.
For example, the following piece of code instantiates a RandomFloat r; the Once picker wraps around it, returns the first random float returned by r, and then null on subsequent calls.
RandomFloat r = new RandomFloat(); Once<Float> f = new Once<Float>(r); float f1 = f.pick(); // 0.8104950, for example float f2 = f.pick(); // null float f3 = f.pick(); // null again ...
Note that a call to reset() will cause the picker to return a non-null object on its next call to pick().
| <T> | The type of object to pick |

Public Member Functions | |
| Once (Picker< T > picker) | |
| Creates a new Once picker. More... | |
| void | reset () |
| Puts the once picker back into its initial state. More... | |
| T | pick () |
| Picks a random value. More... | |
| Once< T > | duplicate (boolean with_state) |
| Creates a copy of the once picker. More... | |
| ca.uqac.lif.synthia.util.Once< T >.Once | ( | Picker< T > | picker | ) |
| Once<T> ca.uqac.lif.synthia.util.Once< T >.duplicate | ( | boolean | with_state | ) |
Creates a copy of the once picker.
| with_state | If set to false, the returned copy is set to the class' initial state (i.e. same thing as calling the picker's constructor). If set to true, the returned copy is put into the same internal state as the object it is copied from. |
Implements ca.uqac.lif.synthia.Picker< T >.
| T ca.uqac.lif.synthia.util.Once< T >.pick | ( | ) |
Picks a random value.
Typically, this method is expected to return non-null objects; a null return value is used to signal that no more objects will be produced. That is, once this method returns null, it should normally return null on all subsequent calls.
Implements ca.uqac.lif.synthia.Picker< T >.
| void ca.uqac.lif.synthia.util.Once< T >.reset | ( | ) |
Puts the once picker back into its initial state.
This means that the sequence of calls to pick() will produce the same values as when the object was instantiated.
Implements ca.uqac.lif.synthia.Picker< T >.