|
From: Sven G. <sgo...@ja...> - 2002-06-14 14:46:36
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Friday 14 June 2002 16:23, Alex Alessandra wrote:
> Hi again,
>
> I'm not deep into C2J, but I can suggest an obvious method to accomplish
> the task, the following code is generic and works outside gl4java classes,
> but, again, please consider the implementation into the gl4java package:
>
> public static int getIntForConstant(String constant) {
> try {
> java.lang.Class enumClass =
> java.lang.Class.forName("gl4java.GLEnum"); java.lang.reflect.Field[] fields
> = enumClass.getFields();
>
> for(int i=0; i<fields.length; i++) {
>
> if(fields[i].getName().equals(constant)) {
> // Found!
> return fields[i].getInt(enumClass);
> }
> }
> } catch (IllegalAccessException e) {
> // Would it occur ??? Do nothing...
> } catch (ClassNotFoundException e) {
> // GLEnum not found ??? Do nothing...
> }
> // Not found!
> return 0;
> }
>
> This method returns the correct GLEnum.[field] as int value if the given
> constant string exists, otherwise it returns simply 0 (maybe -1 is more
> appropriate, or throwing an Exception???).
>
> Waiting for comments...
>
ok !
i guess "-1" would be more c stylish ;-)
but if somebody loves exceptions more .. well, let's vote.
my vote: -1
i do wait a bit, then i can cvs ci this function as a static function
within GLEnum ?
cheers, sven
- --
health & wealth
mailto:sgo...@ja...
www : http://www.jausoft.com ; pgp: http://www.jausoft.com/gpg/
voice : +49-521-2399440 ; fax : +49-521-2399442
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE9CgG/HdOA30NoFAARAm7hAJ9RqOyveKphkZJ9jqeoSkKqzG1gvwCgqWLr
9r3XkHhBRun4zTSXttnbjW8=
=RR08
-----END PGP SIGNATURE-----
|