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

Detailed Description

Picker that returns values taken from a list.

As its name implies, Playback literally replays the values fetched from a list that was passed to its constructor. It loops back to the beginning when the list is over (this can optionally be disabled).

Playback<Integer> p = new Playback<Integer>(2, 7, 1);
System.out.println(p.pick()); // 2
System.out.println(p.pick()); // 7
System.out.println(p.pick()); // 1
System.out.println(p.pick()); // 2
...

Optionally, the picker can be told to start at a different element than the first one. By default, the picker keeps outputting the last value of the sequence if more values are requested and the loop parameter is set to false.

Parameters
<T>The type of objects to return

Definition at line 61 of file Playback.java.

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

Public Member Functions

 Playback (int start_index, T ... values)
 Creates a new Playback picker. More...
 
 Playback (T ... values)
 Creates a new Playback picker. More...
 
 Playback (int start_index, List< T > values)
 Creates a new Playback picker. More...
 
 Playback (List< T > values)
 Creates a new Playback picker. More...
 
pick ()
 Picks the next value in the list of the Playback picker. More...
 
void reset ()
 Puts the Playback picker back into its initial state. More...
 
Playback< T > duplicate (boolean with_state)
 Picks a random string. More...
 
Playback< T > setLoop (boolean b)
 Set the m_loop attribute of the playback picker. More...
 
boolean isDone ()
 Signals if the playback picker picked all the objects from m_values. More...
 
Shrinkable< T > shrink (T o, Picker< Float > decision, float m)
 Shrinks a picker. More...
 
PartNode getExplanation (Part p)
 
PartNode getExplanation (Part p, NodeFactory f)
 
String toString ()
 
Shrinkable< T > shrink (T o)
 Shrinks a picker with default parameters. More...
 
SequenceShrinkable< T > shrink (Picker< Float > d, float m)
 Shrinks a picker. More...
 
List< T > getSequence ()
 Gets the sequence of values that the picker has produced so far. More...
 

Protected Attributes

T[] m_values
 The values to play back. More...
 
int m_index
 The index of the current value. More...
 
int m_startIndex
 The start index. More...
 
boolean m_loop
 Whether to loop through the values. More...
 

Constructor & Destructor Documentation

◆ Playback() [1/4]

ca.uqac.lif.synthia.sequence.Playback< T >.Playback ( int  start_index,
T ...  values 
)

Creates a new Playback picker.

Parameters
start_indexThe position of the first value to return
valuesThe values to play back

Definition at line 89 of file Playback.java.

◆ Playback() [2/4]

Creates a new Playback picker.

Parameters
valuesThe values to play back

Definition at line 102 of file Playback.java.

◆ Playback() [3/4]

ca.uqac.lif.synthia.sequence.Playback< T >.Playback ( int  start_index,
List< T >  values 
)

Creates a new Playback picker.

Parameters
start_indexThe position of the first value to return
valuesThe values to play back

Definition at line 113 of file Playback.java.

◆ Playback() [4/4]

ca.uqac.lif.synthia.sequence.Playback< T >.Playback ( List< T >  values)

Creates a new Playback picker.

Parameters
valuesThe values to play back

Definition at line 124 of file Playback.java.

Member Function Documentation

◆ duplicate()

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

Picks a random string.

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 random string.

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

Reimplemented in ca.uqac.lif.synthia.enumerative.AllElements< T >.

Definition at line 175 of file Playback.java.

◆ getExplanation() [1/2]

PartNode ca.uqac.lif.synthia.sequence.Playback< T >.getExplanation ( Part  p)

Definition at line 220 of file Playback.java.

◆ getExplanation() [2/2]

PartNode ca.uqac.lif.synthia.sequence.Playback< T >.getExplanation ( Part  p,
NodeFactory  f 
)

Definition at line 226 of file Playback.java.

◆ getSequence()

List<T> ca.uqac.lif.synthia.sequence.Playback< T >.getSequence ( )

Gets the sequence of values that the picker has produced so far.

Returns
The sequence of values

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

Definition at line 292 of file Playback.java.

◆ isDone()

boolean ca.uqac.lif.synthia.sequence.Playback< T >.isDone ( )

Signals if the playback picker picked all the objects from m_values.

Loop attributes must be false. If loop is true, the method will always return false.

Returns
true if the picker picked all the objects from m_values and false if it's not the case.

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

Reimplemented in ca.uqac.lif.synthia.enumerative.AllElements< T >.

Definition at line 208 of file Playback.java.

◆ pick()

Picks the next value in the list of the Playback picker.

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 next value

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

Reimplemented in ca.uqac.lif.synthia.enumerative.AllElements< T >.

Definition at line 138 of file Playback.java.

◆ reset()

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

Reimplemented in ca.uqac.lif.synthia.enumerative.AllElements< T >.

Definition at line 160 of file Playback.java.

◆ setLoop()

Playback<T> ca.uqac.lif.synthia.sequence.Playback< T >.setLoop ( boolean  b)

Set the m_loop attribute of the playback picker.

If the attribute is set to false, the next call to the pick() method will return a NoMoreElementException after producing the last element of the list.

Parameters
bboolean value to enable playback loop or not
Returns
The actual instance of the class.

Definition at line 196 of file Playback.java.

◆ shrink() [1/3]

SequenceShrinkable<T> ca.uqac.lif.synthia.sequence.Playback< T >.shrink ( Picker< Float >  d,
float  magnitude 
)

Shrinks a picker.

The method has two arguments: a source of randomness and a magnitude parameter. A picker may use the magnitude to determine how "aggressive" is the shrinking process. A value of 1 is expected to produce a picker with the broadest set, and may return any subsequence of its past values. Lower values (all the way down to 0) instruct the picker to exclude further elements, and typically to only produce sub-sequences that are relatively "much smaller" than the reference.

Parameters
dA source of randomness. Some pickers must make choices when producing shrunk sequences, and this parameter is used as an external source for these choices.
magnitudeA magnitude parameter, which must be between 0 and 1.
Returns
The returned picker instance. This object may be of a different class from the object on which the method is called.

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

Definition at line 270 of file Playback.java.

◆ shrink() [2/3]

Shrinks a picker with default parameters.

For any picker p that implements the Shrinkable interface, a call to p.shrink(o) should be the same as a call to p.shrink(o, RandomFloat.instance, 1).

Parameters
oThe reference object. The picker must guarantee that the returned picker instance only produces objects that are smaller than o, according to an implicit ordering relation that is specific to each object type and each picker.
Returns
The returned picker instance. This object may be of a different class from the object on which the method is called.
See also
#shrink(Object, Picker, float)

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

Definition at line 264 of file Playback.java.

◆ shrink() [3/3]

Shrinkable<T> ca.uqac.lif.synthia.sequence.Playback< T >.shrink ( o,
Picker< Float >  d,
float  m 
)

Shrinks a picker.

The method adds two arguments with respect to shrink(Object): a source of randomness and a magnitude parameter. A picker may use the magnitude to determine how "aggressive" is the shrinking process. A value of 1 is expected to produce a picker with the broadest set, and may return all possible objects that are smaller than the reference. Lower values (all the way down to 0) instruct the picker to exclude further objects, and typically to only produce objects that are relatively "much smaller" than the reference.

Parameters
oThe reference object. The picker must guarantee that the returned picker instance only produces objects that are smaller than o, according to an implicit ordering relation that is specific to each object type and each picker.
dA source of randomness. Some pickers must make choices when producing shrunk objects, and this parameter is used as an external source for these choices.
mA magnitude parameter, which must be between 0 and 1.
Returns
The returned picker instance. This object may be of a different class from the object on which the method is called.

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

Definition at line 214 of file Playback.java.

◆ toString()

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

Definition at line 247 of file Playback.java.

Member Data Documentation

◆ m_index

int ca.uqac.lif.synthia.sequence.Playback< T >.m_index
protected

The index of the current value.

Definition at line 71 of file Playback.java.

◆ m_loop

boolean ca.uqac.lif.synthia.sequence.Playback< T >.m_loop
protected

Whether to loop through the values.

Definition at line 81 of file Playback.java.

◆ m_startIndex

int ca.uqac.lif.synthia.sequence.Playback< T >.m_startIndex
protected

The start index.

Definition at line 76 of file Playback.java.

◆ m_values

T [] ca.uqac.lif.synthia.sequence.Playback< T >.m_values
protected

The values to play back.

Definition at line 66 of file Playback.java.


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