1 10 package org.jgap.impl; 11 12 import org.jgap.*; 13 import org.jgap.util.*; 14 import java.io.*; 15 16 23 public class DefaultCompareToHandler 24 implements ICompareToHandler, ICloneable, Serializable, Comparable { 25 26 private static final String CVS_REVISION = "$Revision: 1.6 $"; 27 28 public boolean isHandlerFor(final Object a_obj, final Class a_clazz) { 29 Class clazz; 30 if (a_clazz == null) { 31 if (a_obj == null) { 32 return false; 33 } 34 clazz = a_obj.getClass(); 35 } 36 else { 37 clazz = a_clazz; 38 } 39 if (Comparable .class.isAssignableFrom(clazz)) { 40 return true; 41 } 42 else { 43 if (clazz != null && Boolean .class == clazz) { 44 return true; 45 } 46 else { 47 return false; 48 } 49 } 50 } 51 52 public Object perform(final Object a_obj, final Class a_class, 53 final Object a_params) 54 throws Exception { 55 int i; 56 if (a_obj == null) { 57 if (a_params != null) { 58 i = -1; 59 } 60 else { 61 i = 0; 62 } 63 } 64 else if (a_params == null) { 65 i = 1; 66 } 67 else { 68 if (a_obj.getClass() == Boolean .class) { 69 boolean b1 = ( (Boolean ) a_obj).booleanValue(); 70 boolean b2 = ( (Boolean ) a_params).booleanValue(); 71 if (b1 == b2) { 72 i = 0; 73 } 74 else if (b1) { 75 i = 1; 76 } 77 else 78 i = -1; 79 } 80 else { 81 i = ( (Comparable ) a_obj).compareTo(a_params); 82 } 83 } 84 return new Integer (i); 85 } 86 87 93 public Object clone() { 94 return new DefaultCompareToHandler(); 95 } 96 97 104 public int compareTo(Object a_other) { 105 if (a_other.getClass().equals(getClass())) { 106 return 0; 107 } 108 else { 109 return getClass().getName().compareTo(a_other.getClass().getName()); 110 } 111 } 112 } 113 | Popular Tags |