Coverage Report - ca.uhn.hl7v2.model.ExtraComponents
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtraComponents
92%
12/13
100%
2/2
1.167
 
 1  
 package ca.uhn.hl7v2.model;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.util.ArrayList;
 5  
 import java.util.List;
 6  
 
 7  
 /**
 8  
  * A set of "extra" components (sub-components) that are not a standard part 
 9  
  * of a field (component) but have been added at runtime.  The purpose is to allow 
 10  
  * processing of locally-defined extensions to datatypes without the need for a 
 11  
  * custom message definition.  
 12  
  * Extra components are not treated uniformly with standard components (e.g. 
 13  
  * they are not accessible through methods like Primitive.getValue() and 
 14  
  * Composite.getComponent()).  To do so would blur the distinction between 
 15  
  * primitive and composite types (i.e. leaf and non-leaf nodes), which seems 
 16  
  * nice and polymorphic for a moment but actually isn't helpful.  
 17  
  * Furthermore, the auto-generated classes do not define accessors to extra 
 18  
  * components, because they are meant to encourage and enforce use of the standard 
 19  
  * message structure -- stepping outside the standard structure must be 
 20  
  * deliberate. 
 21  
  * Note that a uniformity of access to standard and extra components is provided
 22  
  * by Terser.   
 23  
  * @author Bryan Tripp
 24  
  */
 25  
 public class ExtraComponents implements Serializable {
 26  
     
 27  
 
 28  
         private static final long serialVersionUID = -2614683870975956395L;
 29  
     
 30  
     private List<Varies> comps;
 31  
     private Message message;
 32  
 
 33  126748
     public ExtraComponents(Message message) {
 34  126748
         this.comps = new ArrayList<Varies>();
 35  126748
         this.message = message; 
 36  126748
     }
 37  
     
 38  
     /** Returns the number of existing extra components
 39  
      *
 40  
      * @return number of existing extra components
 41  
      */
 42  
     public int numComponents() {
 43  91494
         return comps.size();
 44  
     }
 45  
     
 46  
     /** Returns the number of existing reps of a given extra component */
 47  
     /*public int numReps(int comp) {
 48  
         return ((ArrayList) this.comps.get(comp)).size();
 49  
     }*/
 50  
     
 51  
     /** 
 52  
      * Returns the component at the given location, creating it 
 53  
      * and all preceeding components if necessary.
 54  
      *
 55  
      * @param comp the extra component number starting at 0 (i.e. 0 is the first 
 56  
      *      extra component)
 57  
      * @return component at the given index
 58  
      */
 59  
     public Varies getComponent(int comp) {
 60  329
         ensureComponentAndPredecessorsExist(comp);
 61  329
         return this.comps.get(comp);
 62  
     }
 63  
     
 64  
     /**
 65  
      * Checks that the component at the given location exists, and that 
 66  
      * all preceding components exist, creating any missing ones.  
 67  
      */
 68  
     private void ensureComponentAndPredecessorsExist(int comp) {
 69  460
         for (int i = this.comps.size(); i <= comp; i++) {
 70  131
             this.comps.add(new Varies(message));
 71  
         }
 72  
         /*ArrayList reps = (ArrayList) this.comps.get(comp);
 73  
         for (int j = reps.size(); j <= rep; j++) {
 74  
             addRep(comp, j);
 75  
         }*/
 76  329
     }
 77  
 
 78  
 
 79  
         /**
 80  
          * Clears all extra components
 81  
          */
 82  
         void clear() {
 83  154
                 comps.clear();
 84  154
         }
 85  
 
 86  
     /**
 87  
      * {@inheritDoc}
 88  
          */
 89  
         @Override
 90  
         public String toString() {
 91  0
                 return "ExtraComponents" + comps;
 92  
         }
 93  
         
 94  
 
 95  
     /*private void addComp(int comp) {
 96  
     }*/
 97  
     
 98  
     /*private void addRep(int comp, int rep) {
 99  
         ArrayList l = (ArrayList) this.comps.get(comp);
 100  
         l.add(rep, new Varies());
 101  
     }*/
 102  
 }