[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [x3d-public] Checking node type



>> note: never use == for string comparisons in Java, unless you have
>> access to X3D's java class [it's some interface usually] where the
>> string constants are defined (supposing the same constants are reused
>> everywhere). That is cause == compares for object equality, not for
>> content equality in this case (one of the peculiarities of Java)
>> 
>getNodeType will eventually be the fastest route for checking types.
>But its not implemented in Xj3D yet.  I've been using getNodeName and
.equals right now.  instanceof checks will not work as they the objects are
wrapped by a class
>that's the same for each type.

For extra speed you could add an interface with all types as String
constants that one could import in their class and use in the style of
Xj3DConstants.SOMETYPE so that they could use
x.getNodeType()==Xj3DConstants.SOMETYPE instead of .equals in the code. Of
course this makes the user code Xj3D specific (cause user code has to be
compiled against the same constants file that is used by the browser - also
IPC scenarios were client code is running in other JVM that the VRML
browswer might not work with the ==SomeConstant scheme)

Btw, why are all objects the same class? There should many classes all
descending from the same class. When you have

SomeClass x;
x=new SomeClassDescendent();

When you do
  x instanceof SomeClassDescendent
It will return true OK, even though x was of type SomeClass. That is cause
it's holding an instance of SomeClassDescendent which can be assigned to an
ancestral type like SomeClass, but still is a SomeClassDescendent object and
behaves as such (polymorphism)

Apart from instanceof, the "Class" (or was it the "Object"?) class has some
extra handy method for checking if some object is assignable to some class
type (isAssignable). That is useful since you may have an Object y that you
want to check if it's assignable to a SomeClass type and you're not sure if
it's of SomeClassDescendent, SomeClassOtherDescendent,
SomeClassLongDescendent type (cause to use instanceof you need to know WHICH
descendent class it is you're checking against, whereas you may not care
about it, but just care to see if it's a type descending from a certain
class to know it supports that programming contract-class)

Cheers,
George

----------------
George Birbilis (birbilis@kagi.com)
Microsoft MVP J# for 2004-2006
* QuickTime, QTVR, ActiveX, VCL, .NET
http://www.kagi.com/birbilis
* Robotics PhD student
http://www.mech.upatras.gr/~Robotics
http://www.mech.upatras.gr/~robgroup




  _____  

avast! Antivirus <http://www.avast.com> : Outbound message clean. 


Virus Database (VPS): 0609-3, 03/03/2006
Tested on: 3/3/2006 3:26:13 ??
avast! - copyright (c) 1988-2005 ALWIL Software.



-------------------------------------------------------------------------
for list subscription/unsubscription,
go to http://www.web3d.org/cgi-bin/public_list_signup/lwgate/listsavail.html