com.pixelmed.scpecg
Class Section

java.lang.Object
  extended by com.pixelmed.scpecg.Section
Direct Known Subclasses:
Section0, Section1, Section10, Section2, Section3, Section4, Section5Or6, Section7, Section8Or11

public class Section
extends Object

A class to encapsulate an SCP-ECG section.

Though not abstract, in order to support unrecognized sections, this class is usually extended by more specific classes; there is a factory method makeSection that is used to create specific sub-classes once the section number is known (i.e. has been read).


Field Summary
protected  long bytesRead
           
protected  SectionHeader header
           
protected  long sectionBytesRemaining
           
protected  SCPTreeRecord tree
           
 
Constructor Summary
Section(SectionHeader header)
          Construct an empty section with the specified header.
 
Method Summary
protected static void addNodeOfDecimalAndHex(SCPTreeRecord parent, String name, int value)
          Add a tree node with a numeric value as decimal and hexadecimal strings.
protected static void addNodeOfDecimalWithMissingValues(SCPTreeRecord parent, String name, int value)
          Add a tree node with a numeric value as decimal string, with potentially missing values.
protected  void addSectionHeaderToTree(SCPTreeRecord parent)
          Get section header information to the section node in a tree for display.
static String describeMissingValues(int i)
          Get a description of measurement values that may have missing values.
 SectionHeader getSectionHeader()
           
 String getSectionName()
          Get a string name for this section.
 SCPTreeRecord getTree()
          Get the contents of the section as a tree for display.
 SCPTreeRecord getTree(SCPTreeRecord parent)
          Get the contents of the section as a tree for display, constructing it if not already done.
protected  String getValueForSectionNodeInTree()
          Get the value to use as the value section of the section node in a tree for display.
static Section makeSection(SectionHeader sectionHeader, TreeMap sections)
          A factory method to construct specific sub-classes of section.
static String makeStringFromByteArrayRemovingAnyNulls(byte[] bytes)
          Convert an array of bytes to a String removing any embedded nulls.
 long read(BinaryInputStream i)
          Read the remainder of the section from a stream.
protected  long skipToEndOfSectionIfNotAlreadyThere(BinaryInputStream i)
          Skip to the end of the section, if not already there.
 String toString()
          Dump the section as a String.
 String validate()
          Validate the section against the standard.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

header

protected SectionHeader header

bytesRead

protected long bytesRead

sectionBytesRemaining

protected long sectionBytesRemaining

tree

protected SCPTreeRecord tree
Constructor Detail

Section

public Section(SectionHeader header)

Construct an empty section with the specified header.

Parameters:
header - the header (which has already been read)
Method Detail

getSectionHeader

public SectionHeader getSectionHeader()

read

public long read(BinaryInputStream i)
          throws IOException

Read the remainder of the section from a stream.

Parameters:
i - the input stream
Returns:
the number of bytes read
Throws:
IOException

skipToEndOfSectionIfNotAlreadyThere

protected long skipToEndOfSectionIfNotAlreadyThere(BinaryInputStream i)
                                            throws IOException

Skip to the end of the section, if not already there.

Used either for unrecognized sections, or when there is an encoding error within a section and parsing of the section has to be abandoned.

Parameters:
i - the input stream
Returns:
the number of bytes skipped
Throws:
IOException

toString

public String toString()

Dump the section as a String.

Overrides:
toString in class Object
Returns:
the section as a String

validate

public String validate()

Validate the section against the standard.

Returns:
the validation results as a String

getSectionName

public String getSectionName()

Get a string name for this section.

Returns:
a string name for this section

makeSection

public static Section makeSection(SectionHeader sectionHeader,
                                  TreeMap sections)

A factory method to construct specific sub-classes of section.

Parameters:
sectionHeader - the section header already read from the stream, containing the section number
sections - the sections that have already been read, in case values are needed for making new sections
Returns:
a section of the appropriate sub-class.

getValueForSectionNodeInTree

protected String getValueForSectionNodeInTree()

Get the value to use as the value section of the section node in a tree for display.

Returns:
the value of just this node (not its contents)

addSectionHeaderToTree

protected void addSectionHeaderToTree(SCPTreeRecord parent)

Get section header information to the section node in a tree for display.


getTree

public SCPTreeRecord getTree()

Get the contents of the section as a tree for display.

Returns:
the section as a tree, or null if not constructed

getTree

public SCPTreeRecord getTree(SCPTreeRecord parent)

Get the contents of the section as a tree for display, constructing it if not already done.

Parameters:
parent - the node to which this section is to be added if it needs to be created de novo
Returns:
the section as a tree

describeMissingValues

public static String describeMissingValues(int i)

Get a description of measurement values that may have missing values.

Described in Section 5.10.2 as being defined in the CSE Project.

Parameters:
i - the numeric value that may be missing
Returns:
a description of the type of missing value

addNodeOfDecimalAndHex

protected static void addNodeOfDecimalAndHex(SCPTreeRecord parent,
                                             String name,
                                             int value)

Add a tree node with a numeric value as decimal and hexadecimal strings.

Parameters:
parent - the node to which to add this new node as a child
name - the name of the new node
value - the numeric value of the new node

addNodeOfDecimalWithMissingValues

protected static void addNodeOfDecimalWithMissingValues(SCPTreeRecord parent,
                                                        String name,
                                                        int value)

Add a tree node with a numeric value as decimal string, with potentially missing values.

Parameters:
parent - the node to which to add this new node as a child
name - the name of the new node
value - the numeric value of the new node

makeStringFromByteArrayRemovingAnyNulls

public static String makeStringFromByteArrayRemovingAnyNulls(byte[] bytes)

Convert an array of bytes to a String removing any embedded nulls.

Nulls may be embedded, and are simply ignored; they do not terminate the string.

The default character encoding is used; ISO 2022 escapes are not yet supported.

Parameters:
bytes - the array of bytes, possibly with embedded nulls
Returns:
the String value