View Javadoc

1   /*
2    *  jDTAUS Core API
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *
20   */
21  package org.jdtaus.core.container;
22  
23  import java.io.Serializable;
24  
25  /**
26   * Argument meta-data.
27   * <p>An argument consists of the properties {@code index}, {@code name} and
28   * {@code type}. Property {@code index} holds the index of the argument in a
29   * list of arguments. Property {@code name} holds the name uniquely identifying
30   * the argument in a set of arguments. Property {@code type} holds the type
31   * of the argument.</p>
32   *
33   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
34   * @version $JDTAUS: Argument.java 8743 2012-10-07 03:06:20Z schulte $
35   */
36  public class Argument extends ModelObject implements Cloneable, Serializable
37  {
38      //--Constants---------------------------------------------------------------
39  
40      /** Constant for property {@code type}. */
41      public static final int TYPE_NUMBER = 27000;
42  
43      /** Constant for property {@code type}. */
44      public static final int TYPE_DATE = 27001;
45  
46      /** Constant for property {@code type}. */
47      public static final int TYPE_TIME = 27002;
48  
49      /** Constant for property {@code type}. */
50      public static final int TYPE_TEXT = 27003;
51  
52      /** Serial version UID for backwards compatibility with 1.5.x classes. */
53      private static final long serialVersionUID = 5250117542077493369L;
54  
55      //---------------------------------------------------------------Constants--
56      //--Argument----------------------------------------------------------------
57  
58      /**
59       * The index of the argument.
60       * @serial
61       */
62      private int index;
63  
64      /**
65       * The name of the argument.
66       * @serial
67       */
68      private String name;
69  
70      /**
71       * The type of the argument.
72       * @serial
73       */
74      private int type;
75  
76      /** Creates a new {@code Argument} instance. */
77      public Argument()
78      {
79          super();
80      }
81  
82      /**
83       * Gets the index of the argument.
84       *
85       * @return the index of the argument.
86       */
87      public int getIndex()
88      {
89          return this.index;
90      }
91  
92      /**
93       * Setter for property {@code index}.
94       *
95       * @param value the new index of the argument.
96       */
97      public void setIndex( final int value )
98      {
99          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 }