1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.pluto.portalImpl.util;
17
18 import java.io.IOException;
19 import java.io.ObjectInputStream;
20 import java.io.ObjectOutputStream;
21
22 /***
23 ** Wraps around the internal Object IDs. By holding both
24 ** the string and the integer version of an Object ID this class
25 ** helps speed up the internal processing.
26 **/
27
28 public class ObjectID implements org.apache.pluto.om.common.ObjectID, java.io.Serializable
29 {
30
31 private String stringOID;
32 private int intOID;
33
34 private ObjectID (int oid, String stringOID)
35 {
36 this.stringOID = stringOID;
37 intOID = oid;
38 }
39
40
41
42 private void readObject (ObjectInputStream stream) throws IOException, ClassNotFoundException
43 {
44 intOID = stream.readInt ();
45
46 stringOID = String.valueOf (intOID);
47 }
48
49 private void writeObject (ObjectOutputStream stream) throws IOException
50 {
51 stream.write (intOID);
52 }
53
54
55
56
57 public boolean equals (Object object)
58 {
59 boolean result = false;
60
61 if (object instanceof ObjectID)
62 result = (intOID == ((ObjectID) object).intOID);
63 else if (object instanceof String)
64 result = stringOID.equals (object);
65 else if (object instanceof Integer)
66 result = (intOID == ((Integer)object).intValue());
67 return (result);
68 }
69
70 public int hashCode ()
71 {
72 return (intOID);
73 }
74
75 public String toString ()
76 {
77 return (stringOID);
78 }
79
80 public int intValue ()
81 {
82 return (intOID);
83 }
84
85 static public ObjectID createFromString(String idStr)
86 {
87 char[] id = idStr.toCharArray();
88 int _id = 1;
89 for (int i=0; i<id.length; i++)
90 {
91 if ((i%2)==0) _id *= id[i];
92 else _id ^= id[i];
93 _id = Math.abs(_id);
94 }
95 return new ObjectID(_id, idStr);
96 }
97 }