Coverage Report - org.org.usurper.model.PropertyTypeDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyTypeDefinition
48 %
10/21
50 %
4/8
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  
 /**
 22  
  * The Class PropertyTypeDefinition is an immutable value object describing a target property type.
 23  
  */
 24  
 public class PropertyTypeDefinition implements ITargetDefinition {
 25  
 
 26  
     private final Class<?> targetClass;
 27  
 
 28  
     /**
 29  
      * Instantiates a new PropertyTypeDefinition from a Class object.
 30  
      * 
 31  
      * @param targetClass the target class
 32  
      */
 33  
     public PropertyTypeDefinition(final Class<?> targetClass) {
 34  7684
         super();
 35  7684
         this.targetClass = targetClass;
 36  7684
     }
 37  
 
 38  
     /**
 39  
      * Instantiates a new PropertyTypeDefinition from the name of a Class.
 40  
      * 
 41  
      * @param targetDescription the target description
 42  
      */
 43  
     public PropertyTypeDefinition(final String targetDescription) {
 44  0
         super();
 45  0
         String targetClassName = targetDescription;
 46  
         try {
 47  0
             this.targetClass = Class.forName(targetClassName);
 48  0
         } catch (ClassNotFoundException e) {
 49  0
             throw new IllegalArgumentException("Impossible to resolve class in: " + targetDescription, e);
 50  0
         }
 51  0
     }
 52  
 
 53  
     /**
 54  
      * Gets the target class.
 55  
      * 
 56  
      * @return the target class
 57  
      */
 58  
     public Class<?> getTargetClass() {
 59  0
         return targetClass;
 60  
     }
 61  
 
 62  
     @Override
 63  
     public String toString() {
 64  0
         return targetClass.getName();
 65  
     }
 66  
 
 67  
     @Override
 68  
     public boolean equals(Object obj) {
 69  7575
         if (this == obj)
 70  0
             return true;
 71  7575
         if ((obj == null) || (obj.getClass() != this.getClass()))
 72  0
             return false;
 73  
         // object must be Test at this point
 74  7575
         PropertyTypeDefinition other = (PropertyTypeDefinition) obj;
 75  7575
         return targetClass.equals(other.targetClass);
 76  
     }
 77  
 
 78  
     @Override
 79  
     public int hashCode() {
 80  52956
         int hash = 7;
 81  52956
         hash = 31 * hash + (null == targetClass ? 0 : targetClass.hashCode());
 82  52956
         return hash;
 83  
     }
 84  
 }