Coverage Report - org.mule.config.spring.parsers.assembly.MapEntryCombiner
 
Classes in this File Line Coverage Branch Coverage Complexity
MapEntryCombiner
0%
0/34
0%
0/4
1.167
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.config.spring.parsers.assembly;
 8  
 
 9  
 import java.util.Collection;
 10  
 import java.util.HashMap;
 11  
 import java.util.Map;
 12  
 import java.util.Set;
 13  
 
 14  
 /**
 15  
  * This is used internally by {@link org.mule.config.spring.parsers.assembly.DefaultBeanAssembler}
 16  
  * along with {@link org.mule.config.spring.parsers.collection.ChildSingletonMapDefinitionParser}.
 17  
  * It creates a map with a single key/value pair.  This may seem odd, but the result is not
 18  
  * manipulated within the assembler - that means that, unlike
 19  
  * {@link org.mule.config.spring.parsers.collection.ChildMapEntryDefinitionParser}, this element
 20  
  * can contain nested values.  Note that most uses will set
 21  
  * {@link org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration#isCollection(String)}
 22  
  * so that several entries can be combined.
 23  
  */
 24  0
 public class MapEntryCombiner implements Map
 25  
 {
 26  
 
 27  
     public static final String KEY = "key";
 28  
     public static final String VALUE = "value";
 29  
 
 30  
     private Object key;
 31  
     private Object value;
 32  0
     private Map cachedMerge = new HashMap();
 33  0
     private boolean isMerged = false;
 34  
 
 35  
     private synchronized Map getCachedMerge()
 36  
     {
 37  0
         if (!isMerged)
 38  
         {
 39  0
             cachedMerge.put(key, value);
 40  0
             isMerged = true;
 41  
         }
 42  0
         return cachedMerge;
 43  
     }
 44  
 
 45  
     public Object getKey()
 46  
     {
 47  0
         assertNotMerged();
 48  0
         return key;
 49  
     }
 50  
 
 51  
     public void setKey(Object key)
 52  
     {
 53  0
         assertNotMerged();
 54  0
         this.key = key;
 55  0
     }
 56  
 
 57  
     public Object getValue()
 58  
     {
 59  0
         assertNotMerged();
 60  0
         return value;
 61  
     }
 62  
 
 63  
     public void setValue(Object value)
 64  
     {
 65  0
         assertNotMerged();
 66  0
         this.value = value;
 67  0
     }
 68  
 
 69  
     private synchronized void assertNotMerged()
 70  
     {
 71  0
         if (isMerged)
 72  
         {
 73  0
             throw new IllegalStateException("Maps have already been merged");
 74  
         }
 75  0
     }
 76  
 
 77  
     // map delegates (except hashCode and equals)
 78  
 
 79  
     public int size()
 80  
     {
 81  0
         return getCachedMerge().size();
 82  
     }
 83  
 
 84  
     public void clear()
 85  
     {
 86  0
         getCachedMerge().clear();
 87  0
     }
 88  
 
 89  
     public boolean isEmpty()
 90  
     {
 91  0
         return getCachedMerge().isEmpty();
 92  
     }
 93  
 
 94  
     public boolean containsKey(Object key)
 95  
     {
 96  0
         return getCachedMerge().containsKey(key);
 97  
     }
 98  
 
 99  
     public boolean containsValue(Object value)
 100  
     {
 101  0
         return getCachedMerge().containsValue(value);
 102  
     }
 103  
 
 104  
     public Collection values()
 105  
     {
 106  0
         return getCachedMerge().values();
 107  
     }
 108  
 
 109  
     public void putAll(Map t)
 110  
     {
 111  0
         getCachedMerge().putAll(t);
 112  0
     }
 113  
 
 114  
     public Set entrySet()
 115  
     {
 116  0
         return getCachedMerge().entrySet();
 117  
     }
 118  
 
 119  
     public Set keySet()
 120  
     {
 121  0
         return getCachedMerge().keySet();
 122  
     }
 123  
 
 124  
     public Object get(Object key)
 125  
     {
 126  0
         return getCachedMerge().get(key);
 127  
     }
 128  
 
 129  
     public Object remove(Object key)
 130  
     {
 131  0
         return getCachedMerge().remove(key);
 132  
     }
 133  
 
 134  
     public Object put(Object key, Object value)
 135  
     {
 136  0
         return getCachedMerge().put(key, value);
 137  
     }
 138  
 
 139  
 }