| Author | Topic |
Posts: 273
Registered: June 2006
|
|
Initialization of ListOf objects
|
21 Dec '09 23:24
|
 |
|
Good morning!
It is understandable that in all SBase objects that contain ListOf
objects these lists are set to null when initializing these objects. For
instance, a when a new Model is created, all pointers to ListOf (e.g.,
Parameters or Species) are set to null. The same holds true for
Reactions, Events etc.
With this approach, it becomes possible to check whether such a list has
been set or not by designated methods, such as isSetListOfParameters().
In some cases this functionality can be nice. isSetListOfParameters()
simply checks whether the corresponding ListOf object is set to null.
However, this approach makes working with our data structure much harder
than it should be because programmers always have to take care to avoid
NullPointerExceptions. This dramatically reduces the fun when working
with JSBML, although there is a little more functionality due to these
isSetListOf*() methods. Things are much easier if these lists are
initialized as empty lists. And, of course, if such a list is empty, it
will not be written into an SBML file at the end. But as long as we work
in memory, we can apply methods such as
reaction.getListOfReactants().size() as an alternative for
reaction.getNumReactants() and so forth. The other problem is that when
trying to add a ChangeListener one receives several null pointer
exceptions except one sets all listOf* objects to empty lists before
adding a ChangeListener to the SBase objects. I am convinced that people
will not do that but get angry when trying to add a ChangeListener
correctly to some SBase and then receive NullPointerExceptions.
I therefore strongly recommend to initialize all lists as empty lists
when creating new SBase objects.
Cheers and merry Christmas!
Andreas
--
Dipl.-Bioinform. Andreas Dräger
Eberhard Karls University Tübingen
Center for Bioinformatics (ZBIT)
Sand 1
72076 Tübingen
Germany
Phone: +49-7071-29-70436
Fax: +49-7071-29-5091
____________________________________________________________
To manage your jsbml-development list subscription, visit
https://utils.its.caltech.edu/mailman/listinfo/jsbml-development
For a web interface to the jsbml-development mailing list, visit
http://sbml.org/Forums/
For questions or feedback about the jsbml-development list,
contact sbml-team@caltech.edu
|
|
|
Posts: 273
Registered: June 2006
|
|
|
Posts: 307
Location: Cambridge UK
Registered: February 2005
|
|
|