Skip to content

Conversation

@dyrpsf
Copy link

@dyrpsf dyrpsf commented Jan 7, 2026

Summary

This PR updates ModelBuilder so that it checks whether a model element with a given id
already exists before creating a new one. This avoids clashes and duplicate elements when
using ModelBuilder to extend or modify existing models.

The following methods now reuse existing elements if present:

  • buildModel(String id, String name) → reuses the existing model in the SBMLDocument if set.
  • buildCompartment(...) → uses model.getCompartment(id) if available.
  • buildParameter(...) → uses model.getParameter(id) if available.
  • buildReaction(...) → uses model.getReaction(id) if available.
  • buildSpecies(...) → uses model.getSpecies(id) if available.
  • buildUnitDefinition(...) → uses model.getUnitDefinition(id) if available.

In each case, a new element is only created if no element with the given id already exists.

Rationale

Previously, ModelBuilder always called createXXX(id) on the model, assuming that elements
with the given IDs did not exist yet. When extending an existing model, this could lead to
clashes or exceptions if an element with that id was already present.

With these changes, ModelBuilder becomes safer to use for both new and existing models.

Related issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant