Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: exptree/utilities/variablePackage.java


1   /* Evolvo - Image Generator
2    * Copyright (C) 2000 Andrew Molloy
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU General Public License
6    * as published by the Free Software Foundation; either version 2
7    * of the License, or (at your option) any later version.
8   
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13  
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   */
18  
19  /*
20   * @(#)variablePackage.java   0.1   08/19/2000
21   */
22  package exptree.utilities;
23  
24  import exptree.variable;
25  import java.io.Serializable;
26  
27  /**
28   * Keeps a list of variables available for use in an expressionTree.
29   *
30   * To Do: put variables in a HashTable and allow the definition of variables.
31   *
32   * @version 1.1 08/19/2000
33   * @author Andy Molloy
34   */
35  public class variablePackage implements Serializable
36  {
37     /** Stores the variables. */
38     variable vars[] = new variable[5];
39     
40     /** Creates instances for each variable in the package. */
41     public variablePackage()
42     {
43        vars[0] = new variable(0.0, "x");
44        vars[1] = new variable(0.0, "y");
45        vars[2] = new variable(0.0, "r");
46        vars[3] = new variable(0.0, "theta");
47        vars[4] = new variable(1.0, "t");
48     }
49  
50     /** Returns the variables available for use. */
51     public variable[] getVariables()
52     {
53        return vars;
54     }
55  
56     /** Returns a variable by its name. */
57     public variable getVariable(String which)
58     {
59        if ( which.equals("x") )
60        {
61           return vars[0];
62        }
63        if ( which.equals("y") )
64        {
65           return vars[1];
66        }
67        if ( which.equals("r") )
68        {
69           return vars[2];
70        }
71        if ( which.equals("theta"))
72        {
73           return vars[3];
74        }
75        return vars[4];
76     }
77  }