mavis
Class MeasurementSequence

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

public class MeasurementSequence
extends java.lang.Object
implements java.lang.Comparable<MeasurementSequence>

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

All operations are thread-safe.


Field Summary
private  java.lang.String name
          Name of the sequence.
private  java.util.List<MeasurementStep> steps
          The measurement steps of this sequence.
 
Constructor Summary
MeasurementSequence()
          Creates an empty sequence with no name.
MeasurementSequence(org.w3c.dom.Element element)
          Creates a sequence from the specified element.
MeasurementSequence(org.w3c.dom.Element element, Project project)
          Creates a sequence from the specified element for a project.
MeasurementSequence(java.lang.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.
 org.w3c.dom.Element getElement(org.w3c.dom.Document document)
          Exports this sequence to a DOM element.
 java.lang.String getName()
          Returns the name of this sequence.
 MeasurementStep getStep(int index)
          Returns the specified step from this sequence.
 int getStepIndex(MeasurementStep step)
          Returns the index of the given MeasurementStep object in the sequence or -1 if it isn't in the sequence.
 int getSteps()
          Returns the number of steps in this sequence.
 void removeStep(int index)
          Removes a step from this sequence.
 void setName(java.lang.String name)
          Sets the name of this sequence.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

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


steps

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

Constructor Detail

MeasurementSequence

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


MeasurementSequence

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

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

MeasurementSequence

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

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

MeasurementSequence

public MeasurementSequence(org.w3c.dom.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:
java.lang.NullPointerException - if element is null.
java.lang.IllegalArgumentException - if the element was not in the right format.
Method Detail

getElement

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

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

getName

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


setName

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

Throws:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > getSteps()).
java.lang.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:
java.lang.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 java.lang.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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

getStepIndex

public int getStepIndex(MeasurementStep step)
Returns the index of the given MeasurementStep object in the sequence or -1 if it isn't in the sequence.

Parameters:
step - a MeasurementStep object whose index we need.
Returns:
the index of the given MeasurementStep or -1 if the step is not in the sequence.