01: /*
02: * Created on 22 juin 2005
03: */
04: package abook.data;
05:
06: /**
07: * This class provides an objectId (i.e. identifier) for the Acquisition class
08: */
09: public class AcquisitionId {
10:
11: public static final String SEP = ":";
12: // 1) public fields
13: public long book_id;
14: public String user_id;
15:
16: // 2) empty constructor
17: public AcquisitionId() {
18: }
19:
20: public AcquisitionId(long a, String b) {
21: this .book_id = a;
22: this .user_id = b;
23: }
24:
25: // 4) constructor with a string parameter
26: public AcquisitionId(String str) {
27: setValue(str);
28: }
29:
30: private void setValue(String str) {
31: if (str == null) {
32: throw new NullPointerException(
33: "String representation of MyClass Identifier is null");
34: }
35: int idx = str.indexOf(SEP);
36: if (idx == -1) {
37: throw new NullPointerException(
38: "Bad String representation of MyClass Identifier: "
39: + str);
40: }
41: book_id = new Long(str.substring(0, idx)).longValue();
42: user_id = str.substring(idx + SEP.length());
43: }
44:
45: // 3) toString()
46: public String toString() {
47: return book_id + SEP + user_id;
48: }
49:
50: // 3) implement your own hashCode() method
51: public int hashCode() {
52: return 0;
53: }
54:
55: // 3) implement your own equals method
56: public boolean equals(Object o) {
57: if (!(o instanceof AcquisitionId)) {
58: return false;
59: }
60: AcquisitionId oCompare = (AcquisitionId) o;
61: return (book_id == oCompare.book_id)
62: && (user_id.equals(oCompare.user_id));
63: }
64: }
|