Coverage Report - org.org.usurper.model.HandledConstructorArg
 
Classes in this File Line Coverage Branch Coverage Complexity
HandledConstructorArg
40 %
10/25
0 %
0/18
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.model;
 20  
 
 21  
 import java.lang.reflect.Constructor;
 22  
 
 23  
 import org.org.usurper.setup.IUsurperGeneratorSetup;
 24  
 
 25  
 /**
 26  
  * The Class HandledConstructorArg is an immutable value object containing all the necessary elements for the handling of a precise constructor argument of an usurped object.
 27  
  */
 28  
 public class HandledConstructorArg implements IHandledEntity {
 29  
 
 30  
     private final Constructor<?> targetConstructor;
 31  
 
 32  
     private final Class<?> constructorArgClass;
 33  
 
 34  
     private final Integer constructorArgOrderingNumber;
 35  
 
 36  
     private final IUsurperGeneratorSetup usurperGeneratorSetup;
 37  
 
 38  
     /**
 39  
      * This constructor creates the HandledConstructorArg
 40  
      * 
 41  
      * @param targetConstructor 
 42  
      *          the constructor object for the object to be created (can be useful to handle relations between arguments).
 43  
      * @param constructorArgClass
 44  
      *          the class of the constructor arg to generate.
 45  
      * @param constructorArgOrderingNumber the constructor arg ordering number
 46  
      * @param usurperGeneratorSetup the usurper generator setup
 47  
      */
 48  
     public HandledConstructorArg(final Constructor<?> targetConstructor, final Class<?> constructorArgClass, final Integer constructorArgOrderingNumber, final IUsurperGeneratorSetup usurperGeneratorSetup) {
 49  84
         super();
 50  84
         this.targetConstructor = targetConstructor;
 51  84
         this.constructorArgClass = constructorArgClass;
 52  84
         this.constructorArgOrderingNumber = constructorArgOrderingNumber;
 53  84
         this.usurperGeneratorSetup = usurperGeneratorSetup;
 54  84
     }
 55  
 
 56  
     /**
 57  
      * Gets the constructor used to create the object.
 58  
      * 
 59  
      * @return the target constructor
 60  
      */
 61  
     public Constructor<?> getTargetConstructor() {
 62  10
         return targetConstructor;
 63  
     }
 64  
     
 65  
     /**
 66  
      * Gets the class of the constructor arg to be handled. 
 67  
      * 
 68  
      * @return the constructor arg class
 69  
      */
 70  
     public Class<?> getConstructorArgClass() {
 71  76
         return constructorArgClass;
 72  
     }
 73  
 
 74  
     /**
 75  
      * Gets the constructor arg ordering number.
 76  
      * 
 77  
      * @return the constructor arg ordering number
 78  
      */
 79  
     public Integer getConstructorArgOrderingNumber() {
 80  10
         return constructorArgOrderingNumber;
 81  
     }
 82  
 
 83  
     /**
 84  
      * Gets the usurper generator setup.
 85  
      * 
 86  
      * @return the usurper generator setup
 87  
      */
 88  
     public IUsurperGeneratorSetup getUsurperGeneratorSetup() {
 89  192
         return usurperGeneratorSetup;
 90  
     }
 91  
 
 92  
     @Override
 93  
     public String toString() {
 94  0
         StringBuilder stringBuilder = new StringBuilder();
 95  0
         stringBuilder.append("Target constructor: " + targetConstructor.toGenericString());
 96  0
         stringBuilder.append("constructor arg: " + constructorArgClass.getName() + " (" + constructorArgOrderingNumber + ")");
 97  0
         return stringBuilder.toString();
 98  
     }
 99  
 
 100  
     @Override
 101  
     public boolean equals(Object obj) {
 102  0
         if (this == obj)
 103  0
             return true;
 104  0
         if ((obj == null) || (obj.getClass() != this.getClass()))
 105  0
             return false;
 106  
         // object must be Test at this point
 107  0
         HandledConstructorArg other = (HandledConstructorArg) obj;
 108  0
         return targetConstructor.equals(other.targetConstructor) && constructorArgClass.getName().equals(other.constructorArgClass.getName()) && constructorArgOrderingNumber == other.constructorArgOrderingNumber;
 109  
     }
 110  
 
 111  
     @Override
 112  
     public int hashCode() {
 113  0
         int hash = 7;
 114  0
         hash = 31 * hash + (null == targetConstructor ? 0 : targetConstructor.hashCode());
 115  0
         hash = 31 * hash + (null == constructorArgClass ? 0 : constructorArgClass.hashCode());
 116  0
         hash = 31 * hash + (null == constructorArgOrderingNumber ? 0 : constructorArgOrderingNumber.hashCode());
 117  0
         return hash;
 118  
     }
 119  
 }