| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
package ca.uhn.hl7v2.parser; |
| 28 | |
|
| 29 | |
import ca.uhn.hl7v2.HL7Exception; |
| 30 | |
import ca.uhn.hl7v2.model.Message; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public class EncodingCharacters implements Cloneable { |
| 40 | |
|
| 41 | |
private char fieldSep; |
| 42 | |
private char[] encChars; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | 27586 | public EncodingCharacters(char fieldSeparator, String encodingCharacters) { |
| 58 | 27586 | this.fieldSep = fieldSeparator; |
| 59 | 27586 | this.encChars = new char[5]; |
| 60 | |
|
| 61 | 27586 | if (encodingCharacters == null) { |
| 62 | 95 | setComponentSeparator('^'); |
| 63 | 95 | setRepetitionSeparator('~'); |
| 64 | 95 | setEscapeCharacter('\\'); |
| 65 | 95 | setSubcomponentSeparator('&'); |
| 66 | 95 | setTruncationCharacter('#'); |
| 67 | |
} else { |
| 68 | 27491 | encodingCharacters.getChars(0, 4, this.encChars, 0); |
| 69 | |
|
| 70 | 27491 | if (encodingCharacters.length() > 4) { |
| 71 | 14890 | char extraChar = encodingCharacters.charAt(4); |
| 72 | 14890 | if (extraChar != fieldSeparator) { |
| 73 | 215 | setTruncationCharacter(extraChar); |
| 74 | |
} |
| 75 | |
} |
| 76 | |
} |
| 77 | |
|
| 78 | 27586 | } |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public static EncodingCharacters getInstance(Message message) throws HL7Exception { |
| 89 | |
|
| 90 | 9805 | final String encodingCharactersValue = message.getEncodingCharactersValue(); |
| 91 | 9805 | if (encodingCharactersValue == null || encodingCharactersValue.length() == 0) { |
| 92 | 5 | throw new HL7Exception("encoding characters not populated"); |
| 93 | |
} |
| 94 | |
|
| 95 | 9800 | final Character fieldSeparatorValue = message.getFieldSeparatorValue(); |
| 96 | 9800 | if (fieldSeparatorValue == null) { |
| 97 | 0 | throw new HL7Exception("Field separator not populated"); |
| 98 | |
} |
| 99 | |
|
| 100 | 9800 | return new EncodingCharacters(fieldSeparatorValue, encodingCharactersValue); |
| 101 | |
} |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
public EncodingCharacters(char fieldSeparator, char componentSeparator, char repetitionSeparator, |
| 106 | |
char escapeCharacter, char subcomponentSeparator) { |
| 107 | 0 | this(fieldSeparator, String.valueOf(componentSeparator) + repetitionSeparator + |
| 108 | |
escapeCharacter + subcomponentSeparator); |
| 109 | 0 | } |
| 110 | |
|
| 111 | |
public EncodingCharacters(char fieldSeparator, char componentSeparator, char repetitionSeparator, |
| 112 | |
char escapeCharacter, char subcomponentSeparator, char truncationCharacter) { |
| 113 | 0 | this(fieldSeparator, String.valueOf(componentSeparator) + repetitionSeparator + |
| 114 | |
escapeCharacter + subcomponentSeparator + truncationCharacter); |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | 0 | public EncodingCharacters(EncodingCharacters other) { |
| 120 | 0 | this.fieldSep = other.getFieldSeparator(); |
| 121 | 0 | this.encChars = new char[5]; |
| 122 | 0 | setComponentSeparator(other.getComponentSeparator()); |
| 123 | 0 | setRepetitionSeparator(other.getRepetitionSeparator()); |
| 124 | 0 | setEscapeCharacter(other.getEscapeCharacter()); |
| 125 | 0 | setSubcomponentSeparator(other.getSubcomponentSeparator()); |
| 126 | 0 | setTruncationCharacter(other.getTruncationCharacter()); |
| 127 | 0 | } |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
public char getFieldSeparator() { |
| 135 | 544602 | return this.fieldSep; |
| 136 | |
} |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
public char getComponentSeparator() { |
| 144 | 467430 | return this.encChars[0]; |
| 145 | |
} |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public char getRepetitionSeparator() { |
| 153 | 350215 | return this.encChars[1]; |
| 154 | |
} |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
public char getEscapeCharacter() { |
| 162 | 287360 | return this.encChars[2]; |
| 163 | |
} |
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
public char getSubcomponentSeparator() { |
| 171 | 726147 | return this.encChars[3]; |
| 172 | |
} |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
public char getTruncationCharacter() { |
| 180 | 174716 | return this.encChars[4]; |
| 181 | |
} |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
public String toString() { |
| 188 | 385 | return String.valueOf(encChars); |
| 189 | |
} |
| 190 | |
|
| 191 | |
public Object clone() throws CloneNotSupportedException |
| 192 | |
{ |
| 193 | 0 | super.clone(); |
| 194 | 0 | return new EncodingCharacters(this); |
| 195 | |
} |
| 196 | |
|
| 197 | |
public void setFieldSeparator(char newFieldSep) { |
| 198 | 385 | this.fieldSep = newFieldSep; |
| 199 | 385 | } |
| 200 | |
|
| 201 | |
public void setComponentSeparator(char newComponentSep) { |
| 202 | 480 | this.encChars[0] = newComponentSep; |
| 203 | 480 | } |
| 204 | |
|
| 205 | |
public void setRepetitionSeparator(char newRepetitionSep) { |
| 206 | 480 | this.encChars[1] = newRepetitionSep; |
| 207 | 480 | } |
| 208 | |
|
| 209 | |
public void setEscapeCharacter(char newEscapeChar) { |
| 210 | 480 | this.encChars[2] = newEscapeChar; |
| 211 | 480 | } |
| 212 | |
|
| 213 | |
public void setSubcomponentSeparator(char newSubcomponentSep) { |
| 214 | 480 | this.encChars[3] = newSubcomponentSep; |
| 215 | 480 | } |
| 216 | |
|
| 217 | |
public void setTruncationCharacter(char newTruncationChar) { |
| 218 | 310 | this.encChars[4] = newTruncationChar; |
| 219 | 310 | } |
| 220 | |
|
| 221 | |
|
| 222 | |
public boolean equals(Object o) { |
| 223 | 62527 | if (o instanceof EncodingCharacters) { |
| 224 | 62527 | EncodingCharacters other = (EncodingCharacters) o; |
| 225 | 125054 | return (this.getFieldSeparator() == other.getFieldSeparator() |
| 226 | 62527 | && this.getComponentSeparator() == other.getComponentSeparator() |
| 227 | 62527 | && this.getEscapeCharacter() == other.getEscapeCharacter() |
| 228 | 62527 | && this.getRepetitionSeparator() == other.getRepetitionSeparator() |
| 229 | 62527 | && this.getSubcomponentSeparator() == other.getSubcomponentSeparator() |
| 230 | 58042 | && this.getTruncationCharacter() == other.getTruncationCharacter()); |
| 231 | |
} else { |
| 232 | 0 | return false; |
| 233 | |
} |
| 234 | |
} |
| 235 | |
|
| 236 | |
|
| 237 | |
public int hashCode() { |
| 238 | 117234 | return 7 * (int) this.getComponentSeparator() |
| 239 | 58617 | * (int) this.getEscapeCharacter() |
| 240 | 58617 | * (int) this.getFieldSeparator() |
| 241 | 58617 | * (int) this.getRepetitionSeparator() |
| 242 | 58617 | * (int) this.getSubcomponentSeparator() |
| 243 | 58617 | * (int) this.getTruncationCharacter(); |
| 244 | |
} |
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
public static EncodingCharacters defaultInstance() { |
| 253 | 5 | return new EncodingCharacters('|', null); |
| 254 | |
} |
| 255 | |
|
| 256 | |
} |
| 257 | |
|