01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: Mutation.java,v 1.7.2.2 2008/01/07 15:14:19 cwl Exp $
07: */
08:
09: package com.sleepycat.persist.evolve;
10:
11: import 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: */
19: public 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
66: .equals(o.fieldName)
67: : (o.fieldName == null));
68: } else {
69: return false;
70: }
71: }
72:
73: @Override
74: public int hashCode() {
75: return className.hashCode() + 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: }
|