Source code: joelib/util/JOEHelper.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: JOEHelper.java,v $
3 // Purpose: Atom representation.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: Joerg K. Wegner
7 // Version: $Revision: 1.13 $
8 // $Date: 2003/08/19 13:11:29 $
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.util;
25
26
27 /*==========================================================================*
28 * IMPORTS
29 *========================================================================== */
30 import joelib.data.*;
31
32
33 /*==========================================================================*
34 * CLASS DECLARATION
35 *========================================================================== */
36
37 /**
38 * JOELib helper methods.
39 *
40 * @author wegnerj
41 * @license GPL
42 * @cvsversion $Revision: 1.13 $, $Date: 2003/08/19 13:11:29 $
43 */
44 public class JOEHelper
45 {
46 //~ Static fields/initializers /////////////////////////////////////////////
47
48 /*-------------------------------------------------------------------------*
49 * public static member variables
50 *------------------------------------------------------------------------- */
51
52 /**
53 * Description of the Field
54 */
55 public final static String CONTACT_E_MAIL = "wegnerj@informatik.uni-tuebingen.de";
56
57 /**
58 * Description of the Field
59 */
60 public final static String BABEL_VERSION = "2.0a1";
61
62 /**
63 * Description of the Field
64 */
65 public final static int BUFF_SIZE = 1024;
66
67 /**
68 * Description of the Field
69 */
70 public static int OEPolarGrid = 0x01;
71
72 /**
73 * Description of the Field
74 */
75 public static int OELipoGrid = 0x02;
76
77 /**
78 * Description of the Field
79 */
80 public static int PT_CATION = 1;
81
82 /**
83 * Description of the Field
84 */
85 public static int PT_ANION = 2;
86
87 /**
88 * Description of the Field
89 */
90 public static int PT_ACCEPTOR = 3;
91
92 /**
93 * Description of the Field
94 */
95 public static int PT_POLAR = 4;
96
97 /**
98 * Description of the Field
99 */
100 public static int PT_DONOR = 5;
101
102 /**
103 * Description of the Field
104 */
105 public static int PT_HYDROPHOBIC = 6;
106
107 /**
108 * Description of the Field
109 */
110 public static int PT_OTHER = 7;
111
112 /**
113 * Description of the Field
114 */
115 public static int PT_METAL = 8;
116
117 //~ Methods ////////////////////////////////////////////////////////////////
118
119 // private static Hashtable hasInterfaceCache = new Hashtable(500);
120
121 /*-------------------------------------------------------------------------*
122 * public methods
123 *------------------------------------------------------------------------- */
124
125 /**
126 * Description of the Method
127 *
128 * @param a Description of the Parameter
129 * @param b Description of the Parameter
130 * @return Description of the Return Value
131 */
132 public final static boolean EQ(String a, String b)
133 {
134 return a.equals(b);
135 }
136
137 /**
138 * Description of the Method
139 *
140 * @param a Description of the Parameter
141 * @param b Description of the Parameter
142 * @param n Description of the Parameter
143 * @return Description of the Return Value
144 */
145 public final static boolean EQn(String a, String b, int n)
146 {
147 return (a.substring(0, n - 1).equals(b.substring(0, n - 1)));
148 }
149
150 /**
151 * Description of the Method
152 *
153 * @param x Description of the Parameter
154 * @return Description of the Return Value
155 */
156 public final static double SQUARE(double x)
157 {
158 return x * x;
159 }
160
161 /**
162 * Gets the unsatType attribute of the JOEHelper class
163 *
164 * @param x Description of the Parameter
165 * @return The unsatType value
166 */
167 public static boolean isUnsatType(String x)
168 {
169 return (EQ(x, "Car") || EQ(x, "C2") || EQ(x, "Sox") || EQ(x, "Sac") ||
170 EQ(x, "Pac") || EQ(x, "So2"));
171 }
172
173 /**
174 * Checks if an class implements an interface. This version allows short Interface name definitions.
175 * E.g. joelib.io.PropertyWriter or (faster) PropertyWriter.
176 *
177 * @todo Cache search routine for object/interface pairs
178 * @todo Use shorter interface names
179 * @param o Description of the Parameter
180 * @param interfaceName Description of the Parameter
181 * @return Description of the Return Value
182 */
183 public static boolean hasInterface(Object o, String interfaceName)
184 {
185 // System.out.println("check: "+o);
186 if (o == null)
187 {
188 return false;
189 }
190
191 Class c = o.getClass();
192
193 int size;
194
195 while (true)
196 {
197 Class[] theInterfaces = c.getInterfaces();
198 size = theInterfaces.length;
199
200 for (int i = 0; i < size; i++)
201 {
202 String _interfaceName = theInterfaces[i].getName();
203
204 // System.out.println("class:"+o.getClass().getName()+"_interfaceName:"+_interfaceName);
205 // absoulutely correct, but a little bit slower
206 // if(_interfaceName.equals(interfaceName))return true;
207 // if (_interfaceName.lastIndexOf(interfaceName) != -1)
208 // faster and more problematic by multiple interface names, if you choose short
209 // interface names without package names ! Your (efficiency) choice !;-)
210 if (_interfaceName.regionMatches(_interfaceName.length() -
211 interfaceName.length(), interfaceName, 0,
212 interfaceName.length()))
213 {
214 return true;
215 }
216 }
217
218 theInterfaces = null;
219 c = c.getSuperclass();
220
221 if (c == null)
222 {
223 break;
224 }
225 }
226
227 c = null;
228
229 return false;
230 }
231
232 /*-------------------------------------------------------------------------*
233 * public member variables
234 *------------------------------------------------------------------------- */
235 /*-------------------------------------------------------------------------*
236 * constructor
237 *------------------------------------------------------------------------- */
238 /*-------------------------------------------------------------------------*
239 * public methods
240 *------------------------------------------------------------------------- */
241 }
242 ///////////////////////////////////////////////////////////////////////////////
243 // END OF FILE.
244 ///////////////////////////////////////////////////////////////////////////////