KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > examples > jet > article2 > model > Attribute


1 package org.eclipse.emf.examples.jet.article2.model;
2
3
4 /**
5  * Class modelling an attribute of an enumeration instance. An attribute is a
6  * member variable of the enumeration instance that may or may not be used to
7  * uniquely identify an instance depending on whether is is marked as a key
8  * attribute or not.
9  *
10  * @author Remko Popma
11  * @version $Revision: 1.1 $ ($Date: 2004/05/31 21:35:35 $)
12  */

13 public class Attribute
14 {
15
16   private boolean mKey = false;
17
18   private String JavaDoc mName = "";
19
20   private String JavaDoc mType = "";
21
22   /**
23    * Constructs an uninitialized <code>Attribute</code>.
24    */

25   public Attribute()
26   {
27     super();
28   }
29
30   /**
31    * Constructs an <code>Attribute</code> initialized with the specified
32    * values.
33    *
34    * @param type
35    * the type of this attribute
36    * @param name
37    * the name of this attribute
38    * @param isKey
39    * whether this attribute is one of the key attributes that uniquely
40    * identifies an instance
41    */

42   public Attribute(String JavaDoc type, String JavaDoc name, boolean isKey)
43   {
44     super();
45     mType = type;
46     mName = name;
47     mKey = isKey;
48   }
49
50   /**
51    * Returns the name of the get method for this attribute. The returned string
52    * does not contain the type of this attribute and does not end in brackets.
53    * For example <code>isInitialized</code> or <code>getAddress</code>.
54    *
55    * @return the name of the get method for this attribute
56    */

57   public String JavaDoc toGetMethod()
58   {
59     return ("boolean".equals(getType())) ? "is" + getCappedName() : "get" + getCappedName();
60   }
61
62   /**
63    * Returns the name of this attribute with the first character converted to
64    * upper case.
65    *
66    * @return the name of this attribute with the first character converted to
67    * upper case
68    */

69   public String JavaDoc getCappedName()
70   {
71     return NameUtil.capName(getName());
72   }
73
74   /**
75    * Returns the name of this attribute with the first character converted to
76    * lower case.
77    *
78    * @return the name of this attribute with the first character converted to
79    * lower case
80    */

81   public String JavaDoc getUncappedName()
82   {
83     return NameUtil.uncapName(getName());
84   }
85
86   public boolean isBoolean()
87   {
88     return "boolean".equals(getType());
89   }
90
91   public boolean isInt()
92   {
93     return "int".equals(getType());
94   }
95
96   public boolean isChar()
97   {
98     return "char".equals(getType());
99   }
100
101   public boolean isByte()
102   {
103     return "byte".equals(getType());
104   }
105
106   public boolean isShort()
107   {
108     return "short".equals(getType());
109   }
110
111   public boolean isLong()
112   {
113     return "long".equals(getType());
114   }
115
116   public boolean isDouble()
117   {
118     return "double".equals(getType());
119   }
120
121   public boolean isFloat()
122   {
123     return "float".equals(getType());
124   }
125
126   /**
127    * Returns the name of this attribute.
128    *
129    * @return the name of this attribute
130    */

131   public String JavaDoc getName()
132   {
133     return mName;
134   }
135
136   /**
137    * Returns the type of this attribute.
138    *
139    * @return the type of this attribute
140    */

141   public String JavaDoc getType()
142   {
143     return mType;
144   }
145
146   /**
147    * Sets the name of this attribute.
148    *
149    * @param name
150    * the name of this attribute
151    */

152   public void setName(String JavaDoc name)
153   {
154     mName = name;
155   }
156
157   /**
158    * Sets the type of this attribute.
159    *
160    * @param type
161    * the type of this attribute
162    */

163   public void setType(String JavaDoc type)
164   {
165     mType = type;
166   }
167
168   /**
169    * Returns whether this attribute is one of the attributes that uniquely
170    * identify an instance.
171    *
172    * @return whether this attribute is one of the attributes that uniquely
173    * identify an instance
174    */

175   public boolean isKey()
176   {
177     return mKey;
178   }
179
180   /**
181    * Sets whether this attribute is one of the attributes that uniquely identify
182    * an instance.
183    *
184    * @param isKey
185    * whether this attribute is one of the attributes that uniquely
186    * identify an instance
187    */

188   public void setKey(boolean isKey)
189   {
190     mKey = isKey;
191   }
192 }
Popular Tags