From: <raj...@us...> - 2007-06-23 18:12:15
|
Revision: 8386 http://svn.sourceforge.net/cdk/?rev=8386&view=rev Author: rajarshi Date: 2007-06-23 11:12:04 -0700 (Sat, 23 Jun 2007) Log Message: ----------- Converted to typed collections and simplified code since lists now specify the type of object being stored Modified Paths: -------------- trunk/cdk/src/org/openscience/cdk/config/ElementPTFactory.java trunk/cdk/src/org/openscience/cdk/config/elements/ElementPTHandler.java trunk/cdk/src/org/openscience/cdk/config/elements/ElementPTReader.java Modified: trunk/cdk/src/org/openscience/cdk/config/ElementPTFactory.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/config/ElementPTFactory.java 2007-06-23 18:03:27 UTC (rev 8385) +++ trunk/cdk/src/org/openscience/cdk/config/ElementPTFactory.java 2007-06-23 18:12:04 UTC (rev 8386) @@ -23,16 +23,16 @@ */ package org.openscience.cdk.config; +import org.openscience.cdk.PeriodicTableElement; +import org.openscience.cdk.config.elements.ElementPTReader; +import org.openscience.cdk.tools.LoggingTool; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OptionalDataException; import java.util.Vector; -import org.openscience.cdk.PeriodicTableElement; -import org.openscience.cdk.config.elements.ElementPTReader; -import org.openscience.cdk.tools.LoggingTool; - /** * Used to store and return data of a particular chemicalElement. As this class is a * singleton class, one gets an instance with: @@ -48,7 +48,7 @@ { private static ElementPTFactory efac = null; - private Vector elements = null; + private Vector<PeriodicTableElement> elements = null; private boolean debug = false; private LoggingTool logger; @@ -120,20 +120,18 @@ *@param symbol An element symbol to search for *@return An array of element that matches the given element symbol */ - public PeriodicTableElement getElement(String symbol) - { - for (int f = 0; f < elements.size(); f++) - { - if (((PeriodicTableElement) elements.elementAt(f)).getSymbol().equals(symbol)) - try { - return (PeriodicTableElement) ((PeriodicTableElement) elements.elementAt(f)).clone(); - } catch (CloneNotSupportedException e) { - logger.error("Could not clone PeriodicTableElement: ", e.getMessage()); + public PeriodicTableElement getElement(String symbol) { + for (PeriodicTableElement element : elements) { + if (element.getSymbol().equals(symbol)) { + try { + return (PeriodicTableElement) element.clone(); + } catch (CloneNotSupportedException e) { + logger.error("Could not clone PeriodicTableElement: ", e.getMessage()); logger.debug(e); - } - - } - return null; + } + } + } + return null; } /** Modified: trunk/cdk/src/org/openscience/cdk/config/elements/ElementPTHandler.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/config/elements/ElementPTHandler.java 2007-06-23 18:03:27 UTC (rev 8385) +++ trunk/cdk/src/org/openscience/cdk/config/elements/ElementPTHandler.java 2007-06-23 18:12:04 UTC (rev 8386) @@ -23,13 +23,13 @@ */ package org.openscience.cdk.config.elements; -import java.util.Vector; - import org.openscience.cdk.PeriodicTableElement; import org.openscience.cdk.tools.LoggingTool; import org.xml.sax.Attributes; import org.xml.sax.helpers.DefaultHandler; +import java.util.Vector; + /** * Reads an element list in CML2 format. An example definition is: * <pre> @@ -61,7 +61,7 @@ private int scalarType; private LoggingTool logger; private String currentChars; - private Vector elements; + private Vector<PeriodicTableElement> elements; public PeriodicTableElement elementType; public String currentElement; @@ -77,7 +77,7 @@ * * @return A Vector object with all isotopes */ - public Vector getElements() + public Vector<PeriodicTableElement> getElements() { return elements; } @@ -86,7 +86,7 @@ public void startDocument() { - elements = new Vector(); + elements = new Vector<PeriodicTableElement>(); scalarType = SCALAR_UNSET; elementType = null; } Modified: trunk/cdk/src/org/openscience/cdk/config/elements/ElementPTReader.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/config/elements/ElementPTReader.java 2007-06-23 18:03:27 UTC (rev 8385) +++ trunk/cdk/src/org/openscience/cdk/config/elements/ElementPTReader.java 2007-06-23 18:12:04 UTC (rev 8386) @@ -27,15 +27,16 @@ */ package org.openscience.cdk.config.elements; -import java.io.IOException; -import java.io.Reader; -import java.util.Vector; - +import org.openscience.cdk.PeriodicTableElement; import org.openscience.cdk.tools.LoggingTool; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; +import java.io.IOException; +import java.io.Reader; +import java.util.Vector; + /** * Reader that instantiates an XML parser and customized handler to process * the isotope information in the CML2 isotope data file. The Reader first @@ -119,8 +120,8 @@ * @return a Vector of Isotope's. Returns an empty vector is some reading error * occured. */ - public Vector readElements() { - Vector elements = new Vector(); + public Vector<PeriodicTableElement> readElements() { + Vector<PeriodicTableElement> elements = new Vector<PeriodicTableElement>(); try { parser.setFeature("http://xml.org/sax/features/validation", false); logger.info("Deactivated validation"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |