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