001/* 002 * jDTAUS Core API 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.core.container; 022 023import java.io.Serializable; 024 025/** 026 * Argument meta-data. 027 * <p>An argument consists of the properties {@code index}, {@code name} and 028 * {@code type}. Property {@code index} holds the index of the argument in a 029 * list of arguments. Property {@code name} holds the name uniquely identifying 030 * the argument in a set of arguments. Property {@code type} holds the type 031 * of the argument.</p> 032 * 033 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 034 * @version $JDTAUS: Argument.java 8743 2012-10-07 03:06:20Z schulte $ 035 */ 036public class Argument extends ModelObject implements Cloneable, Serializable 037{ 038 //--Constants--------------------------------------------------------------- 039 040 /** Constant for property {@code type}. */ 041 public static final int TYPE_NUMBER = 27000; 042 043 /** Constant for property {@code type}. */ 044 public static final int TYPE_DATE = 27001; 045 046 /** Constant for property {@code type}. */ 047 public static final int TYPE_TIME = 27002; 048 049 /** Constant for property {@code type}. */ 050 public static final int TYPE_TEXT = 27003; 051 052 /** Serial version UID for backwards compatibility with 1.5.x classes. */ 053 private static final long serialVersionUID = 5250117542077493369L; 054 055 //---------------------------------------------------------------Constants-- 056 //--Argument---------------------------------------------------------------- 057 058 /** 059 * The index of the argument. 060 * @serial 061 */ 062 private int index; 063 064 /** 065 * The name of the argument. 066 * @serial 067 */ 068 private String name; 069 070 /** 071 * The type of the argument. 072 * @serial 073 */ 074 private int type; 075 076 /** Creates a new {@code Argument} instance. */ 077 public Argument() 078 { 079 super(); 080 } 081 082 /** 083 * Gets the index of the argument. 084 * 085 * @return the index of the argument. 086 */ 087 public int getIndex() 088 { 089 return this.index; 090 } 091 092 /** 093 * Setter for property {@code index}. 094 * 095 * @param value the new index of the argument. 096 */ 097 public void setIndex( final int value ) 098 { 099 this.index = value; 100 } 101 102 /** 103 * Gets the name of the argument. 104 * 105 * @return the name of the argument. 106 */ 107 public String getName() 108 { 109 if ( this.name == null ) 110 { 111 this.name = ""; 112 } 113 114 return this.name; 115 } 116 117 /** 118 * Setter for property {@code name}. 119 * 120 * @param value the new name of the argument. 121 */ 122 public void setName( final String value ) 123 { 124 this.name = value; 125 } 126 127 /** 128 * Gets the type of the argument. 129 * 130 * @return the type of the argument. 131 */ 132 public int getType() 133 { 134 return this.type; 135 } 136 137 /** 138 * Setter for property {@code type}. 139 * 140 * @param value the new type of the argument. 141 * 142 * @throws IllegalArgumentException if {@code value} is not equal to one of 143 * the constants {@code TYPE_NUMBER}, {@code TYPE_DATE}, {@code TYPE_TIME} 144 * or {@code TYPE_TEXT}. 145 */ 146 public void setType( final int value ) 147 { 148 if ( value != TYPE_NUMBER && value != TYPE_DATE && 149 value != TYPE_TIME && value != TYPE_TEXT ) 150 { 151 throw new IllegalArgumentException( Integer.toString( value ) ); 152 } 153 154 this.type = value; 155 } 156 157 /** 158 * Creates a string representing the properties of the instance. 159 * 160 * @return a string representing the properties of the instance. 161 */ 162 private String internalString() 163 { 164 final StringBuffer buf = new StringBuffer( 500 ).append( '{' ). 165 append( this.internalString( this ) ). 166 append( ", index=" ).append( this.index ). 167 append( ", name=" ).append( this.name ). 168 append( ", type=" ); 169 170 if ( this.type == TYPE_NUMBER ) 171 { 172 buf.append( "number" ); 173 } 174 else if ( this.type == TYPE_DATE ) 175 { 176 buf.append( "date" ); 177 } 178 else if ( this.type == TYPE_TIME ) 179 { 180 buf.append( "time" ); 181 } 182 else if ( this.type == TYPE_TEXT ) 183 { 184 buf.append( "text" ); 185 } 186 187 return buf.append( '}' ).toString(); 188 } 189 190 //----------------------------------------------------------------Argument-- 191 //--Object------------------------------------------------------------------ 192 193 /** 194 * Returns a string representation of the object. 195 * 196 * @return a string representation of the object. 197 */ 198 public String toString() 199 { 200 return super.toString() + this.internalString(); 201 } 202 203 /** 204 * Indicates whether some other object is equal to this one by comparing 205 * the values of all properties. 206 * 207 * @param o the reference object with which to compare. 208 * 209 * @return {@code true} if this object is the same as {@code o}; 210 * {@code false} otherwise. 211 */ 212 public boolean equals( final Object o ) 213 { 214 boolean equal = this == o; 215 216 if ( !equal && o instanceof Argument ) 217 { 218 final Argument that = (Argument) o; 219 equal = this.getIndex() == that.getIndex() && 220 this.getType() == that.getType() && 221 this.getName().equals( that.getName() ); 222 223 } 224 225 return equal; 226 } 227 228 /** 229 * Returns a hash code value for this object. 230 * 231 * @return a hash code value for this object. 232 */ 233 public int hashCode() 234 { 235 int hc = 23; 236 hc = 37 * hc + this.getIndex(); 237 hc = 37 * hc + this.getName().hashCode(); 238 hc = 37 * hc + this.getType(); 239 return hc; 240 } 241 242 /** 243 * Creates and returns a copy of this object. This method performs a 244 * "shallow copy" of this object, not a "deep copy" operation. 245 * 246 * @return a clone of this instance. 247 */ 248 public Object clone() 249 { 250 try 251 { 252 return super.clone(); 253 } 254 catch ( final CloneNotSupportedException e ) 255 { 256 throw new AssertionError( e ); 257 } 258 } 259 260 //------------------------------------------------------------------Object-- 261}