From: <and...@us...> - 2012-06-12 06:21:38
|
Revision: 1301 http://jsbml.svn.sourceforge.net/jsbml/?rev=1301&view=rev Author: andreas-draeger Date: 2012-06-12 06:21:26 +0000 (Tue, 12 Jun 2012) Log Message: ----------- Added several convenient methods and avoided null pointer exceptions when dealing with user objects. Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/AbstractTreeNode.java trunk/core/src/org/sbml/jsbml/SBO.java trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/CompartmentGlyph.java trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/Layout.java trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/ReactionGlyph.java trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/SpeciesGlyph.java trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/SpeciesReferenceGlyph.java trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/TextGlyph.java Modified: trunk/core/src/org/sbml/jsbml/AbstractTreeNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/AbstractTreeNode.java 2012-06-11 19:29:10 UTC (rev 1300) +++ trunk/core/src/org/sbml/jsbml/AbstractTreeNode.java 2012-06-12 06:21:26 UTC (rev 1301) @@ -61,6 +61,7 @@ * @return the index of the child in the parent's list of children or -1 if no * such child can be found. */ + @SuppressWarnings("unchecked") public static int indexOf(TreeNode parent, TreeNode child) { if (child == null) { throw new IllegalArgumentException("Argument is null."); @@ -249,7 +250,7 @@ */ //@Override public boolean containsUserObjectKey(Object key) { - return userObjects.containsKey(key); + return isSetUserObjects() ? userObjects.containsKey(key) : false; } /* (non-Javadoc) Modified: trunk/core/src/org/sbml/jsbml/SBO.java =================================================================== --- trunk/core/src/org/sbml/jsbml/SBO.java 2012-06-11 19:29:10 UTC (rev 1300) +++ trunk/core/src/org/sbml/jsbml/SBO.java 2012-06-12 06:21:26 UTC (rev 1301) @@ -700,6 +700,15 @@ return 534; } + /** + * Physical compartment. + * + * @return + */ + public static int getCompartment() { + return 290; + } + /** * * @return Modified: trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/CompartmentGlyph.java =================================================================== --- trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/CompartmentGlyph.java 2012-06-11 19:29:10 UTC (rev 1300) +++ trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/CompartmentGlyph.java 2012-06-12 06:21:26 UTC (rev 1301) @@ -94,14 +94,6 @@ public String getCompartment() { return getNamedSBase(); } - - /* (non-Javadoc) - * @see org.sbml.jsbml.ext.layout.NamedSBaseGlyph#getNamedSBaseInstance() - */ - @Override - public Compartment getNamedSBaseInstance() { - return (Compartment) super.getNamedSBaseInstance(); - } /** * @return Modified: trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/Layout.java =================================================================== --- trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/Layout.java 2012-06-11 19:29:10 UTC (rev 1300) +++ trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/Layout.java 2012-06-12 06:21:26 UTC (rev 1301) @@ -479,6 +479,14 @@ return null; } + /** + * + * @return + */ + public int getAdditionalGraphicalObjectCount() { + return isSetListOfAdditionalGraphicalObjects() ? listOfAdditionalGraphicalObjects.size() : 0; + } + /* (non-Javadoc) * @see org.sbml.jsbml.AbstractSBase#getChildAt(int) */ @@ -531,7 +539,7 @@ throw new IndexOutOfBoundsException(String.format("Index %d >= %d", index, +((int) Math.min(pos, 0)))); } - + /* (non-Javadoc) * @see org.sbml.jsbml.AbstractSBase#getChildCount() */ @@ -558,7 +566,7 @@ } return count; } - + /** * * @param i @@ -567,7 +575,7 @@ public CompartmentGlyph getCompartmentGlyph(int i) { return getListOfCompartmentGlyphs().get(i); } - + /** * * @param id @@ -584,10 +592,19 @@ * * @return */ + public int getCompartmentGlyphCount() { + return isSetListOfCompartmentGlyphs() ? listOfCompartmentGlyphs.size() : 0; + } + + /** + * + * @return + */ public Dimensions getDimensions() { return dimensions; } - + + /** * * @return @@ -599,7 +616,7 @@ } return listOfAdditionalGraphicalObjects; } - + /** * * @return @@ -611,7 +628,6 @@ } return listOfCompartmentGlyphs; } - /** * @@ -624,7 +640,7 @@ } return listOfReactionGlyphs; } - + /** * * @return @@ -669,16 +685,24 @@ } return null; } - + /** * + * @return + */ + public int getReactionGlyphCount() { + return isSetListOfReactionGlyphs() ? listOfReactionGlyphs.size() : 0; + } + + /** + * * @param i * @return */ public SpeciesGlyph getSpeciesGlyph(int i) { return getListOfSpeciesGlyphs().get(i); } - + /** * * @param id @@ -690,16 +714,24 @@ } return null; } - + /** * + * @return + */ + public int getSpeciesGlyphCount() { + return isSetListOfSpeciesGlyphs() ? listOfSpeciesGlyphs.size() : 0; + } + + /** + * * @param i * @return */ public TextGlyph getTextGlyph(int i) { return getListOfTextGlyphs().get(i); } - + /** * * @param id @@ -711,14 +743,22 @@ } return null; } - + /** * + * @return */ + public int getTextGlyphCount() { + return isSetListOfTextGlyphs() ? listOfTextGlyphs.size() : 0; + } + + /** + * + */ private void initDefault() { addNamespace(LayoutConstants.namespaceURI); } - + /* (non-Javadoc) * @see org.sbml.jsbml.NamedSBase#isIdMandatory() */ @@ -726,21 +766,21 @@ // See "Including Layout Information in SBML Files" Version 2.2, p. 6 return true; } - + /** * @return */ public boolean isSetAddGraphicalObjects() { return (listOfAdditionalGraphicalObjects != null) && (listOfAdditionalGraphicalObjects.size() > 0); } - + /** * @return */ public boolean isSetDimensions() { return dimensions != null; } - + /** * @return */ @@ -769,14 +809,14 @@ public boolean isSetListOfSpeciesGlyphs() { return (listOfSpeciesGlyphs != null) && (listOfSpeciesGlyphs.size() > 0); } - + /** * @return */ public boolean isSetListOfTextGlyphs() { return (listOfTextGlyphs != null) && (listOfTextGlyphs.size() > 0); } - + /** * @param attributeName * @param prefix @@ -814,7 +854,7 @@ this.dimensions = dimensions; registerChild(this.dimensions); } - + /** * * @param AdditionalGraphicalObjects @@ -827,7 +867,7 @@ registerChild(this.listOfAdditionalGraphicalObjects); } } - + /** * * @param compartmentGlyphs @@ -840,7 +880,7 @@ } registerChild(this.listOfCompartmentGlyphs); } - + /** * * @param reactionGlyphs @@ -853,7 +893,7 @@ registerChild(this.listOfReactionGlyphs); } } - + /** * * @param speciesGlyphs @@ -870,7 +910,7 @@ registerChild(this.listOfSpeciesGlyphs); } } - + /** * * @param textGlyphs @@ -883,7 +923,7 @@ registerChild(this.listOfTextGlyphs); } } - + /* (non-Javadoc) * @see org.sbml.jsbml.AbstractNamedSBase#toString() */ @@ -891,7 +931,7 @@ public String toString() { return getElementName(); } - + /** * Removes the {@link #listOfAdditionalGraphicalObjects} from this {@link Model} and notifies * all registered instances of {@link TreeNodeChangeListener}. @@ -925,7 +965,7 @@ } return false; } - + /** * Removes the {@link #listOfReactionGlyphs} from this {@link Model} and notifies * all registered instances of {@link TreeNodeChangeListener}. @@ -959,7 +999,7 @@ } return false; } - + /** * Removes the {@link #listOfTextGlyphs} from this {@link Model} and notifies * all registered instances of {@link TreeNodeChangeListener}. Modified: trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/ReactionGlyph.java =================================================================== --- trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/ReactionGlyph.java 2012-06-11 19:29:10 UTC (rev 1300) +++ trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/ReactionGlyph.java 2012-06-12 06:21:26 UTC (rev 1301) @@ -205,14 +205,6 @@ return listOfSpeciesReferencesGlyph; } - /* (non-Javadoc) - * @see org.sbml.jsbml.ext.layout.NamedSBaseGlyph#getNamedSBaseInstance() - */ - @Override - public Reaction getNamedSBaseInstance() { - return (Reaction) super.getNamedSBaseInstance(); - } - /** * * @return @@ -331,7 +323,7 @@ Map<String, String> attributes = super.writeXMLAttributes(); if (isSetReaction()) { - attributes.put(LayoutConstants.shortLabel + ":" + attributes.put(LayoutConstants.shortLabel + ':' + LayoutConstants.reaction, getReaction()); } Modified: trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/SpeciesGlyph.java =================================================================== --- trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/SpeciesGlyph.java 2012-06-11 19:29:10 UTC (rev 1300) +++ trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/SpeciesGlyph.java 2012-06-12 06:21:26 UTC (rev 1301) @@ -87,14 +87,6 @@ public SpeciesGlyph clone() { return new SpeciesGlyph(this); } - - /* (non-Javadoc) - * @see org.sbml.jsbml.ext.layout.NamedSBaseGlyph#getNamedSBaseInstance() - */ - @Override - public Species getNamedSBaseInstance() { - return (Species) super.getNamedSBaseInstance(); - } /** * Modified: trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/SpeciesReferenceGlyph.java =================================================================== --- trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/SpeciesReferenceGlyph.java 2012-06-11 19:29:10 UTC (rev 1300) +++ trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/SpeciesReferenceGlyph.java 2012-06-12 06:21:26 UTC (rev 1301) @@ -179,14 +179,6 @@ return curve; } - /* (non-Javadoc) - * @see org.sbml.jsbml.ext.layout.NamedSBaseGlyph#getNamedSBaseInstance() - */ - @Override - public SimpleSpeciesReference getNamedSBaseInstance() { - return (SimpleSpeciesReference) super.getNamedSBaseInstance(); - } - /** * * @return @@ -356,15 +348,15 @@ Map<String, String> attributes = super.writeXMLAttributes(); if (isSetSpeciesGlyph()) { - attributes.put(LayoutConstants.shortLabel + ":" + attributes.put(LayoutConstants.shortLabel + ':' + LayoutConstants.speciesGlyph, speciesGlyph); } if (isSetSpeciesReference()) { - attributes.put(LayoutConstants.shortLabel + ":" + attributes.put(LayoutConstants.shortLabel + ':' + LayoutConstants.speciesReference, getSpeciesReference()); } if (isSetSpeciesReferenceRole()) { - attributes.put(LayoutConstants.shortLabel + ":" + attributes.put(LayoutConstants.shortLabel + ':' + LayoutConstants.role, role.toString().toLowerCase()); } Modified: trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/TextGlyph.java =================================================================== --- trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/TextGlyph.java 2012-06-11 19:29:10 UTC (rev 1300) +++ trunk/extensions/layout/src/org/sbml/jsbml/ext/layout/TextGlyph.java 2012-06-12 06:21:26 UTC (rev 1301) @@ -285,15 +285,15 @@ Map<String, String> attributes = super.writeXMLAttributes(); if (isSetGraphicalObject()) { - attributes.put(LayoutConstants.shortLabel + ":" + attributes.put(LayoutConstants.shortLabel + ':' + LayoutConstants.graphicalObject, graphicalObject); } if (isSetText()) { - attributes.put(LayoutConstants.shortLabel + ":" + attributes.put(LayoutConstants.shortLabel + ':' + LayoutConstants.text, text); } if (isSetOriginOfText()) { - attributes.put(LayoutConstants.shortLabel + ":" + attributes.put(LayoutConstants.shortLabel + ':' + LayoutConstants.originOfText, getOriginOfText()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |