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 */
021
022/*
023 * Created on December 20, 2000, 7:19 PM
024 */
025
026package org.biojava.bio.symbol;
027
028import java.util.HashMap;
029import java.util.Map;
030
031/**
032 * Class that implements the SymbolPropertyTable interface
033 * @author  Mike Jones (primary author)
034 * @author  David Huen (minor, extended class to cover pK)
035 */
036public class SimpleSymbolPropertyTable implements SymbolPropertyTable {
037
038    //Finite ? 
039    private final Alphabet source;
040    private String name;
041    
042    private final Map doublePropMap;
043    
044    public SimpleSymbolPropertyTable(Alphabet source, String name)
045    {
046        this.source = source;
047        this.name = name;
048        doublePropMap = new HashMap();
049    }
050    
051    public void setDoubleProperty(Symbol s, String value)
052            throws IllegalSymbolException {
053                        
054        source.validate(s);
055        doublePropMap.put(s, new Double(value));
056    }
057
058    public String getName() {
059        return name;
060    }
061    
062    public Alphabet getAlphabet() {
063        return source;
064    }
065  
066    public double getDoubleValue(Symbol s) throws IllegalSymbolException {
067        source.validate(s);
068        
069        Double  value = (Double)doublePropMap.get(s);
070        if(value==null) {
071            throw new IllegalSymbolException(
072                    "Symbol " + s.getName() + " not found in property table " + this.getName());
073        }
074        return  value.doubleValue();
075    }
076}