Class HL7Field
- java.lang.Object
-
- org.dellroad.hl7.HL7Field
-
- All Implemented Interfaces:
Serializable
public final class HL7Field extends Object implements Serializable
Represents one field in an HL7 message, possibly with repeats.Instances of this class are "immutable"; however, for this to be true the calling application must not alter the arrays passed to the constructor or returned from any of the methods.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description HL7Field(String value)
Constructor.HL7Field(String[] repeats)
Constructor used to create a field containing zero or more repeated values, each a simple string value.HL7Field(String[][][] repeats)
Constructor used to create a field containing zero or more repeated values, each containing zero or more components, each component containing zero or more sub-components.HL7Field(String field, HL7Seps seps)
Parsing constructor.HL7Field(HL7Field field)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(StringBuilder buf, HL7Seps seps)
Append properly separated and escaped version of this field to the given buffer.boolean
equals(Object obj)
String
get(int repnum, int compnum, int subnum)
Get a specific field sub-component.String[][][]
getValue()
Get field contents.int
hashCode()
boolean
isEmpty()
String
toString()
Convert to a string usingHL7Seps.DEFAULT
.String
toString(HL7Seps seps)
Convert to a string using the provided separators.
-
-
-
Constructor Detail
-
HL7Field
public HL7Field(String value)
Constructor.- Parameters:
value
- simple string value for this field; null is treated like the empty string
-
HL7Field
public HL7Field(String[] repeats)
Constructor used to create a field containing zero or more repeated values, each a simple string value.Note: the
repeats
array is not copied by this constructor, so the caller should not modify the array.- Parameters:
repeats
- repeat values for this field; null is treated like the empty string- Throws:
IllegalArgumentException
- ifrepeats
array has length zero
-
HL7Field
public HL7Field(String[][][] repeats)
Constructor used to create a field containing zero or more repeated values, each containing zero or more components, each component containing zero or more sub-components.Note: the
repeats
array is not copied by this constructor, so the caller should not modify the array.- Parameters:
repeats
- repeat array, each containing a component array, each containing a sub-component array; null in any String position is treated like the empty string- Throws:
NullPointerException
- if any intermediate array element (i.e., not of type String) is nullIllegalArgumentException
- ifrepeats
array or any sub-array has length zero
-
HL7Field
public HL7Field(String field, HL7Seps seps)
Parsing constructor.Parses the encoded HL7 field. Non-custom escapes will be decoded, while custom escapes will be silently removed.
- Parameters:
field
- encoded HL7 field contentsseps
- HL7 separator characters
-
HL7Field
public HL7Field(HL7Field field)
Copy constructor.This constructor performs a deep copy of
field
, so that subsequent changes to it do not affect this instance.- Parameters:
field
- field to copy
-
-
Method Detail
-
getValue
public String[][][] getValue()
Get field contents.The length of the returned array, each of its array elements, and each of their sub-array elements, is guaranteed to be at least one.
Note: the returned array is not a copy, so the caller should not modify it.
- Returns:
- array of repeats, each an array of components, each an array of sub-components, each a non-null String.
-
isEmpty
public boolean isEmpty()
-
get
public String get(int repnum, int compnum, int subnum)
Get a specific field sub-component.- Parameters:
repnum
- repeat number (zero-based)compnum
- component number (zero-based)subnum
- sub-component number (zero-based)- Returns:
- specified sub-component, or null if it does not exist
- Throws:
IllegalArgumentException
- if any parameter is negative
-
append
public void append(StringBuilder buf, HL7Seps seps)
Append properly separated and escaped version of this field to the given buffer.- Parameters:
buf
- string bufferseps
- HL7 separator and escape characters
-
toString
public String toString(HL7Seps seps)
Convert to a string using the provided separators.- Parameters:
seps
- HL7 separator and escape characters- Returns:
- this field properly separated and escaped with
seps
-
toString
public String toString()
Convert to a string usingHL7Seps.DEFAULT
.
-
-