Coverage Report - ca.uhn.hl7v2.hoh.api.AbstractReceivable
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractReceivable
83%
10/12
50%
4/8
4
 
 1  
 package ca.uhn.hl7v2.hoh.api;
 2  
 
 3  
 import java.util.Collections;
 4  
 import java.util.HashMap;
 5  
 import java.util.Map;
 6  
 
 7  180
 public abstract class AbstractReceivable<T> implements IReceivable<T> {
 8  180
         private final Map<String, Object> myMetadata = new HashMap<String, Object>();
 9  
 
 10  
         /**
 11  
          * Add a metadata value
 12  
          * 
 13  
          * @param theKey The key
 14  
          * @param theValue The value
 15  
          * @throws NullPointerException If theKey is null
 16  
          */
 17  
         public void addMetadata(String theKey, Object theValue) {
 18  160
                 if (theKey == null) {
 19  0
                         throw new NullPointerException("Key may not be null");
 20  
                 }
 21  
                 
 22  160
                 if (theValue != null) {
 23  160
                         if (MessageMetadataKeys.keyStringSet().contains(theKey)) {
 24  160
                                 Class<?> valueType = MessageMetadataKeys.valueOf(theKey).getValueType();
 25  160
                                 if (!valueType.isAssignableFrom(theValue.getClass())) {
 26  0
                                         throw new IllegalArgumentException("Value for key \"" + theKey + "\" must be of type: " + valueType.getName());
 27  
                                 }
 28  
                         }
 29  
                 }
 30  
                 
 31  160
                 myMetadata.put(theKey, theValue);
 32  160
         }
 33  
         
 34  
         /**
 35  
          * {@inheritDoc}
 36  
          */
 37  
         public Map<String, Object> getMetadata() {
 38  20
                 return Collections.unmodifiableMap(myMetadata);
 39  
         }
 40  
 
 41  
 
 42  
 }