public class Section
extends java.lang.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).
Modifier and Type | Field and Description |
---|---|
protected long |
bytesRead |
protected SectionHeader |
header |
protected long |
sectionBytesRemaining |
protected SCPTreeRecord |
tree |
Constructor and Description |
---|
Section(SectionHeader header)
Construct an empty section with the specified header.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
addNodeOfDecimalAndHex(SCPTreeRecord parent,
java.lang.String name,
int value)
Add a tree node with a numeric value as decimal and hexadecimal strings.
|
protected static void |
addNodeOfDecimalWithMissingValues(SCPTreeRecord parent,
java.lang.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 java.lang.String |
describeMissingValues(int i)
Get a description of measurement values that may have missing values.
|
SectionHeader |
getSectionHeader() |
java.lang.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 java.lang.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,
java.util.TreeMap sections)
A factory method to construct specific sub-classes of section.
|
static java.lang.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.
|
java.lang.String |
toString()
Dump the section as a
String . |
java.lang.String |
validate()
Validate the section against the standard.
|
protected long bytesRead
protected SectionHeader header
protected long sectionBytesRemaining
protected SCPTreeRecord tree
public Section(SectionHeader header)
Construct an empty section with the specified header.
header
- the header (which has already been read)protected static void addNodeOfDecimalAndHex(SCPTreeRecord parent, java.lang.String name, int value)
Add a tree node with a numeric value as decimal and hexadecimal strings.
parent
- the node to which to add this new node as a childname
- the name of the new nodevalue
- the numeric value of the new nodeprotected static void addNodeOfDecimalWithMissingValues(SCPTreeRecord parent, java.lang.String name, int value)
Add a tree node with a numeric value as decimal string, with potentially missing values.
parent
- the node to which to add this new node as a childname
- the name of the new nodevalue
- the numeric value of the new nodeprotected void addSectionHeaderToTree(SCPTreeRecord parent)
Get section header information to the section node in a tree for display.
public static java.lang.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.
i
- the numeric value that may be missingpublic SectionHeader getSectionHeader()
public java.lang.String getSectionName()
Get a string name for this section.
public SCPTreeRecord getTree()
Get the contents of the section as a tree for display.
public SCPTreeRecord getTree(SCPTreeRecord parent)
Get the contents of the section as a tree for display, constructing it if not already done.
parent
- the node to which this section is to be added if it needs to be created de novoprotected java.lang.String getValueForSectionNodeInTree()
Get the value to use as the value section of the section node in a tree for display.
public static Section makeSection(SectionHeader sectionHeader, java.util.TreeMap sections)
A factory method to construct specific sub-classes of section.
sectionHeader
- the section header already read from the stream, containing the section numbersections
- the sections that have already been read, in case values are needed for making new sectionspublic static java.lang.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.
bytes
- the array of bytes, possibly with embedded nullsString
valuepublic long read(BinaryInputStream i) throws java.io.IOException
Read the remainder of the section from a stream.
i
- the input streamjava.io.IOException
protected long skipToEndOfSectionIfNotAlreadyThere(BinaryInputStream i) throws java.io.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.
i
- the input streamjava.io.IOException
public java.lang.String toString()
Dump the section as a String
.
toString
in class java.lang.Object
String
public java.lang.String validate()
Validate the section against the standard.
String