Coverage Report - org.org.usurper.setup.ImmutableUsurperGeneratorSetup
 
Classes in this File Line Coverage Branch Coverage Complexity
ImmutableUsurperGeneratorSetup
81 %
21/26
N/A
0
 
 1  
 /*
 2  
  ORG Usurper is a random value object generator library 
 3  
  Copyright (C) 2007  Pierre-Antoine GrĂ©goire
 4  
  
 5  
  This library is free software; you can redistribute it and/or
 6  
  modify it under the terms of the GNU Lesser General Public
 7  
  License as published by the Free Software Foundation; either
 8  
  version 2.1 of the License, or (at your option) any later version.
 9  
  
 10  
  This library is distributed in the hope that it will be useful,
 11  
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  Lesser General Public License for more details.
 14  
  
 15  
  You should have received a copy of the GNU Lesser General Public
 16  
  License along with this library; if not, write to the Free Software
 17  
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.org.usurper.setup;
 20  
 
 21  
 import java.util.Collections;
 22  
 import java.util.HashMap;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.org.usurper.handlers.IHandler;
 26  
 import org.org.usurper.handlers.basic.AbstractPropertyTypeHandler;
 27  
 import org.org.usurper.handlers.basic.AbstractSpecificPropertyHandler;
 28  
 import org.org.usurper.handlers.basic.ArrayHandler;
 29  
 import org.org.usurper.handlers.basic.EnumHandler;
 30  
 import org.org.usurper.model.ITargetDefinition;
 31  
 import org.org.usurper.model.PropertyTypeDefinition;
 32  
 import org.org.usurper.model.SpecificPropertyDefinition;
 33  
 import org.org.usurper.setup.constants.OnMissingHandlers;
 34  
 import org.org.usurper.setup.constants.PropertyWritingMechanism;
 35  
 import org.org.usurper.utils.UsurperGeneratorSetupUtils;
 36  
 
 37  
 /**
 38  
  * This is the immutable version of the class setting up the behaviour of the UsurperGenerator. 
 39  
  * 
 40  
  * @author pagregoire
 41  
  * 
 42  
  */
 43  
 public class ImmutableUsurperGeneratorSetup implements IUsurperGeneratorSetup {
 44  
     private Map<PropertyTypeDefinition, AbstractPropertyTypeHandler> propertyTypeHandlersMap;
 45  
     private Map<SpecificPropertyDefinition, AbstractSpecificPropertyHandler> specificPropertyHandlersMap;
 46  
     private ArrayHandler arrayHandler;
 47  
     private EnumHandler enumHandler;
 48  
     private OnMissingHandlers onMissingHandlers;
 49  
     private PropertyWritingMechanism propertyWritingMechanism;
 50  
     private ICountCallback countCallback;
 51  
 
 52  
     /**
 53  
      * Instantiates a new immutable usurper generator setup.
 54  
      * 
 55  
      * @param propertyTypeHandlersMap the property type handlers map
 56  
      * @param specificPropertyHandlersMap the specific property handlers map
 57  
      * @param arrayHandler the array handler
 58  
      * @param enumHandler the enum handler
 59  
      * @param onMissingHandlers the on missing handlers
 60  
      * @param propertyWritingMechanism the property writing mechanism
 61  
      * @param countCallback the count callback
 62  
      */
 63  
     public ImmutableUsurperGeneratorSetup(Map<PropertyTypeDefinition, AbstractPropertyTypeHandler> propertyTypeHandlersMap, Map<SpecificPropertyDefinition, AbstractSpecificPropertyHandler> specificPropertyHandlersMap, ArrayHandler arrayHandler, EnumHandler enumHandler, OnMissingHandlers onMissingHandlers, PropertyWritingMechanism propertyWritingMechanism, ICountCallback countCallback) {
 64  356
         super();
 65  356
         this.propertyTypeHandlersMap = Collections.unmodifiableMap(propertyTypeHandlersMap);
 66  356
         this.specificPropertyHandlersMap = Collections.unmodifiableMap(specificPropertyHandlersMap);
 67  356
         this.arrayHandler = arrayHandler;
 68  356
         this.enumHandler = enumHandler;
 69  356
         this.onMissingHandlers = onMissingHandlers;
 70  356
         this.propertyWritingMechanism = propertyWritingMechanism;
 71  356
         this.countCallback = countCallback;
 72  356
     }
 73  
 
 74  
     /**
 75  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getPropertyTypeHandlersMap()
 76  
      */
 77  
     public Map<PropertyTypeDefinition, AbstractPropertyTypeHandler> getPropertyTypeHandlersMap() {
 78  0
         return propertyTypeHandlersMap;
 79  
     }
 80  
 
 81  
     /**
 82  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getSpecificPropertyHandlersMap()
 83  
      */
 84  
     public Map<SpecificPropertyDefinition, AbstractSpecificPropertyHandler> getSpecificPropertyHandlersMap() {
 85  0
         return specificPropertyHandlersMap;
 86  
     }
 87  
 
 88  
     /**
 89  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getArrayHandler()
 90  
      */
 91  
     public ArrayHandler getArrayHandler() {
 92  13
         return arrayHandler;
 93  
     }
 94  
 
 95  
     /**
 96  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getEnumHandler()
 97  
      */
 98  
     public EnumHandler getEnumHandler() {
 99  43
         return enumHandler;
 100  
     }
 101  
 
 102  
     /**
 103  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getOnMissingHandlers()
 104  
      */
 105  
     public OnMissingHandlers getOnMissingHandlers() {
 106  3
         return onMissingHandlers;
 107  
     }
 108  
 
 109  
     /**
 110  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getPropertyWritingMechanism()
 111  
      */
 112  
     public PropertyWritingMechanism getPropertyWritingMechanism() {
 113  6973
         return propertyWritingMechanism;
 114  
     }
 115  
 
 116  
     /**
 117  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getCountCallback()
 118  
      */
 119  
     public ICountCallback getCountCallback() {
 120  26
         return countCallback;
 121  
     }
 122  
 
 123  
     /**
 124  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getAllHandlers()
 125  
      */
 126  
     public Map<ITargetDefinition, IHandler> getAllHandlers() {
 127  850
         Map<ITargetDefinition, IHandler> result = new HashMap<ITargetDefinition, IHandler>();
 128  850
         result.putAll(specificPropertyHandlersMap);
 129  850
         result.putAll(propertyTypeHandlersMap);
 130  850
         return Collections.unmodifiableMap(result);
 131  
     }
 132  
 
 133  
     /**
 134  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#hasPropertyTypeHandler(org.org.usurper.model.PropertyTypeDefinition)
 135  
      */
 136  
     public boolean hasPropertyTypeHandler(PropertyTypeDefinition propertyTypeDefinition) {
 137  0
         return this.propertyTypeHandlersMap.containsKey(propertyTypeDefinition);
 138  
     }
 139  
 
 140  
     /**
 141  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getPropertyTypeHandler(org.org.usurper.model.PropertyTypeDefinition)
 142  
      */
 143  
     public AbstractPropertyTypeHandler getPropertyTypeHandler(PropertyTypeDefinition propertyTypeDefinition) {
 144  7065
         return this.propertyTypeHandlersMap.get(propertyTypeDefinition);
 145  
     }
 146  
 
 147  
     /**
 148  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#hasSpecificPropertyHandler(org.org.usurper.model.SpecificPropertyDefinition)
 149  
      */
 150  
     public boolean hasSpecificPropertyHandler(SpecificPropertyDefinition specificPropertyDefinition) {
 151  6964
         return this.specificPropertyHandlersMap.containsKey(specificPropertyDefinition);
 152  
     }
 153  
 
 154  
     /**
 155  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#getSpecificPropertyHandler(org.org.usurper.model.SpecificPropertyDefinition)
 156  
      */
 157  
     public AbstractSpecificPropertyHandler getSpecificPropertyHandler(SpecificPropertyDefinition specificPropertyDefinition) {
 158  14
         return this.specificPropertyHandlersMap.get(specificPropertyDefinition);
 159  
     }
 160  
 
 161  
     /**
 162  
      * @see org.org.usurper.setup.IUsurperGeneratorSetup#toStringRepresentation()
 163  
      */
 164  
     public String toStringRepresentation() {
 165  0
         return UsurperGeneratorSetupUtils.buildStringRepresentation(this);
 166  
     }
 167  
 
 168  
     /**
 169  
      * @see java.lang.Object#toString()
 170  
      */
 171  
     public String toString() {
 172  0
         return toStringRepresentation();
 173  
     }
 174  
 }