com.yosokumo.core
Class SpecimenBlock

java.lang.Object
  extended by com.yosokumo.core.Block
      extended by com.yosokumo.core.SpecimenBlock

 class SpecimenBlock
extends Block

A block of Specimens.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.yosokumo.core.Block
Block.Type
 
Field Summary
private  java.util.List<Specimen> specimenSequence
          A sequence of Specimens.
 
Constructor Summary
SpecimenBlock()
          Initializes a newly created SpecimenBlock object with default attributes.
SpecimenBlock(java.util.Collection<Specimen> specimenCollection)
          Initializes a newly created SpecimenBlock object with the specimen sequence specified by the input parameter.
SpecimenBlock(java.lang.String id)
          Initializes a newly created SpecimenBlock object with a study identifier.
SpecimenBlock(java.lang.String id, java.util.Collection<Specimen> specimenCollection)
          Initializes a newly created SpecimenBlock object with the study identifier and the specimen sequence specified by the input parameters.
 
Method Summary
(package private)  void addSpecimen(Specimen specimen)
          Add a Specimen to the block.
(package private)  boolean addSpecimens(java.util.Collection<Specimen> specimens)
          Add a collection of Specimens to the block.
(package private)  void clearSpecimens()
          Remove all specimens from the block.
(package private)  Specimen getSpecimen(int index)
          Return a specimen from the block.
(package private)  java.util.List<Specimen> getSpecimenSequence()
          Return all specimens in the block as a List<Specimen>.
(package private)  Block.Type getType()
          Return the specimen block type.
(package private)  boolean isEmpty()
          Return true if the block contains no specimens.
(package private)  boolean removeSpecimens(int numSpecimensToRemove)
          Remove specimens from the end of the block.
(package private)  int size()
          Return the number of specimens in the block.
 java.lang.String toString()
          Return a string representation of this SpecimenBlock.
 
Methods inherited from class com.yosokumo.core.Block
getStudyIdentifier, setStudyIdentifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

specimenSequence

private java.util.List<Specimen> specimenSequence
A sequence of Specimens.

Constructor Detail

SpecimenBlock

SpecimenBlock()
Initializes a newly created SpecimenBlock object with default attributes.


SpecimenBlock

SpecimenBlock(java.lang.String id)
Initializes a newly created SpecimenBlock object with a study identifier.

Parameters:
id - a study identifier for the block.

SpecimenBlock

SpecimenBlock(java.util.Collection<Specimen> specimenCollection)
Initializes a newly created SpecimenBlock object with the specimen sequence specified by the input parameter.

Parameters:
specimenCollection - the specimen sequence of the specimen.

SpecimenBlock

SpecimenBlock(java.lang.String id,
              java.util.Collection<Specimen> specimenCollection)
Initializes a newly created SpecimenBlock object with the study identifier and the specimen sequence specified by the input parameters.

Parameters:
id - a study identifier for the block.
specimenCollection - the specimen sequence of the specimen.
Method Detail

getType

Block.Type getType()
Return the specimen block type.

Specified by:
getType in class Block
Returns:
the specimen block type: Type.SPECIMEN.

addSpecimen

void addSpecimen(Specimen specimen)
Add a Specimen to the block. The specimen parameter is appended to the end of the specimen sequence.

Parameters:
specimen - the Specimen to add to the block.

addSpecimens

boolean addSpecimens(java.util.Collection<Specimen> specimens)
Add a collection of Specimens to the block. The Specimens in the collection specified by the parameter are appended to the end of the specimen sequence. The order the specimens are appended is the order in which the collection's Iterator returns the specimens.

Parameters:
specimens - the collection of Specimens to add to the block.
Returns:
true if and only if the specimen sequence changes.

removeSpecimens

boolean removeSpecimens(int numSpecimensToRemove)
Remove specimens from the end of the block. The specified number of specimens are removed from the end of the specimen sequence.

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

getSpecimen

Specimen getSpecimen(int index)
Return a specimen from the block. This makes it possible to iterate over all specimens in the sequence like this:
   for (int i = 0;  i < specimenSequence.size();  ++i)
   {
       Specimen c = specimenSequence.getSpecimen(i)
       process specimen c
   }
 
Caution: It is better to iterate over all specimens by using getSpecimenSequence 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 the specimen of the 0-based block.
Returns:
the Specimen at the location specified by the index.

getSpecimenSequence

java.util.List<Specimen> getSpecimenSequence()
Return all specimens in the block as a List<Specimen>. This makes it possible to iterate over all specimens in the block like this:
   for (Specimen c : specimenSequence.getSpecimenSequence())
   {
       process specimen c
   }
 

Returns:
a sequence of all specimens in the specimen sequence.

clearSpecimens

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


size

int size()
Return the number of specimens in the block.

Returns:
the number of specimens in the block.

isEmpty

boolean isEmpty()
Return true if the block contains no specimens.

Returns:
true if the block contains no specimens. false otherwise.

toString

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

Specified by:
toString in class Block
Returns:
the string representation of this SpecimenBlock.