ikayaki
Class MeasurementStep

java.lang.Object
  extended by ikayaki.MeasurementStep
All Implemented Interfaces:
Iterable<MeasurementResult>

public class MeasurementStep
extends Object
implements Iterable<MeasurementResult>

A single step in a measurement sequence. Each step can include multiple measurements for improved precision. A step can have a different volume and mass than the related project, but by default the volume and mass of the project will be used. Any changes made to the measurement step will invoke the project's autosaving. Only the project may change the state and results of a measurement step.

All operations are thread-safe.

Author:
Esko Luontola

Nested Class Summary
static class MeasurementStep.State
          The state of a measurement step.
 
Field Summary
private  double mass
          The mass of this step's sample, or a negative number to use the project's default mass.
private  Project project
          The project that owns this step, or null if there is no owner.
private  List<MeasurementResult> results
          The individual measurement results that are part of this measurement step.
private  MeasurementStep.State state
          Tells if this step has been completed or not, or if a measurement is still running.
private  double stepValue
          The AF or Thermal value of this step, or a negative number if it has not been specified.
private  double susceptibility
          The susceptibility of this step's sample, or a negative number to use the project's default volume.
private  Date timestamp
          The time the measurements were completed, or null if that has not yet happened.
private  double volume
          The volume of this step's sample, or a negative number to use the project's default volume.
 
Constructor Summary
MeasurementStep()
          Creates a blank measurement step.
MeasurementStep(Element element)
          Creates a measurement step from the specified element.
MeasurementStep(Element element, Project project)
          Creates a measurement step from the specified element for a project.
MeasurementStep(Project project)
          Creates a blank measurement step for a project.
 
Method Summary
 void addResult(MeasurementResult result)
          Appends a measurement result to this step.
 Element getElement(Document document)
          Exports this step to a DOM element.
 javax.vecmath.Vector3d getHolder()
          Returns the average of the holder results (raw values).
 double getMass()
          Returns the mass of this step's sample, or a negative number to use the project's default mass.
 javax.vecmath.Vector3d getNoise()
          Returns the average of the noise results (raw values).
 Project getProject()
          Returns the owner project of this step, or null if there is no owner.
 MeasurementResult getResult(int index)
          Returns the specified result from this step.
 int getResults()
          Returns the number of results in this step.
 MeasurementStep.State getState()
          Tells if this step has been completed or not, or if a measurement is still running.
 double getStepValue()
          Returns the AF/Thermal value of this step, or a negative number if it has not been specified.
 double getSusceptibility()
          Returns the susceptibility of this step's sample, or a negative number to use the project's default susceptibility.
 Date getTimestamp()
          Returns the time the measurements were completed, or null if that has not yet happened.
 double getVolume()
          Returns the volume of this step's sample, or a negative number to use the project's default volume.
 Iterator<MeasurementResult> iterator()
          Returns an iterator for iterating through this step's measurement results.
 void save()
          Invokes the owner project's autosaving.
 void setDone()
          Called after all results have been added.
 void setMass(double mass)
          Sets the mass of this step's sample.
 void setMeasuring()
          Called when the step's measurements are started.
 void setStepValue(double stepValue)
          Sets the value of this step.
 void setSusceptibility(double susceptibility)
          Sets the susceptibility of this step's sample.
 void setVolume(double volume)
          Sets the volume of this step's sample.
protected  void updateTransforms()
          Updates all of the measurement results with the owner project's transformation matrix and applies the noise and holder fixes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

project

private final Project project
The project that owns this step, or null if there is no owner.


state

private MeasurementStep.State state
Tells if this step has been completed or not, or if a measurement is still running.


timestamp

private Date timestamp
The time the measurements were completed, or null if that has not yet happened. This equals the time of the latest measurement result.


stepValue

private double stepValue
The AF or Thermal value of this step, or a negative number if it has not been specified. The unit is millitesla (when AF) or Celcius (when thermal).


mass

private double mass
The mass of this step's sample, or a negative number to use the project's default mass. The unit is gram.


volume

private double volume
The volume of this step's sample, or a negative number to use the project's default volume. The unit is cm^3.


susceptibility

private double susceptibility
The susceptibility of this step's sample, or a negative number to use the project's default volume. The unit is 10^-6 SI.


results

private final List<MeasurementResult> results
The individual measurement results that are part of this measurement step.

Constructor Detail

MeasurementStep

public MeasurementStep()
Creates a blank measurement step.


MeasurementStep

public MeasurementStep(Project project)
Creates a blank measurement step for a project.

Parameters:
project - the project who is the owner of this step.

MeasurementStep

public MeasurementStep(Element element)
Creates a measurement step from the specified element. Will update the transformation matrices.

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

MeasurementStep

public MeasurementStep(Element element,
                       Project project)
Creates a measurement step from the specified element for a project. Will update the transformation matrices.

Parameters:
element - the element from which this step will be created.
project - the project who is the owner of this step.
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 step to a DOM element.

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

save

public void save()
Invokes the owner project's autosaving. If there is no owner, will do nothing.


getProject

public Project getProject()
Returns the owner project of this step, or null if there is no owner.


getState

public MeasurementStep.State getState()
Tells if this step has been completed or not, or if a measurement is still running.


getTimestamp

public Date getTimestamp()
Returns the time the measurements were completed, or null if that has not yet happened.


getStepValue

public double getStepValue()
Returns the AF/Thermal value of this step, or a negative number if it has not been specified. The unit is millitesla (when AF) or Celcius (when thermal).


setStepValue

public void setStepValue(double stepValue)
Sets the value of this step. A negative value will clear it. The unit is millitesla (when AF) or Celcius (when thermal).

If this step is part of an AF project, the stepValue will be adjusted to be the closest correct value.

Throws:
IllegalStateException - if the step's state is not READY.

getMass

public double getMass()
Returns the mass of this step's sample, or a negative number to use the project's default mass. The unit is gram.


setMass

public void setMass(double mass)
Sets the mass of this step's sample. A negative value will clear it. The unit is gram.


getVolume

public double getVolume()
Returns the volume of this step's sample, or a negative number to use the project's default volume. The unit is cm^3.


setVolume

public void setVolume(double volume)
Sets the volume of this step's sample. A negative value will clear it. The unit is cm^3.


getSusceptibility

public double getSusceptibility()
Returns the susceptibility of this step's sample, or a negative number to use the project's default susceptibility. The unit is 10^-6 SI.


setSusceptibility

public void setSusceptibility(double susceptibility)
Sets the susceptibility of this step's sample. A negative value will clear it. The unit is 10^-6 SI.


updateTransforms

protected void updateTransforms()
Updates all of the measurement results with the owner project's transformation matrix and applies the noise and holder fixes. If there is no owner, an identity matrix will be used.


getResults

public int getResults()
Returns the number of results in this step.


getResult

public MeasurementResult getResult(int index)
Returns the specified result from this step.

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

addResult

public void addResult(MeasurementResult result)
Appends a measurement result to this step. This method may be called only for a steps whose state is READY or MEASURING.

Sets the timestamp to the current time. Sets the state to MEASURING. The transformation matrix of the result will be updated automatically.

Parameters:
result - the result to be added.
Throws:
NullPointerException - if result is null.
IllegalStateException - if this step's state is not READY or MEASURING.

setMeasuring

public void setMeasuring()
Called when the step's measurements are started. Sets the step's state to MEASURING.

Throws:
IllegalStateException - if this method is called when the state is marked as DONE.

setDone

public void setDone()
Called after all results have been added. Sets the step's status to DONE_RECENTLY and prevents the adding of further results. If there are no results (maybe the measurement was cancelled), will set the state back to READY. If the state is already DONE or DONE_RECENTLY, then nothing will be changed.


getHolder

public javax.vecmath.Vector3d getHolder()
Returns the average of the holder results (raw values). If there are no holder results or this is the holder calibration project itself, will return a zero-filled vector.


getNoise

public javax.vecmath.Vector3d getNoise()
Returns the average of the noise results (raw values). If there are no noise results, will return a zero-filled vector.


iterator

public Iterator<MeasurementResult> iterator()
Returns an iterator for iterating through this step's measurement results.

Specified by:
iterator in interface Iterable<MeasurementResult>