1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002-2009 Oracle. All rights reserved. 5 * 6 * $Id$ 7 */ 8 9package com.sleepycat.persist.evolve; 10 11import java.io.Serializable; 12 13/** 14 * The base class for all mutations. 15 * 16 * @see com.sleepycat.persist.evolve Class Evolution 17 * @author Mark Hayes 18 */ 19public abstract class Mutation implements Serializable { 20 21 private static final long serialVersionUID = -8094431582953129268L; 22 23 private String className; 24 private int classVersion; 25 private String fieldName; 26 27 Mutation(String className, int classVersion, String fieldName) { 28 this.className = className; 29 this.classVersion = classVersion; 30 this.fieldName = fieldName; 31 } 32 33 /** 34 * Returns the class to which this mutation applies. 35 */ 36 public String getClassName() { 37 return className; 38 } 39 40 /** 41 * Returns the class version to which this mutation applies. 42 */ 43 public int getClassVersion() { 44 return classVersion; 45 } 46 47 /** 48 * Returns the field name to which this mutation applies, or null if this 49 * mutation applies to the class itself. 50 */ 51 public String getFieldName() { 52 return fieldName; 53 } 54 55 /** 56 * Returns true if the class name, class version and field name are equal 57 * in this object and given object. 58 */ 59 @Override 60 public boolean equals(Object other) { 61 if (other instanceof Mutation) { 62 Mutation o = (Mutation) other; 63 return className.equals(o.className) && 64 classVersion == o.classVersion && 65 ((fieldName != null) ? fieldName.equals(o.fieldName) 66 : (o.fieldName == null)); 67 } else { 68 return false; 69 } 70 } 71 72 @Override 73 public int hashCode() { 74 return className.hashCode() + 75 classVersion + 76 ((fieldName != null) ? fieldName.hashCode() : 0); 77 } 78 79 @Override 80 public String toString() { 81 return "Class: " + className + " Version: " + classVersion + 82 ((fieldName != null) ? (" Field: " + fieldName) : ""); 83 } 84} 85