plugins/base1/se.lu.onk/trunk/QPackage/src/qpackage/calculator/Token.java

Code
Comments
Other
Rev Date Author Line
66 09 Feb 06 enell 1 /*
66 09 Feb 06 enell 2  * Created on 26-May-2004
66 09 Feb 06 enell 3  * 
66 09 Feb 06 enell 4  * Token.java is a part of WeightedMerge
66 09 Feb 06 enell 5  * 
66 09 Feb 06 enell 6  * Copyright (C) 2004 Johan Enell, Dept Oncology, Lund University
66 09 Feb 06 enell 7  * 
66 09 Feb 06 enell 8  * This program is free software; you can redistribute it and/or modify it under
66 09 Feb 06 enell 9  * the terms of the GNU General Public License as published by the Free Software
66 09 Feb 06 enell 10  * Foundation; either version 2 of the License, or (at your option) any later
66 09 Feb 06 enell 11  * version.
66 09 Feb 06 enell 12  * 
66 09 Feb 06 enell 13  * This program is distributed in the hope that it will be useful, but WITHOUT
66 09 Feb 06 enell 14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
66 09 Feb 06 enell 15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
66 09 Feb 06 enell 16  * details.
66 09 Feb 06 enell 17  * 
66 09 Feb 06 enell 18  * You should have received a copy of the GNU General Public License along with
66 09 Feb 06 enell 19  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
66 09 Feb 06 enell 20  * Place - Suite 330, Boston, MA 02111-1307, USA.
66 09 Feb 06 enell 21  */
67 10 Feb 06 enell 22 package qpackage.calculator;
66 09 Feb 06 enell 23
66 09 Feb 06 enell 24 import java.util.HashMap;
66 09 Feb 06 enell 25 import java.util.HashSet;
66 09 Feb 06 enell 26
66 09 Feb 06 enell 27 /**
66 09 Feb 06 enell 28  * All members in an equaiton is a Token. A Token holds a value that can be get
66 09 Feb 06 enell 29  * using the getValue() method.
66 09 Feb 06 enell 30  * 
66 09 Feb 06 enell 31  * @author Johan Enell, johan.enell@onk.lu.se, Dept Oncology, Lund University,
66 09 Feb 06 enell 32  *         S-221 85 Lund, Sweden
66 09 Feb 06 enell 33  */
66 09 Feb 06 enell 34 public abstract class Token
66 09 Feb 06 enell 35 {
66 09 Feb 06 enell 36
66 09 Feb 06 enell 37   /**
66 09 Feb 06 enell 38    * Constuctor that creates a new instance of a Token. It does nothing.
66 09 Feb 06 enell 39    */
66 09 Feb 06 enell 40   protected Token()
66 09 Feb 06 enell 41   {}
66 09 Feb 06 enell 42
66 09 Feb 06 enell 43   /**
66 09 Feb 06 enell 44    * Returns the value of this Token. If the Token consists of any unset
66 09 Feb 06 enell 45    * Variable <code>Float.NaN</code> is returned.
66 09 Feb 06 enell 46    * 
66 09 Feb 06 enell 47    * @return the value of this Token.
66 09 Feb 06 enell 48    */
66 09 Feb 06 enell 49   protected abstract float getValue();
66 09 Feb 06 enell 50
66 09 Feb 06 enell 51   /**
66 09 Feb 06 enell 52    * Returns the value of this Token. If the Token contains any variables they
66 09 Feb 06 enell 53    * can be submitted in the <code>HashMap</code> where each element has the
66 09 Feb 06 enell 54    * format (<code>Variable</code> variable, <code>Double</code>,
66 09 Feb 06 enell 55    * value). If the variable is not present <code>Float.NaN</code> is
66 09 Feb 06 enell 56    * returned.
66 09 Feb 06 enell 57    * 
66 09 Feb 06 enell 58    * @param variables
66 09 Feb 06 enell 59    *            The value of each variable as <Variable, value> pairs.
66 09 Feb 06 enell 60    * @return the value of the token or <code>Float.NaN</code> if a variable
66 09 Feb 06 enell 61    *         has no value.
66 09 Feb 06 enell 62    */
66 09 Feb 06 enell 63   protected abstract float getValue(HashMap variables);
66 09 Feb 06 enell 64
66 09 Feb 06 enell 65   /**
66 09 Feb 06 enell 66    * Sets the <code>Variable</code> variable in this Token to value.
66 09 Feb 06 enell 67    * 
66 09 Feb 06 enell 68    * @param variable
66 09 Feb 06 enell 69    *            the variable to be set.
66 09 Feb 06 enell 70    * @param value
66 09 Feb 06 enell 71    *            the value of the variable.
66 09 Feb 06 enell 72    */
66 09 Feb 06 enell 73   protected abstract void setVariable(Variable variable, float value);
66 09 Feb 06 enell 74
66 09 Feb 06 enell 75   /**
66 09 Feb 06 enell 76    * Returns all the Variables in this Token as a <code>HashSet</code>.
66 09 Feb 06 enell 77    * 
66 09 Feb 06 enell 78    * @return the variables.
66 09 Feb 06 enell 79    */
66 09 Feb 06 enell 80   protected abstract HashSet<Variable> getVariables();
66 09 Feb 06 enell 81
66 09 Feb 06 enell 82   /**
66 09 Feb 06 enell 83    * Returns the value of this Token as a <code>double</code>. Creates a
66 09 Feb 06 enell 84    * <code>double</code> of the method <code>float getValue()</code>
66 09 Feb 06 enell 85    * 
66 09 Feb 06 enell 86    * @return the value of this Token as a <code>double</code>.
66 09 Feb 06 enell 87    */
66 09 Feb 06 enell 88   protected double doubleValue()
66 09 Feb 06 enell 89   {
66 09 Feb 06 enell 90     return (new Float(this.getValue())).doubleValue();
66 09 Feb 06 enell 91   }
66 09 Feb 06 enell 92
66 09 Feb 06 enell 93   /**
66 09 Feb 06 enell 94    * Returns the value of this Token as a <code>double</code>. Creates a
66 09 Feb 06 enell 95    * <code>double</code> of the method
66 09 Feb 06 enell 96    * <code>float getValue(HashMap variables)</code>
66 09 Feb 06 enell 97    * 
66 09 Feb 06 enell 98    * @param variables
66 09 Feb 06 enell 99    *            the variable to be set.
66 09 Feb 06 enell 100    * @return the value of this Token as a <code>double</code>.
66 09 Feb 06 enell 101    */
66 09 Feb 06 enell 102   protected double doubleValue(HashMap variables)
66 09 Feb 06 enell 103   {
66 09 Feb 06 enell 104     return (new Float(this.getValue(variables))).doubleValue();
66 09 Feb 06 enell 105   }
66 09 Feb 06 enell 106 }