1 10 package org.jgap.impl; 11 12 import org.jgap.*; 13 14 20 public abstract class NumberGene 21 extends BaseGene { 22 23 private static final String CVS_REVISION = "$Revision: 1.22 $"; 24 25 29 private Object m_value; 30 31 public NumberGene(Configuration a_config) throws InvalidConfigurationException { 32 super(a_config); 33 } 34 35 50 public int compareTo(final Object a_other) { 51 NumberGene otherGene = (NumberGene) a_other; 52 if (otherGene == null) { 57 return 1; 58 } 59 else if (otherGene.m_value == null) { 60 if (!otherGene.getClass().equals(getClass())) { 64 throw new ClassCastException ( 65 "Comparison not possible: different types!"); 66 } 67 if (m_value == null) { 71 if (isCompareApplicationData()) { 72 return compareApplicationData(getApplicationData(), 73 otherGene.getApplicationData()); 74 } 75 else { 76 return 0; 77 } 78 } 79 else { 80 return 1; 81 } 82 } 83 else { 84 try { 85 if (!otherGene.getClass().equals(getClass())) { 86 throw new ClassCastException ( 87 "Comparison not possible: different types!"); 88 } 89 if (m_value == null) { 90 return -1; 91 } 92 int res = compareToNative(m_value, otherGene.m_value); 93 if (res == 0) { 94 if (isCompareApplicationData()) { 95 return compareApplicationData(getApplicationData(), 96 otherGene.getApplicationData()); 97 } 98 else { 99 return 0; 100 } 101 } 102 else { 103 return res; 104 } 105 } 106 catch (ClassCastException e) { 107 throw e; 108 } 109 } 110 } 111 112 124 protected abstract int compareToNative(Object a_o1, Object a_o2); 125 126 137 public void setAllele(final Object a_newValue) { 138 if (getConstraintChecker() != null) { 139 if (!getConstraintChecker().verify(this, a_newValue, null, -1)) { 140 return; 141 } 142 } 143 m_value = a_newValue; 144 mapValueToWithinBounds(); 148 } 149 150 162 protected abstract void mapValueToWithinBounds(); 163 164 protected Object getInternalValue() { 165 return m_value; 166 } 167 } 168 | Popular Tags |