KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > gp > terminal > Constant


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.gp.terminal;
11
12 import org.jgap.*;
13 import org.jgap.gp.*;
14 import org.jgap.gp.impl.*;
15
16 /**
17  * A constant remaining the same value all time.
18  *
19  * @author Klaus Meffert
20  * @since 3.0
21  */

22 public class Constant
23     extends MathCommand {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.6 $";
26
27   private Object JavaDoc m_value;
28
29   public Constant(final GPConfiguration a_conf, Class JavaDoc a_type, Object JavaDoc a_value)
30       throws InvalidConfigurationException {
31     this(a_conf, a_type, a_value, 0);
32   }
33
34   public Constant(final GPConfiguration a_conf, Class JavaDoc a_type, Object JavaDoc a_value,
35                   int a_subReturnType)
36       throws InvalidConfigurationException {
37     super(a_conf, 0, a_type, a_subReturnType, null);
38     m_value = a_value;
39   }
40
41   public String JavaDoc toString() {
42     return m_value.toString();
43   }
44
45   /**
46    * @return textual name of this command
47    *
48    * @author Klaus Meffert
49    * @since 3.2
50    */

51   public String JavaDoc getName() {
52     return "Constant";
53   }
54
55   public int execute_int(ProgramChromosome c, int n, Object JavaDoc[] args) {
56     return ( (Integer JavaDoc) m_value).intValue();
57   }
58
59   public long execute_long(ProgramChromosome c, int n, Object JavaDoc[] args) {
60     return ( (Long JavaDoc) m_value).intValue();
61   }
62
63   public float execute_float(ProgramChromosome c, int n, Object JavaDoc[] args) {
64     return ( (Float JavaDoc) m_value).floatValue();
65   }
66
67   public double execute_double(ProgramChromosome c, int n, Object JavaDoc[] args) {
68     return ( (Double JavaDoc) m_value).doubleValue();
69   }
70
71   public Object JavaDoc execute_object(ProgramChromosome c, int n, Object JavaDoc[] args) {
72     return m_value;
73   }
74 }
75
Popular Tags