1 package ca.uhn.hl7v2.testpanel.util; 2 3 import java.util.Comparator; 4 5 import org.apache.commons.lang.StringUtils; 6 7 import ca.uhn.hl7v2.HL7Exception; 8 import ca.uhn.hl7v2.model.Message; 9 import ca.uhn.hl7v2.parser.PipeParser; 10 import ca.uhn.hl7v2.util.Terser; 11 12 public class Hl7V2MessageStringComparatorByControlId implements Comparator<String> { 13 private static final PipeParser ourParser = PipeParser.getInstanceWithNoValidation(); 14 15 public int compare(String theS1, String theS2) { 16 17 if (theS1 == null && theS2 == null) { 18 return 0; 19 } 20 if (theS1 == null) { 21 return 1; 22 } 23 if (theS2 == null) { 24 return -1; 25 } 26 27 Message o1; 28 Message o2; 29 try { 30 o1 = ourParser.parse(theS1); 31 o2 = ourParser.parse(theS2); 32 } catch (HL7Exception e) { 33 throw new Error(e); 34 } 35 36 try { 37 String c1 = new Terser(o1).get("/MSH-10"); 38 String c2 = new Terser(o2).get("/MSH-10"); 39 40 c1 = StringUtils.defaultString(c1); 41 c2 = StringUtils.defaultString(c2); 42 43 return c1.compareToIgnoreCase(c2); 44 45 } catch (HL7Exception e) { 46 throw new Error(e); 47 } 48 49 } 50 51 }