Forums

F.A.Q. F.A.Q.    Register Register    Login Login    Home Home
Search Search
SBML Discussions » jsbml-development » Initialization of ListOf objects
Show: Today's Posts  :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
AuthorTopic
Andreas Dräger


Posts: 273
Registered:
June 2006
Initialization of ListOf objects 21 Dec '09 23:24 Go to next message

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

      
Andreas Dräger


Posts: 273
Registered:
June 2006
Re: Initialization of ListOf objects 27 Dec '09 23:46 Go to previous messageGo to next message

Good morning everybody!

Ok, maybe we can go with the following compromise: Let's set all lists
to null when new Objects that contain ListOf Objects are initialized.
But the get- method should initialized the corresponding list, e.g.,
getListOfParameters() should initialize the list of parameters if it is
still null. The method addChangeListener() has to initialize all lists
otherwise we'll run into unnecessary NullPointerExceptions or we have to
force the programmer to initialize all lists first. What do you think?

Cheers
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

      
rodrigue


Posts: 307
Location:
Cambridge UK
Registered:
February 2005
Re: Initialization of ListOf objects 22 Jan '10 02:39 Go to previous message

Andreas Draeger wrote:
> Good morning everybody!
>
> Ok, maybe we can go with the following compromise: Let's set all lists
> to null when new Objects that contain ListOf Objects are initialized.
> But the get- method should initialized the corresponding list, e.g.,
> getListOfParameters() should initialize the list of parameters if it is
> still null. The method addChangeListener() has to initialize all lists
> otherwise we'll run into unnecessary NullPointerExceptions or we have to
> force the programmer to initialize all lists first. What do you think
As always in these case, a simple way to decide which way to go is to
check the behavior of libsbml as we want to be as close as possible to
their api.
So can you check what libsbml is returning in these cases ? And if they
return an empty list and not null, it would make sense to initialize the
lists from the start.

Nico


____________________________________________________________
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

      
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic:Annotation and ModelHistory
Next Topic:Re: help offer
Go to forum:
-=] Back to Top [=-

Powered by FUDforum. (Copyright Advanced Internet Designs Inc.)

Please use our issue tracking system for any questions or suggestions about this website.