Class HL7Seps
- java.lang.Object
-
- org.dellroad.hl7.HL7Seps
-
- All Implemented Interfaces:
Serializable
public final class HL7Seps extends Object implements Serializable
Container for the HL7 separator and escape characters for an HL7 message.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static charCOMPONENT_SEPARATOR_ESCAPEstatic HL7SepsDEFAULTSeparator using the default HL7 separator and escape characters.static charDEFAULT_COMPONENT_SEPARATORstatic charDEFAULT_ESCAPE_CHARACTERstatic charDEFAULT_FIELD_SEPARATORstatic charDEFAULT_REPEAT_SEPARATORstatic charDEFAULT_SUBCOMPONENT_SEPARATORstatic charESCAPE_CHARACTER_ESCAPEstatic charFIELD_SEPARATOR_ESCAPEstatic charHEX_DATA_ESCAPEstatic charREPEAT_SEPARATOR_ESCAPEstatic charSUBCOMPONENT_SEPARATOR_ESCAPE
-
Constructor Summary
Constructors Constructor Description HL7Seps(char fieldSep, char compSep, char repSep)Convenience constructor for when there is no sub-component separator and no escape character.HL7Seps(char fieldSep, char compSep, char repSep, char escChar)Convenience constructor for when there is no sub-component separator.HL7Seps(char fieldSep, char compSep, char repSep, char escChar, char subSep)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Stringescape(String value)Escape instances of any separator or escape character within the given string.voidescape(String value, StringBuilder buf)Escape instances of any separator or escape character within the given string, and add the result to the given buffer.chargetCompSep()Get the component separator character.chargetEscChar()Get the escape character.chargetFieldSep()Get the field separator character.chargetRepSep()Get the repeat separator character.chargetSubSep()Get the sub-component separator character.booleanhasEscapeCharacter()Determine if there is an escape character defined.inthashCode()booleanhasSubcomponentSeparator()Determine if there is a sub-component character defined.StringtoString()Returns string representation as well-formed MSH.1 and MSH.2 fields.Stringunescape(String value)Parse the escaped string back into its unescaped form.static voidvalidate(char fieldSep, char compSep, char repSep, char escChar, char subSep)Verify that the given combination of separator and escape characters is valid.
-
-
-
Field Detail
-
DEFAULT_FIELD_SEPARATOR
public static final char DEFAULT_FIELD_SEPARATOR
- See Also:
- Constant Field Values
-
DEFAULT_COMPONENT_SEPARATOR
public static final char DEFAULT_COMPONENT_SEPARATOR
- See Also:
- Constant Field Values
-
DEFAULT_REPEAT_SEPARATOR
public static final char DEFAULT_REPEAT_SEPARATOR
- See Also:
- Constant Field Values
-
DEFAULT_SUBCOMPONENT_SEPARATOR
public static final char DEFAULT_SUBCOMPONENT_SEPARATOR
- See Also:
- Constant Field Values
-
DEFAULT_ESCAPE_CHARACTER
public static final char DEFAULT_ESCAPE_CHARACTER
- See Also:
- Constant Field Values
-
FIELD_SEPARATOR_ESCAPE
public static final char FIELD_SEPARATOR_ESCAPE
- See Also:
- Constant Field Values
-
COMPONENT_SEPARATOR_ESCAPE
public static final char COMPONENT_SEPARATOR_ESCAPE
- See Also:
- Constant Field Values
-
REPEAT_SEPARATOR_ESCAPE
public static final char REPEAT_SEPARATOR_ESCAPE
- See Also:
- Constant Field Values
-
ESCAPE_CHARACTER_ESCAPE
public static final char ESCAPE_CHARACTER_ESCAPE
- See Also:
- Constant Field Values
-
SUBCOMPONENT_SEPARATOR_ESCAPE
public static final char SUBCOMPONENT_SEPARATOR_ESCAPE
- See Also:
- Constant Field Values
-
HEX_DATA_ESCAPE
public static final char HEX_DATA_ESCAPE
- See Also:
- Constant Field Values
-
DEFAULT
public static final HL7Seps DEFAULT
Separator using the default HL7 separator and escape characters.
-
-
Constructor Detail
-
HL7Seps
public HL7Seps(char fieldSep, char compSep, char repSep, char escChar, char subSep) throws HL7ContentExceptionConstructor.The sub-component separator and escape characters are optional and may be equal to
(char)0to indicate not defined. However, if a sub-component separator is defined, then so must be an escape character.- Parameters:
fieldSep- field separatorcompSep- component separatorrepSep- repetition separatorescChar- escape character, or(char)0for nonesubSep- subcomponent separator, or(char)0for none- Throws:
HL7ContentException- if the characters are invalid according tovalidate(char, char, char, char, char)
-
HL7Seps
public HL7Seps(char fieldSep, char compSep, char repSep, char escChar) throws HL7ContentExceptionConvenience constructor for when there is no sub-component separator. Equivalent to:HL7Seps(fieldSep, compSep, repSep, escChar, (char)0)- Parameters:
fieldSep- field separatorcompSep- component separatorrepSep- repetition separatorescChar- escape character, or(char)0for none- Throws:
HL7ContentException- if the characters are invalid according tovalidate(char, char, char, char, char)
-
HL7Seps
public HL7Seps(char fieldSep, char compSep, char repSep) throws HL7ContentExceptionConvenience constructor for when there is no sub-component separator and no escape character. Equivalent to:HL7Seps(fieldSep, compSep, repSep, (char)0, (char)0)- Parameters:
fieldSep- field separatorcompSep- component separatorrepSep- repetition separator- Throws:
HL7ContentException- if the characters are invalid according tovalidate(char, char, char, char, char)
-
-
Method Detail
-
getFieldSep
public char getFieldSep()
Get the field separator character.- Returns:
- field separator character
-
getCompSep
public char getCompSep()
Get the component separator character.- Returns:
- component separator character
-
getRepSep
public char getRepSep()
Get the repeat separator character.- Returns:
- repeat separator character
-
getEscChar
public char getEscChar()
Get the escape character.- Returns:
- escape character, or
(char)0for none - See Also:
hasEscapeCharacter()
-
getSubSep
public char getSubSep()
Get the sub-component separator character.- Returns:
- sub-component separator character, or
(char)0for none - See Also:
hasSubcomponentSeparator()
-
escape
public String escape(String value)
Escape instances of any separator or escape character within the given string.If some character needs to be escaped but there is no escape character defined, the character is silently elided.
- Parameters:
value- the String to escape- Returns:
- the escaped string
-
escape
public void escape(String value, StringBuilder buf)
Escape instances of any separator or escape character within the given string, and add the result to the given buffer.If some character needs to be escaped but there is no escape character defined, the character is silently elided.
- Parameters:
value- the String to escapebuf- buffer to append to
-
hasSubcomponentSeparator
public boolean hasSubcomponentSeparator()
Determine if there is a sub-component character defined.- Returns:
- true if a sub-component character is defined
-
hasEscapeCharacter
public boolean hasEscapeCharacter()
Determine if there is an escape character defined.- Returns:
- true if an escape character is defined
-
unescape
public String unescape(String value)
Parse the escaped string back into its unescaped form.The string must have been previously escaped using the same escape character as is defined for this instance.
If no escape character is defined for this instance, the unaltered value is returned.
Any "custom" or invalid escapes are silently removed.
An unclosed escape is returned unaltered.
- Parameters:
value- escaped string value- Returns:
- original unescaped value
-
toString
public String toString()
Returns string representation as well-formed MSH.1 and MSH.2 fields.
-
validate
public static void validate(char fieldSep, char compSep, char repSep, char escChar, char subSep) throws HL7ContentExceptionVerify that the given combination of separator and escape characters is valid.This method performs the following checks:
- All defined characters are plain ASCII.
- All defined characters are unique.
- If a sub-component separator is defined, then so is an escape character.
- Parameters:
fieldSep- field separatorcompSep- component separatorrepSep- repetition separatorescChar- escape character, or(char)0for nonesubSep- subcomponent separator, or(char)0for none- Throws:
HL7ContentException- if the characters are invalid
-
-