com.yosokumo.core
Class Specimen

java.lang.Object
  extended by com.yosokumo.core.Specimen

public class Specimen
extends java.lang.Object

A row of values. Other terminology that is sometimes used: An observation, a record, an example, or an instance. These are the primary characteristics of a Specimen:


Nested Class Summary
static class Specimen.Status
          Provides a logical delete facility.
 
Field Summary
private  java.util.List<Cell> cellSequence
          A sequence of cells.
private  long key
           
private  Value predictand
           
private  Specimen.Status status
           
private  long weight
           
 
Constructor Summary
Specimen(long key)
          Initializes a newly created Specimen object with key specified by the input parameter.
Specimen(long key, java.util.Collection<Cell> cells)
          Initializes a newly created Specimen object with key and cell sequence as specified by the input parameters.
Specimen(long key, Specimen.Status status, long weight, Value predictand, java.util.Collection<Cell> cells)
          Initializes a newly created Specimen object with attributes specified by the input parameters.
Specimen(long key, Value predictand, java.util.Collection<Cell> cells)
          Initializes a newly created Specimen object with key, predictand, and cell sequence as specified by the input parameters.
 
Method Summary
(package private)  void addCell(Cell cell)
          Add a Cell to the cell sequence.
(package private)  boolean addCells(java.util.Collection<Cell> cells)
          Add a collection of Cells to the cell sequence.
(package private)  void clearCells()
          Remove all cells from the sequence.
(package private)  Cell getCell(int index)
          Return a cell from the cell sequence.
 java.util.List<Cell> getCells()
          Return all cells in the cell sequence as a List<Cell>.
 Value getPredictand()
          Return the specimen predictand.
 long getSpecimenKey()
          Return the specimen key.
 Specimen.Status getStatus()
          Return the specimen status.
 long getWeight()
          Return the specimen weight.
 boolean isEmpty()
          Return true if the sequence contains no cells.
(package private)  boolean removeCells(int numCellsToRemove)
          Remove cells from the end of the sequence.
 void setCells(java.util.List<Cell> cells)
          Set the cells of this Specimen to the cell list specified by the parameter.
 void setPredictand(Value v)
          Set the specimen predictand.
 void setSpecimenKey(long key)
          Set the specimen key.
 void setStatus(Specimen.Status s)
          Set the specimen status.
 void setWeight(long w)
          Set the specimen weight.
 int size()
          Return the number of cells in the sequence.
 java.lang.String toString()
          Return a string representation of this Specimen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

key

private long key

status

private Specimen.Status status

weight

private long weight

predictand

private Value predictand

cellSequence

private java.util.List<Cell> cellSequence
A sequence of cells.

Constructor Detail

Specimen

public Specimen(long key)
Initializes a newly created Specimen object with key specified by the input parameter. Other attributes are set to default values:

Parameters:
key - the key of the specimen.

Specimen

public Specimen(long key,
                java.util.Collection<Cell> cells)
Initializes a newly created Specimen object with key and cell sequence as specified by the input parameters. Other attributes are set to default values:

Parameters:
key - the key of the specimen.
cells - the cell sequence of the specimen.

Specimen

public Specimen(long key,
                Value predictand,
                java.util.Collection<Cell> cells)
Initializes a newly created Specimen object with key, predictand, and cell sequence as specified by the input parameters. Other attributes are set to default values:

Parameters:
key - the key of the specimen.
predictand - the predictand of the specimen.
cells - the cell sequence of the specimen.

Specimen

public Specimen(long key,
                Specimen.Status status,
                long weight,
                Value predictand,
                java.util.Collection<Cell> cells)
Initializes a newly created Specimen object with attributes specified by the input parameters.

Parameters:
key - the key of the specimen.
status - the status of the specimen.
weight - the weight of the specimen.
predictand - the predictand of the specimen.
cells - the cell sequence of the specimen.
Method Detail

setSpecimenKey

public void setSpecimenKey(long key)
Set the specimen key.

Parameters:
key - the key to assign to this specimen. This is the unique identification of the specimen. It must be positive.

getSpecimenKey

public long getSpecimenKey()
Return the specimen key.

Returns:
the key of this specimen, which is the unique identification of the specimen.

setStatus

public void setStatus(Specimen.Status s)
Set the specimen status.

Parameters:
s - the status to assign to this specimen.

getStatus

public Specimen.Status getStatus()
Return the specimen status.

Returns:
the status of this specimen.

setWeight

public void setWeight(long w)
Set the specimen weight.

Parameters:
w - the weight to assign to this specimen.

getWeight

public long getWeight()
Return the specimen weight.

Returns:
the weight of this specimen.

setPredictand

public void setPredictand(Value v)
Set the specimen predictand.

Parameters:
v - the predictand to assign to this specimen.

getPredictand

public Value getPredictand()
Return the specimen predictand.

Returns:
the predictand of this specimen.

addCell

void addCell(Cell cell)
Add a Cell to the cell sequence. The Cell parameter is appended to the end of the cell sequence.

Parameters:
cell - the Cell to add to the cell sequence.

addCells

boolean addCells(java.util.Collection<Cell> cells)
Add a collection of Cells to the cell sequence. The Cells in the collection specified by the parameter are appended to the end of the cell sequence. The order the cells are appended is the order in which the collection's Iterator returns the cells.

Parameters:
cells - the collection of Cells to add to the cell sequence.
Returns:
true if and only if the cell sequence changes.

removeCells

boolean removeCells(int numCellsToRemove)
Remove cells from the end of the sequence. The specified number of cells are removed from the end of the cell sequence.

Parameters:
numCellsToRemove - is the number of cells to remove from the end of the sequence. If this value is zero or negative, no cells are removed. If this value exceeds the number of cells in the sequence, then all cells are removed.
Returns:
true if and only if the sequence is changed.

getCell

Cell getCell(int index)
Return a cell from the cell sequence. This makes it possible to iterate over all cells in the sequence like this:
   for (int i = 0;  i < cellSequence.size();  ++i)
   {
       Cell c = cellSequence.getCell(i)
       process cell c
   }
 
Caution: It is better to iterate over all cells by using getCells as shown below because that approach is efficient no matter what kind of List is used to implement the sequence. Iterating as shown just above is extremely expensive if the LinkedList implementation is used.

Parameters:
index - specifying which cell of the sequence to return. 0-based.
Returns:
the Cell at the location specified by the index.

getCells

public java.util.List<Cell> getCells()
Return all cells in the cell sequence as a List<Cell>. This makes it possible to iterate over all cells in the sequence like this:
   for (Cell c : cellSequence.getCells())
   {
       process cell c
   }
 

Returns:
a sequence of all cells in the cell sequence.

setCells

public void setCells(java.util.List<Cell> cells)
Set the cells of this Specimen to the cell list specified by the parameter.

Parameters:
cells - a list of cells to assign to this Specimen

clearCells

void clearCells()
Remove all cells from the sequence. After a call of this method, the sequence is empty, i.e., it contains no cells.


size

public int size()
Return the number of cells in the sequence.

Returns:
the number of cells in the sequence.

isEmpty

public boolean isEmpty()
Return true if the sequence contains no cells.

Returns:
true if the sequence contains no cells. false otherwise.

toString

public java.lang.String toString()
Return a string representation of this Specimen.

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this Specimen.