1 8 9 package com.sleepycat.persist.evolve; 10 11 import java.lang.reflect.Method ; 12 13 48 public class Converter extends Mutation { 49 50 private static final long serialVersionUID = 4558176842096181863L; 51 52 private Conversion conversion; 53 54 58 public Converter(String className, 59 int classVersion, 60 Conversion conversion) { 61 this(className, classVersion, null, conversion); 62 } 63 64 69 public Converter(String declaringClassName, 70 int declaringClassVersion, 71 String fieldName, 72 Conversion conversion) { 73 super(declaringClassName, declaringClassVersion, fieldName); 74 this.conversion = conversion; 75 76 77 Class cls = conversion.getClass(); 78 try { 79 Method m = cls.getMethod("equals", Object .class); 80 if (m.getDeclaringClass() == Object .class) { 81 throw new IllegalArgumentException 82 ("Conversion class does not implement the equals method " + 83 "explicitly (Object.equals is not sufficient): " + 84 cls.getName()); 85 } 86 } catch (NoSuchMethodException e) { 87 throw new IllegalStateException (e); 88 } 89 } 90 91 94 public Conversion getConversion() { 95 return conversion; 96 } 97 98 103 @Override 104 public boolean equals(Object other) { 105 if (other instanceof Converter) { 106 Converter o = (Converter) other; 107 return conversion.equals(o.conversion) && 108 super.equals(other); 109 } else { 110 return false; 111 } 112 } 113 114 @Override 115 public int hashCode() { 116 return conversion.hashCode() + super.hashCode(); 117 } 118 119 @Override 120 public String toString() { 121 return "[Converter " + super.toString() + 122 " Conversion: " + conversion + ']'; 123 } 124 } 125 | Popular Tags |