01: // Space4J(TM) - Object Persistence in RAM
02: // Copyright (C) 2003 Sergio Oliveira Junior
03: // This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
04: package org.space4j.demos.phonebook;
05:
06: import java.io.*;
07: import java.util.*;
08:
09: /**
10: * This is a mutable version of a phone book record.
11: * This will illustrate how you can use an Observable to
12: * notify the IndexManager about changes, so it can reindex the object.
13: */
14: public class PhoneBookRecord extends Observable implements Serializable {
15:
16: private int oid = -1;
17: private String name = null;
18: private String number = null;
19:
20: public PhoneBookRecord(int oid) {
21: super ();
22: this .oid = oid;
23: }
24:
25: public int hashCode() {
26: return oid;
27: }
28:
29: public boolean equals(Object obj) {
30: if (obj instanceof PhoneBookRecord) {
31: PhoneBookRecord pbr = (PhoneBookRecord) obj;
32: if (pbr.oid == this .oid)
33: return true;
34: }
35: return false;
36: }
37:
38: public void setName(String name) {
39: this .name = name;
40: setChanged();
41: notifyObservers("name");
42: }
43:
44: public void setNumber(String number) {
45: this .number = number;
46: setChanged();
47: notifyObservers("number");
48: }
49:
50: public int getId() {
51: return oid;
52: }
53:
54: public String getName() {
55: return name;
56: }
57:
58: public String getNumber() {
59: return number;
60: }
61:
62: public String toString() {
63: return oid + "/" + name + "/" + number;
64: }
65: }
|