ikayaki
Class MeasurementSequence

java.lang.Object
  extended by ikayaki.MeasurementSequence
All Implemented Interfaces:
Comparable<MeasurementSequence>

public class MeasurementSequence
extends Object
implements Comparable<MeasurementSequence>

A list of measurement steps. Steps can be added or removed from the sequence.

All operations are thread-safe.

Author:
Esko Luontola

Field Summary
private  String name
          Name of the sequence.
private  List<MeasurementStep> steps
          The measurement steps of this sequence.
 
Constructor Summary
MeasurementSequence()
          Creates an empty sequence with no name.
MeasurementSequence(Element element)
          Creates a sequence from the specified element.
MeasurementSequence(Element element, Project project)
          Creates a sequence from the specified element for a project.
MeasurementSequence(String name)
          Creates an empty sequence with the specified name.
 
Method Summary
 void addStep(int index, MeasurementStep step)
          Adds a step to the specified index of this sequence.
 void addStep(MeasurementStep step)
          Appends a step to this sequence.
 int compareTo(MeasurementSequence other)
          Orders the sequences by their name.
 Element getElement(Document document)
          Exports this sequence to a DOM element.
 String getName()
          Returns the name of this sequence.
 MeasurementStep getStep(int index)
          Returns the specified step from this sequence.
 int getSteps()
          Returns the number of steps in this sequence.
 void removeStep(int index)
          Removes a step from this sequence.
 void setName(String name)
          Sets the name of this sequence.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

private String name
Name of the sequence. Empty string if it has no name.


steps

private final List<MeasurementStep> steps
The measurement steps of this sequence.

Constructor Detail

MeasurementSequence

public MeasurementSequence()
Creates an empty sequence with no name.


MeasurementSequence

public MeasurementSequence(String name)
Creates an empty sequence with the specified name.

Parameters:
name - name of the sequence.
Throws:
NullPointerException - if name is null.

MeasurementSequence

public MeasurementSequence(Element element)
Creates a sequence from the specified element.

Parameters:
element - the element from which this sequence will be created.
Throws:
NullPointerException - if element is null.
IllegalArgumentException - if the element was not in the right format.

MeasurementSequence

public MeasurementSequence(Element element,
                           Project project)
Creates a sequence from the specified element for a project.

Parameters:
element - the element from which this sequence will be created.
project - the project whose sequence this will be, or null if this is not owned by a project. Needed for importing the measurement steps correctly.
Throws:
NullPointerException - if element is null.
IllegalArgumentException - if the element was not in the right format.
Method Detail

getElement

public Element getElement(Document document)
Exports this sequence to a DOM element.

Parameters:
document - the document that will contain this element.

getName

public String getName()
Returns the name of this sequence.


setName

public void setName(String name)
Sets the name of this sequence.

Throws:
NullPointerException - if name is null.

getSteps

public int getSteps()
Returns the number of steps in this sequence.


getStep

public MeasurementStep getStep(int index)
Returns the specified step from this sequence.

Parameters:
index - the index of the step.
Returns:
the specified step.
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getSteps()).

addStep

public void addStep(MeasurementStep step)
Appends a step to this sequence.

Parameters:
step - the measurement step to be added.
Throws:
NullPointerException - if step is null.

addStep

public void addStep(int index,
                    MeasurementStep step)
Adds a step to the specified index of this sequence.

Parameters:
index - the index to which the step will be added.
step - the measurement step to be added.
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index > getSteps()).
NullPointerException - if step is null.

removeStep

public void removeStep(int index)
Removes a step from this sequence.

Parameters:
index - the index of the step to be removed.
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getSteps()).

compareTo

public int compareTo(MeasurementSequence other)
Orders the sequences by their name. If two different sequences have the same name, one of them if always greater than the other.

Specified by:
compareTo in interface Comparable<MeasurementSequence>
Parameters:
other - the sequence to be compared to.
Returns:
less than 0 if this precedes other, or 0 if they are the same sequence, or else greater than 0.

toString

public String toString()
Overrides:
toString in class Object