1 //$Id: ActionState.java 220 2006-03-17 00:22:16Z jg_hamburg $ 2 /******************************************************************************** 3 * DDTUnit, a Datadriven Approach to Unit- and Moduletesting 4 * Copyright (c) 2004, Joerg and Kai Gellien 5 * All rights reserved. 6 * 7 * The Software is provided under the terms of the Common Public License 1.0 8 * as provided with the distribution of DDTUnit in the file cpl-v10.html. 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * + Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * + Redistributions in binary form must reproduce the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer in the documentation and/or other materials provided 19 * with the distribution. 20 * 21 * + Neither the name of the authors or DDTUnit, nor the 22 * names of its contributors may be used to endorse or promote 23 * products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 ********************************************************************************/ 38 package junitx.ddtunit.data.processing; 39 40 /** 41 * Class for defining special processing states useful for object instanciation 42 */ 43 final class ActionState { 44 /** 45 * Object parsing type, identifying a standard object to parse 46 */ 47 public final static ActionState OBJECT_CREATION = new ActionState(4, 48 "Object Creation Processing"); 49 50 /** 51 * Assert parsing type, identifying a standard assertion to parse 52 */ 53 public final static ActionState ASSERT_CREATION = new ActionState(5, 54 "Assert Creation Processing"); 55 56 /** 57 * Exception parsing type, identifying a standard expected exception to 58 * parse 59 */ 60 public final static ActionState EXCEPTION_CREATION = new ActionState(6, 61 "Exception Creation Processing"); 62 63 /** 64 * XML Content parsing type, identifying xml content to parse 65 */ 66 public final static ActionState CONTENT_CREATION = new ActionState(7, 67 "Content Extraction Processing"); 68 69 /** 70 * Subelement parsing type, identifying a substructure object to parse, e.g. 71 * a field of a value object 72 */ 73 public final static ActionState SUBELEMENT_CREATION = new ActionState(8, 74 "Subelement Creation Processing"); 75 76 /** 77 * Collection parsing type, identifying a collection object to parse, e.g. a 78 * list of object values 79 */ 80 public final static ActionState COLLECTION_CREATION = new ActionState(10, 81 "Collection Creation Processing"); 82 83 /** 84 * Map parsing type, identifying a map object to parse, e.g. a list of 85 * object values 86 */ 87 public final static ActionState MAP_CREATION = new ActionState(11, 88 "Map Creation Processing"); 89 90 /** 91 * Date parsing type, identifying a Date object to parse, e.g. a date time 92 * object 93 */ 94 public final static ActionState DATE_CREATION = new ActionState(12, 95 "Date Creation Processing"); 96 97 public static final ActionState ATTRLIST_CREATION = new ActionState(13, 98 "Internal Attribute Creation Processing"); 99 100 public static final ActionState ARRAY_CREATION = new ActionState(14, 101 "Array Creation Processing"); 102 103 public static final ActionState BEAN_CREATION = new ActionState(15, 104 "Bean Creation Processing"); 105 106 public static final ActionState CALL_CREATION = new ActionState(16, 107 "Call Creation Processing"); 108 109 public static final ActionState CONSTANT_CREATION = new ActionState(17, 110 "Constant Creation Process"); 111 112 private int id; 113 114 private String name; 115 116 private ActionState() { 117 // no special initialization 118 } 119 120 private ActionState(int id, String name) { 121 if (id < 0 || name == null || name.compareTo("") == 0) { 122 throw new IllegalArgumentException( 123 "Wrong arguments: id >= 0, name not empty."); 124 } 125 this.id = id; 126 this.name = name; 127 } 128 129 /** 130 * Overwrite toString() method. 131 * 132 * @return name of parse type 133 */ 134 public String toString() { 135 return this.name; 136 } 137 138 /** 139 * Returns <code>true</code> if this <code>ActionState</code> is the 140 * same as the o argument. 141 * 142 * @return <code>true</code> if this <code>ActionState</code> is the 143 * same as the o argument. 144 */ 145 public boolean equals(Object obj) { 146 boolean check = false; 147 if (obj != null && obj.getClass() == getClass()) { 148 ActionState castedObj = (ActionState) obj; 149 check = ((this.id == castedObj.id) && (this.name == null ? castedObj.name == null 150 : this.name.equals(castedObj.name))); 151 } 152 return check; 153 } 154 155 /** 156 * Override hashCode. 157 * 158 * @return the Objects hashcode. 159 */ 160 public int hashCode() { 161 int hashCode = 1; 162 hashCode = 31 * hashCode + id; 163 hashCode = 31 * hashCode + (name == null ? 0 : name.hashCode()); 164 return hashCode; 165 } 166 }