1 10 package org.jgap.gp.terminal; 11 12 import org.jgap.*; 13 import org.jgap.gp.*; 14 import org.jgap.gp.impl.*; 15 16 22 public class Constant 23 extends MathCommand { 24 25 private final static String CVS_REVISION = "$Revision: 1.6 $"; 26 27 private Object m_value; 28 29 public Constant(final GPConfiguration a_conf, Class a_type, Object a_value) 30 throws InvalidConfigurationException { 31 this(a_conf, a_type, a_value, 0); 32 } 33 34 public Constant(final GPConfiguration a_conf, Class a_type, Object 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 toString() { 42 return m_value.toString(); 43 } 44 45 51 public String getName() { 52 return "Constant"; 53 } 54 55 public int execute_int(ProgramChromosome c, int n, Object [] args) { 56 return ( (Integer ) m_value).intValue(); 57 } 58 59 public long execute_long(ProgramChromosome c, int n, Object [] args) { 60 return ( (Long ) m_value).intValue(); 61 } 62 63 public float execute_float(ProgramChromosome c, int n, Object [] args) { 64 return ( (Float ) m_value).floatValue(); 65 } 66 67 public double execute_double(ProgramChromosome c, int n, Object [] args) { 68 return ( (Double ) m_value).doubleValue(); 69 } 70 71 public Object execute_object(ProgramChromosome c, int n, Object [] args) { 72 return m_value; 73 } 74 } 75 | Popular Tags |