Coverage Report - ca.uhn.hl7v2.Location
 
Classes in this File Line Coverage Branch Coverage Complexity
Location
45%
40/88
31%
12/38
2.474
 
 1  
 /**
 2  
 The contents of this file are subject to the Mozilla Public License Version 1.1 
 3  
 (the "License"); you may not use this file except in compliance with the License. 
 4  
 You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
 5  
 Software distributed under the License is distributed on an "AS IS" basis, 
 6  
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
 7  
 specific language governing rights and limitations under the License. 
 8  
 
 9  
 The Original Code is "Location.java".  Description: 
 10  
 "Location of an validated message element" 
 11  
 
 12  
 The Initial Developer of the Original Code is University Health Network. Copyright (C) 
 13  
 2012.  All Rights Reserved. 
 14  
 
 15  
 Contributor(s): ______________________________________. 
 16  
 
 17  
 Alternatively, the contents of this file may be used under the terms of the 
 18  
 GNU General Public License (the "GPL"), in which case the provisions of the GPL are 
 19  
 applicable instead of those above.  If you wish to allow use of your version of this 
 20  
 file only under the terms of the GPL and not to allow others to use your version 
 21  
 of this file under the MPL, indicate your decision by deleting  the provisions above 
 22  
 and replace  them with the notice and other provisions required by the GPL License.  
 23  
 If you do not delete the provisions above, a recipient may use your version of 
 24  
 this file under either the MPL or the GPL. 
 25  
  */
 26  
 package ca.uhn.hl7v2;
 27  
 
 28  
 /**
 29  
  * Location class to determine the location of an element that caused an exception
 30  
  * 
 31  
  * @author Christian Ohr
 32  
  */
 33  
 public class Location {
 34  
 
 35  68
         private String segmentName = null;
 36  68
         private int segmentRepetition = -1;
 37  68
         private int field = -1;
 38  68
         private int fieldRepetition = -1;
 39  68
         private int component = -1;
 40  68
         private int subcomponent = -1;
 41  
 
 42  1
         public static final Location UNKNOWN = new Location();
 43  
 
 44  68
         public Location() {
 45  68
         }
 46  
 
 47  0
         public Location(Location l) {
 48  0
                 this.segmentName = l.segmentName;
 49  0
                 this.segmentRepetition = l.segmentRepetition;
 50  0
                 this.field = l.field;
 51  0
                 this.fieldRepetition = l.fieldRepetition;
 52  0
                 this.component = l.component;
 53  0
                 this.subcomponent = l.subcomponent;
 54  0
         }
 55  
         
 56  
         public boolean isUnknown() {
 57  145
             return this == UNKNOWN;
 58  
         }
 59  
 
 60  
         public String getSegmentName() {
 61  14
                 return segmentName;
 62  
         }
 63  
 
 64  
         public void setSegmentName(String segmentName) {
 65  67
                 this.segmentName = segmentName;
 66  67
         }
 67  
 
 68  
         public int getSegmentRepetition() {
 69  0
                 return segmentRepetition;
 70  
         }
 71  
 
 72  
         public void setSegmentRepetition(int segmentRepetition) {
 73  1
                 this.segmentRepetition = segmentRepetition;
 74  1
         }
 75  
 
 76  
         public int getField() {
 77  14
                 return field;
 78  
         }
 79  
 
 80  
         public void setField(int field) {
 81  64
                 this.field = field;
 82  64
         }
 83  
 
 84  
         public int getFieldRepetition() {
 85  4
                 return fieldRepetition;
 86  
         }
 87  
 
 88  
         public void setFieldRepetition(int fieldRepetition) {
 89  0
                 this.fieldRepetition = fieldRepetition;
 90  0
         }
 91  
 
 92  
         public int getComponent() {
 93  4
                 return component;
 94  
         }
 95  
 
 96  
         public void setComponent(int component) {
 97  0
                 this.component = component;
 98  0
         }
 99  
 
 100  
         public int getSubcomponent() {
 101  4
                 return subcomponent;
 102  
         }
 103  
 
 104  
         public void setSubcomponent(int subcomponent) {
 105  0
                 this.subcomponent = subcomponent;
 106  0
         }
 107  
 
 108  
         /**
 109  
          * Bulk setter for field indices
 110  
          * 
 111  
          * @param indices integer array as returned by Terser#getIndices
 112  
          */
 113  
         public void setFieldIndizes(int[] indices) {
 114  1
                 field = indices[0];
 115  1
                 fieldRepetition = indices[1];
 116  1
                 component = indices[2];
 117  1
                 subcomponent = indices[3];
 118  1
         }
 119  
 
 120  
         @Override
 121  
         public String toString() {
 122  16
                 StringBuilder sb = new StringBuilder();
 123  16
                 if (segmentName != null) {
 124  16
                         sb.append(segmentName);
 125  16
                         if (segmentRepetition >= 0) {
 126  1
                                 sb.append("(").append(segmentRepetition).append(")");
 127  
                         }
 128  16
                         if (field > 0) {
 129  15
                                 sb.append("-").append(field);
 130  15
                                 if (fieldRepetition >= 0) {
 131  1
                                         sb.append("(").append(fieldRepetition).append(")");
 132  
                                 }
 133  15
                                 if (component > 0) {
 134  1
                                         sb.append("-").append(component);
 135  1
                                         if (subcomponent > 0) {
 136  1
                                                 sb.append("-").append(subcomponent);
 137  
                                         }
 138  
                                 }
 139  
                         }
 140  
                 } else {
 141  0
                         sb.append("unknown location");
 142  
                 }
 143  16
                 return sb.toString();
 144  
         }
 145  
 
 146  
         @Override
 147  
         public int hashCode() {
 148  0
                 final int prime = 31;
 149  0
                 int result = 1;
 150  0
                 result = prime * result + component;
 151  0
                 result = prime * result + field;
 152  0
                 result = prime * result + fieldRepetition;
 153  0
                 result = prime * result + ((segmentName == null) ? 0 : segmentName.hashCode());
 154  0
                 result = prime * result + segmentRepetition;
 155  0
                 result = prime * result + subcomponent;
 156  0
                 return result;
 157  
         }
 158  
 
 159  
         @Override
 160  
         public boolean equals(Object obj) {
 161  0
                 if (this == obj)
 162  0
                         return true;
 163  0
                 if (obj == null)
 164  0
                         return false;
 165  0
                 if (getClass() != obj.getClass())
 166  0
                         return false;
 167  0
                 Location other = (Location) obj;
 168  0
                 if (component != other.component)
 169  0
                         return false;
 170  0
                 if (field != other.field)
 171  0
                         return false;
 172  0
                 if (fieldRepetition != other.fieldRepetition)
 173  0
                         return false;
 174  0
                 if (segmentName == null) {
 175  0
                         if (other.segmentName != null)
 176  0
                                 return false;
 177  0
                 } else if (!segmentName.equals(other.segmentName))
 178  0
                         return false;
 179  0
                 if (segmentRepetition != other.segmentRepetition)
 180  0
                         return false;
 181  0
                 if (subcomponent != other.subcomponent)
 182  0
                         return false;
 183  0
                 return true;
 184  
         }
 185  
 
 186  
 }