1 10 package org.jgap.gp.function; 11 12 import org.jgap.*; 13 import org.jgap.gp.*; 14 import org.jgap.gp.impl.*; 15 16 22 public class Pop 23 extends MathCommand { 24 25 private final static String CVS_REVISION = "$Revision: 1.6 $"; 26 27 public Pop(final GPConfiguration a_conf, Class a_type) 28 throws InvalidConfigurationException { 29 this(a_conf, a_type, 0); 30 } 31 32 public Pop(final GPConfiguration a_conf, Class a_type, int a_subReturnType) 33 throws InvalidConfigurationException { 34 super(a_conf, 0, a_type, a_subReturnType, null); 35 } 36 37 public String toString() { 38 return "pop &1"; 39 } 40 41 47 public String getName() { 48 return "Pop"; 49 } 50 51 public int execute_int(ProgramChromosome c, int n, Object [] args) { 52 check(c); 53 if (getGPConfiguration().stackSize() < 1) { 56 throw new IllegalStateException ("pop without push"); 57 } 58 return ( (Integer ) getGPConfiguration().popFromStack()). 59 intValue(); 60 } 61 62 public long execute_long(ProgramChromosome c, int n, Object [] args) { 63 check(c); 64 if (getGPConfiguration().stackSize() < 1) { 65 throw new IllegalStateException ("pop without push"); 66 } 67 return ( (Long ) getGPConfiguration().popFromStack()).longValue(); 68 } 69 70 public double execute_double(ProgramChromosome c, int n, Object [] args) { 71 check(c); 72 if (getGPConfiguration().stackSize() < 1) { 73 throw new IllegalStateException ("pop without push"); 74 } 75 return ( (Double ) getGPConfiguration().popFromStack()).doubleValue(); 76 } 77 78 public float execute_float(ProgramChromosome c, int n, Object [] args) { 79 check(c); 80 if (getGPConfiguration().stackSize() < 1) { 81 throw new IllegalStateException ("pop without push"); 82 } 83 return ( (Float ) getGPConfiguration().popFromStack()).floatValue(); 84 } 85 86 public Object execute_object(ProgramChromosome c, int n, Object [] args) { 87 check(c); 88 if (getGPConfiguration().stackSize() < 1) { 89 throw new IllegalStateException ("pop without push"); 90 } 91 return getGPConfiguration().popFromStack(); 92 } 93 94 public boolean isValid(ProgramChromosome a_program) { 95 return a_program.getCommandOfClass(0, Push.class) >= 0; 96 } 97 } 98 | Popular Tags |