1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2000, 2013 Oracle and/or its affiliates.  All rights reserved.
5  *
6  */
7 package com.sleepycat.collections.test.serial;
8 
9 /**
10  * @see StoredClassCatalogTest
11  * @author Mark Hayes
12  */
13 class TestSerial implements java.io.Serializable {
14 
15     static final long serialVersionUID = -3738980000390384920L;
16 
17     private int i = 123;
18     private TestSerial other;
19 
20     // The following field 's' was added after this class was compiled and
21     // serialized instances were saved in resource files.  This allows testing
22     // that the original stored instances can be deserialized after changing
23     // the class.  The serialVersionUID is needed for this according to Java
24     // serialization rules, and was generated with the serialver tool.
25     //
26     private String s = "string";
27 
TestSerial(TestSerial other)28     TestSerial(TestSerial other) {
29 
30         this.other = other;
31     }
32 
getOther()33     TestSerial getOther() {
34 
35         return other;
36     }
37 
getIntField()38     int getIntField() {
39 
40         return i;
41     }
42 
getStringField()43     String getStringField() {
44 
45         return s; // this returned null before field 's' was added.
46     }
47 
equals(Object object)48     public boolean equals(Object object) {
49 
50         try {
51             TestSerial o = (TestSerial) object;
52             if ((o.other == null) ? (this.other != null)
53                                   : (!o.other.equals(this.other))) {
54                 return false;
55             }
56             if (this.i != o.i) {
57                 return false;
58             }
59             // the following test was not done before field 's' was added
60             if ((o.s == null) ? (this.s != null)
61                               : (!o.s.equals(this.s))) {
62                 return false;
63             }
64             return true;
65         } catch (ClassCastException e) {
66             return false;
67         }
68     }
69 }
70