KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > collections > test > serial > TestSerial


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

8 package com.sleepycat.collections.test.serial;
9
10 /**
11  * @see StoredClassCatalogTest
12  * @author Mark Hayes
13  */

14 class TestSerial implements java.io.Serializable JavaDoc {
15
16     static final long serialVersionUID = -3738980000390384920L;
17
18     private int i = 123;
19     private TestSerial other;
20
21     // The following field 's' was added after this class was compiled and
22
// serialized instances were saved in resource files. This allows testing
23
// that the original stored instances can be deserialized after changing
24
// the class. The serialVersionUID is needed for this according to Java
25
// serialization rules, and was generated with the serialver tool.
26
//
27
private String JavaDoc s = "string";
28
29     TestSerial(TestSerial other) {
30
31         this.other = other;
32     }
33
34     TestSerial getOther() {
35
36         return other;
37     }
38
39     int getIntField() {
40
41         return i;
42     }
43
44     String JavaDoc getStringField() {
45
46         return s; // this returned null before field 's' was added.
47
}
48
49     public boolean equals(Object JavaDoc object) {
50
51         try {
52             TestSerial o = (TestSerial) object;
53             if ((o.other == null) ? (this.other != null)
54                                   : (!o.other.equals(this.other))) {
55                 return false;
56             }
57             if (this.i != o.i) {
58                 return false;
59             }
60             // the following test was not done before field 's' was added
61
if ((o.s == null) ? (this.s != null)
62                               : (!o.s.equals(this.s))) {
63                 return false;
64             }
65             return true;
66         } catch (ClassCastException JavaDoc e) {
67             return false;
68         }
69     }
70 }
71
Popular Tags