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