Synthia
Generic and flexible data structure generator
ca.uqac.lif.synthia.sequence.Knit< T > Class Template Reference

Detailed Description

Picker producing an "interleaved" sequence of objects from calls to multiple other pickers.

The Knit picker must be instantiated by passing to it a picker of pickers p (that is, a Picker<Picker<T>>). Upon every call to pick(), Knit proceeds as follows:

  1. It flips a coin to decide whether to create a new instance of Picker<T>; if so, it calls p.pick() and adds the resulting picker instance to its set of "living" pickers.
  2. It selects one of the living pickers, and returns the object resulting from a call to pick() on that picker.
  3. If this picker cannot produce a new value (e.g. it throws a NoMoreElementException), it is considered "dead" and is removed from the set of living pickers. In such a case, Knit flips a coin to to decide whether to create a new instance of Picker<T> to replace it; if so, it calls p.pick() and adds the resulting picker instance to its set of "living" pickers.
Author
Sylvain Hallé
Parameters
<T>The type of the objects to produce

Definition at line 51 of file Knit.java.

Inheritance diagram for ca.uqac.lif.synthia.sequence.Knit< T >:

Public Member Functions

 Knit (Picker<? extends Picker< T >> instance_picker, Picker< Boolean > new_instance, Picker< Boolean > renew_instance, Picker< Float > float_source)
 Creates a new instance of the picker. More...
 
void reset ()
 Puts the picker back into its initial state. More...
 
pick ()
 Picks an object. More...
 
Knit< T > duplicate (boolean with_state)
 Creates a copy of the picker. More...
 
String toString ()
 

Protected Attributes

Picker<? extends Picker< T > > m_instancePicker
 A picker producing pickers. More...
 
Picker< Boolean > m_newInstance
 A picker deciding whether to start a new instance at any moment. More...
 
Picker< Boolean > m_renewInstance
 A picker deciding whether to start a new instance when one has just finished. More...
 
Picker< Float > m_floatSource
 A picker used to pick a living instance. More...
 
List< Picker< T > > m_instances
 The picker instances that are currently "alive". More...
 

Static Protected Attributes

static final transient int s_maxTries = 1000
 Maximum number of tries to get a new element from an instance before giving up. More...
 

Constructor & Destructor Documentation

◆ Knit()

ca.uqac.lif.synthia.sequence.Knit< T >.Knit ( Picker<? extends Picker< T >>  instance_picker,
Picker< Boolean >  new_instance,
Picker< Boolean >  renew_instance,
Picker< Float >  float_source 
)

Creates a new instance of the picker.

Parameters
instance_pickerA picker producing picker instances
new_instanceA picker deciding whether to start a new instance at any moment
renew_instanceA picker deciding whether to start a new instance when one has just finished
float_sourceA picker used to pick a living instance

Definition at line 94 of file Knit.java.

Member Function Documentation

◆ duplicate()

Knit<T> ca.uqac.lif.synthia.sequence.Knit< T >.duplicate ( boolean  with_state)

Creates a copy of the picker.

Parameters
with_stateIf 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.
Returns
The copy of the picker

Implements ca.uqac.lif.synthia.Picker< T >.

Definition at line 147 of file Knit.java.

◆ pick()

Picks an object.

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.

Returns
The object

Implements ca.uqac.lif.synthia.Picker< T >.

Definition at line 116 of file Knit.java.

◆ reset()

void ca.uqac.lif.synthia.sequence.Knit< T >.reset ( )

Puts the 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 >.

Definition at line 106 of file Knit.java.

◆ toString()

String ca.uqac.lif.synthia.sequence.Knit< T >.toString ( )

Definition at line 161 of file Knit.java.

Member Data Documentation

◆ m_floatSource

Picker<Float> ca.uqac.lif.synthia.sequence.Knit< T >.m_floatSource
protected

A picker used to pick a living instance.

Definition at line 78 of file Knit.java.

◆ m_instancePicker

Picker<? extends Picker<T> > ca.uqac.lif.synthia.sequence.Knit< T >.m_instancePicker
protected

A picker producing pickers.

Definition at line 62 of file Knit.java.

◆ m_instances

List<Picker<T> > ca.uqac.lif.synthia.sequence.Knit< T >.m_instances
protected

The picker instances that are currently "alive".

Definition at line 83 of file Knit.java.

◆ m_newInstance

Picker<Boolean> ca.uqac.lif.synthia.sequence.Knit< T >.m_newInstance
protected

A picker deciding whether to start a new instance at any moment.

Definition at line 67 of file Knit.java.

◆ m_renewInstance

Picker<Boolean> ca.uqac.lif.synthia.sequence.Knit< T >.m_renewInstance
protected

A picker deciding whether to start a new instance when one has just finished.

Definition at line 73 of file Knit.java.

◆ s_maxTries

final transient int ca.uqac.lif.synthia.sequence.Knit< T >.s_maxTries = 1000
staticprotected

Maximum number of tries to get a new element from an instance before giving up.

Definition at line 57 of file Knit.java.


The documentation for this class was generated from the following file: