001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.aaproperties.xml;
022
023import javax.xml.bind.annotation.XmlRootElement;
024import java.util.HashMap;
025import java.util.List;
026import java.util.Map;
027
028@XmlRootElement(name="elements", namespace="http://biojava.org")
029public class ElementTable {
030
031        /**
032         * Contain the full list of elements
033         */
034        private List<Element> element;
035
036        /**
037         * Enable quick retrieval of Element from its name
038         */
039        private Map<String, Element> elementName2Element;
040
041        /**
042         * Enable quick retrieval of Isotop from its name
043         */
044        private Map<String, Isotope> isotopeName2Isotope;
045
046        public ElementTable(){}
047
048        public ElementTable(List<Element> eList){
049                this.setElement(eList);
050        }
051
052        public void setElement(List<Element> eList){
053                this.element = eList;
054                populateMaps();
055        }
056
057        /**
058         * Populate the Maps for quick retrieval
059         */
060        public void populateMaps(){
061                this.elementName2Element = new HashMap<String, Element>();
062                this.isotopeName2Isotope = new HashMap<String, Isotope>();
063                if(this.element != null){
064                        for(Element e:this.element){
065                                this.elementName2Element.put(e.getName(), e);
066                                if(e.getIsotopes() != null){
067                                        for(Isotope i:e.getIsotopes()){
068                                                this.isotopeName2Isotope.put(i.getName(), i);
069                                        }
070                                }
071                        }
072                }
073        }
074
075        public List<Element> getElement(){
076                return this.element;
077        }
078
079        public Element getElement(String name){
080                return this.elementName2Element.get(name);
081        }
082
083        public Isotope getIsotope(String name){
084                return this.isotopeName2Isotope.get(name);
085        }
086}