KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > persist > evolve > Mutation


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: Mutation.java,v 1.7 2006/10/30 21:14:31 bostic Exp $
7  */

8
9 package com.sleepycat.persist.evolve;
10
11 import java.io.Serializable JavaDoc;
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 JavaDoc {
20
21     private static final long serialVersionUID = -8094431582953129268L;
22
23     private String JavaDoc className;
24     private int classVersion;
25     private String JavaDoc fieldName;
26
27     Mutation(String JavaDoc className, int classVersion, String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc
60     public boolean equals(Object JavaDoc 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 JavaDoc
73     public int hashCode() {
74         return className.hashCode() +
75                classVersion +
76                ((fieldName != null) ? fieldName.hashCode() : 0);
77     }
78
79     @Override JavaDoc
80     public String JavaDoc toString() {
81         return "Class: " + className + " Version: " + classVersion +
82                ((fieldName != null) ? (" Field: " + fieldName) : "");
83     }
84 }
85
Popular Tags