Source code: joelib/data/JOEDataType.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: JOEDataType.java,v $
3 // Purpose: Data type.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: Joerg K. Wegner
7 // Version: $Revision: 1.14 $
8 // $Date: 2003/08/19 13:11:24 $
9 // $Author: wegner $
10 // Original Author: ???, OpenEye Scientific Software
11 // Original Version: babel 2.0a1
12 //
13 // Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 ///////////////////////////////////////////////////////////////////////////////
24 package joelib.data;
25
26
27 /*==========================================================================*
28 * IMPORTS
29 *========================================================================== */
30 import java.util.Iterator;
31 import java.util.LinkedList;
32
33
34 /*==========================================================================*
35 * CLASS DECLARATION
36 *========================================================================== */
37
38 /**
39 * Data type.
40 *
41 * There exists a lot of default data types which where defined in
42 * {@link JOEDataType}. These data types are used for caching ring
43 * searches and storing special data types like comments or virtual bonds.
44 * Furthermore there exist the most important data type {@link JOEPairData}
45 * for storing descriptor values.
46 *
47 * <p>
48 * There exists an important difference
49 * between {@link JOEDataType#JOE_PAIR_DATA} and all other data types.
50 * Because there are many descriptor values possible for one molecule, they are hashed to
51 * enable a fast access to these values. This causes that every descriptor
52 * value must have a unique attribute name. It's not possible to store two
53 * {@link JOEPairData} data elements with the same attribute name
54 * ({@link JOEGenericData#setAttribute(String)}).<br>
55 * All other {@link JOEDataType} can occur multiple times, even if they
56 * have the same attribute name. It's e.g. possible to have multiple comments
57 * ({@link JOECommentData}) entries for one molecule.
58 *
59 *
60 * <p>
61 * <TABLE BORDER="1"><THEAD>
62 * <TR>
63 * <TH WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">Data type</TH>
64 * <TH WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">Data name</TH>
65 * <TH WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">Allowed occurence</TH>
66 * </TR>
67 * </THEAD>
68 * <TBODY>
69 * <TR>
70 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">{@link JOEDataType#JOE_UNDEFINED_DATA}</TD>
71 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">Undefined</TD>
72 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">multiple</TD>
73 * </TR>
74 * <TR>
75 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">{@link JOEDataType#JOE_VIRTUAL_BOND_DATA}</TD>
76 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">VirtualBondData</TD>
77 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">multiple</TD>
78 * </TR>
79 * <TR>
80 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">{@link JOEDataType#JOE_ROTAMER_LIST}</TD>
81 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">RotamerList</TD>
82 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">multiple</TD>
83 * </TR>
84 * <TR>
85 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">{@link JOEDataType#JOE_EXTERNAL_BOND_DATA}</TD>
86 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">ExternalBondData</TD>
87 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">multiple</TD>
88 * </TR>
89 * <TR>
90 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">{@link JOEDataType#JOE_COMPRESS_DATA}</TD>
91 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">CompressData</TD>
92 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">multiple</TD>
93 * </TR>
94 * <TR>
95 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">{@link JOEDataType#JOE_COMMENT_DATA}</TD>
96 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">Comment</TD>
97 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">multiple</TD>
98 * </TR>
99 * <TR>
100 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">{@link JOEDataType#JOE_ENERGY_DATA}</TD>
101 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">EnergyData</TD>
102 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">multiple</TD>
103 * </TR>
104 * <TR>
105 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">{@link JOEDataType#JOE_PAIR_DATA}</TD>
106 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">PairData</TD>
107 * <TD WIDTH="33%" ALIGN="LEFT" VALIGN="TOP">single attribute name ({@link JOEGenericData#setAttribute(String)})</TD>
108 * </TR>
109 * </TBODY>
110 * </TABLE>
111 *
112 * @author wegnerj
113 * @license GPL
114 * @cvsversion $Revision: 1.14 $, $Date: 2003/08/19 13:11:24 $
115 */
116 public final class JOEDataType implements java.io.Serializable
117 {
118 //~ Static fields/initializers /////////////////////////////////////////////
119
120 /*-------------------------------------------------------------------------*
121 * public static member variables ( enum variables)
122 *------------------------------------------------------------------------- */
123 private final static LinkedList usedTypes = new LinkedList();
124
125 /**
126 * Description of the Field
127 */
128 public final static JOEDataType JOE_UNDEFINED_DATA = new JOEDataType(0,
129 "Undefined");
130
131 /**
132 * Pair data (descriptor data).
133 *
134 * @see joelib.data.JOEPairData
135 */
136 public final static JOEDataType JOE_PAIR_DATA = new JOEDataType(1,
137 "PairData");
138
139 /**
140 * Description of the Field
141 */
142 public final static JOEDataType JOE_ENERGY_DATA = new JOEDataType(2,
143 "EnergyData");
144
145 /**
146 * Comment data.
147 *
148 * @see joelib.data.JOECommentData
149 */
150 public final static JOEDataType JOE_COMMENT_DATA = new JOEDataType(3,
151 "Comment");
152
153 /**
154 * Description of the Field
155 */
156 public final static JOEDataType JOE_COMPRESS_DATA = new JOEDataType(4,
157 "CompressData");
158
159 /**
160 * Description of the Field
161 */
162 public final static JOEDataType JOE_EXTERNAL_BOND_DATA = new JOEDataType(5,
163 "ExternalBondData");
164
165 /**
166 * Description of the Field
167 */
168 public final static JOEDataType JOE_ROTAMER_LIST = new JOEDataType(6,
169 "RotamerList");
170
171 /**
172 * Description of the Field
173 */
174 public final static JOEDataType JOE_VIRTUAL_BOND_DATA = new JOEDataType(7,
175 "VirtualBondData");
176
177 /**
178 * Ring data.
179 *
180 * @see joelib.ring.JOERingData
181 */
182 public final static JOEDataType JOE_RING_DATA = new JOEDataType(8,
183 "RingData");
184
185 /**
186 * Description of the Field
187 */
188 public final static JOEDataType JOE_SPECTRA_DATA = new JOEDataType(9,
189 "SpectraData");
190
191 /**
192 * Rgroup data.
193 *
194 * @see joelib.data.JOERgroupData
195 */
196 public final static JOEDataType JOE_RGROUP_DATA = new JOEDataType(10,
197 "RgroupData");
198
199 //~ Instance fields ////////////////////////////////////////////////////////
200
201 private String defaultAttribut;
202
203 /**
204 * Description of the Field
205 */
206
207 // private static int minType = 0;
208
209 /**
210 * Description of the Field
211 */
212
213 // private static int maxType = 10;
214 // private final static LinkedList freeNumbers = new LinkedList();
215
216 /*-------------------------------------------------------------------------*
217 * private member variables
218 *------------------------------------------------------------------------- */
219 private int value;
220
221 //~ Constructors ///////////////////////////////////////////////////////////
222
223 /*-------------------------------------------------------------------------*
224 * constructor
225 *------------------------------------------------------------------------- */
226
227 /**
228 * Constructor for the JOEDataType object
229 *
230 * @param _value Description of the Parameter
231 * @param defAttr Description of the Parameter
232 */
233 private JOEDataType(int _value, String _defaultAttr)
234 {
235 value = _value;
236 defaultAttribut = _defaultAttr;
237
238 usedTypes.add(this);
239 }
240
241 //~ Methods ////////////////////////////////////////////////////////////////
242
243 // public static JOEDataType getNewDataType(String _defaultAttr)
244 // {
245 // // return type, if it already exists
246 // if(usedTypes.contains(_defaultAttr))
247 // {
248 // return (JOEDataType)usedTypes.get(usedTypes.indexOf(_defaultAttr));
249 // }
250 //
251 // // create new type
252 // int newNumber;
253 // if( freeNumbers.size()!=0 ) newNumber = ((Integer)freeNumbers.removeFirst()).intValue();
254 // else
255 // {
256 // newNumber = ++maxType;
257 // }
258 //
259 // return new JOEDataType( newNumber, _defaultAttr );
260 // }
261 //
262 // public static boolean releaseDataType(JOEDataType dataType)
263 // {
264 // if(dataType.equals(JOE_UNDEFINED_DATA) ||
265 // dataType.equals(JOE_PAIR_DATA) ||
266 // dataType.equals(JOE_ENERGY_DATA) ||
267 // dataType.equals(JOE_COMMENT_DATA) ||
268 // dataType.equals(JOE_COMPRESS_DATA) ||
269 // dataType.equals(JOE_EXTERNAL_BOND_DATA) ||
270 // dataType.equals(JOE_ROTAMER_LIST) ||
271 // dataType.equals(JOE_VIRTUAL_BOND_DATA) ||
272 // dataType.equals(JOE_RING_DATA) ) return false;
273 //
274 // Integer oldNumber = new Integer(dataType.value);
275 // freeNumbers.add(oldNumber);
276 //
277 // return usedTypes.remove(dataType);
278 // }
279 public static Iterator getAllTypes()
280 {
281 return usedTypes.iterator();
282 }
283
284 /*-------------------------------------------------------------------------*
285 * public methods
286 *-------------------------------------------------------------------------*/
287
288 /**
289 * Gets the defaultAttr attribute of the JOEDataType object
290 *
291 * @return The defaultAttr value
292 */
293 public String getDefaultAttr()
294 {
295 return defaultAttribut;
296 }
297
298 /**
299 * Description of the Method
300 *
301 * @param is Description of the Parameter
302 * @return Description of the Return Value
303 */
304 public boolean equals(Object obj)
305 {
306 if (obj instanceof JOEDataType && (obj != null))
307 {
308 JOEDataType is = (JOEDataType) obj;
309
310 //System.out.println(is.value+"=="+value);
311 if (is.value == value)
312 {
313 return true;
314 }
315 }
316
317 if (obj instanceof String && (obj != null))
318 {
319 String is = (String) obj;
320
321 if (is.equals(defaultAttribut))
322 {
323 return true;
324 }
325 }
326
327 return false;
328 }
329
330 public String toString()
331 {
332 return defaultAttribut;
333 }
334 }
335 ///////////////////////////////////////////////////////////////////////////////
336 // END OF FILE.
337 ///////////////////////////////////////////////////////////////////////////////