Coverage Report - ca.uhn.hl7v2.model.AbstractComposite
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractComposite
73%
11/15
66%
4/6
2.75
 
 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 "AbstractComposite.java".  Description: 
 10  
 "A partial implementation of Composite" 
 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.model;
 27  
 
 28  
 import org.slf4j.Logger;
 29  
 import org.slf4j.LoggerFactory;
 30  
 
 31  
 import ca.uhn.hl7v2.HL7Exception;
 32  
 
 33  
 /**
 34  
  * @author i000161
 35  
  *
 36  
  */
 37  
 public abstract class AbstractComposite extends AbstractType implements
 38  
                 Composite {
 39  
 
 40  
         private static final long serialVersionUID = -2657103285266475699L;
 41  
         
 42  
         protected Logger log;
 43  
         
 44  
         public AbstractComposite(Message message) {
 45  23230
                 super(message);
 46  23230
                 log = LoggerFactory.getLogger(getClass());
 47  23230
         }
 48  
 
 49  
         @Override
 50  
         public void clear() {
 51  27
                 super.clear();
 52  130
                 for (Type component : getComponents()) {
 53  103
                         component.clear();
 54  
                 }
 55  27
         }
 56  
         
 57  
         protected <T extends Type> T getTyped(int idx, Class<T> type) {
 58  
                 try {
 59  198
                         @SuppressWarnings("unchecked") T ret = (T)getComponent(idx);
 60  198
                         return ret;
 61  0
                 } catch (HL7Exception e) {
 62  0
                  log.error("Unexpected problem accessing known data type component - this is a bug.", e);
 63  0
                  throw new RuntimeException(e);
 64  
                 }
 65  
         }
 66  
 
 67  
         @Override
 68  
         public boolean isEmpty() {
 69  218
                 for (Type type : getComponents()) {
 70  218
                         if (!type.isEmpty()) return false;
 71  
                 }
 72  0
                 return super.isEmpty(); // for the ExtraComponents
 73  
         }
 74  
         
 75  
         
 76  
 
 77  
 }