Class SequentialCollection

java.lang.Object
All Implemented Interfaces:
Composable, Playable, java.lang.Runnable
Direct Known Subclasses:
Player, ScoreCollection

public class SequentialCollection
extends ParallelCollection
A sequential collection launches each of its Composable children in sequence. Can alternatively use a user-defined behavior function to choose which child to launch every repeat (see Behavior). If behavior function returns null child, it signals finish(), so even a colleciton with 10000 repeat count will terminate early if child returned is null. If Behavior itself is null, collection acts strictly sequentially. Can switch back and forth between these modes.

Example of building a SequentialCollection with two stock MusicJobs. The collection will act behaviorally using UniformRandomBehavior which chooses a child randomly upon each of 5 repeats.
                SequentialCollection seqCol = new SequentialCollection(new MusicJob(), new MusicJob());
                seqCol.setBehavior(new UniformRandomBehavior());
                seqCol.setRepeats(5);
                seqCol.launch(JMSL.now());

  1. startDelay
  2. start()
  3. startPlayables.play() optional
  4. startPause
  5. internalRepeat(), launches all children sequentially, or launches one chosen with behavior
  6. repeat()
  7. repeatPlayables.play() optional
  8. repeatPause (loop back to repeat() for getRepeats() times)
  9. stopDelay
  10. stopPlayables.play() optional
  11. stop()
  • Constructor Details

    • SequentialCollection

      public SequentialCollection()
      Simple constructor. Builds a SequentialCollection with no children, and initializes its Behavior to UniformRandomBehavior (although it defaults to sequential behavior). Use add(Composable) to add children.
    • SequentialCollection

      public SequentialCollection​(Composable child1)
      Conveniant constructor which automatically adds one Composable child to the sequential hierarchy.
    • SequentialCollection

      public SequentialCollection​(Composable child1, Composable child2)
      Conveniant constructor which automatically adds two Composable children to the sequential hierarchy.
    • SequentialCollection

      public SequentialCollection​(Composable child1, Composable child2, Composable child3)
      Conveniant constructor which automatically adds three Composable children to the sequential hierarchy.
    • SequentialCollection

      public SequentialCollection​(Composable child1, Composable child2, Composable child3, Composable child4)
      Conveniant constructor which automatically adds four Composable children to the sequential hierarchy.
  • Method Details

    • setBehavior

      public void setBehavior​(Behavior b)
      Plug in a class satisfying the Behavior interface, which chooses which child to launch every repeat. If behavior returns null child, finish() is called.
    • getBehavior

      public Behavior getBehavior()
      Retrieve the class that chooses a child to launch. If Behavior is null, collection executes sequentially.
      Returns:
      Behavior used to choose children.
    • internalRepeat

      public double internalRepeat​(double playTime) throws java.lang.InterruptedException
      Every repeat, either choose next child if acting sequentially (ie getBehavior() == null) or choose one using Behavior. If Behavior returns null child, finish()
      Specified by:
      internalRepeat in interface Composable
      Overrides:
      internalRepeat in class ParallelCollection
      Returns:
      time of completion
      Throws:
      java.lang.InterruptedException - if the thread running this Composable is interrupted.
    • print

      public void print()
      Overrides:
      print in class ParallelCollection
    • main

      public static void main​(java.lang.String[] args)