01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.container.om.common;
07:
08: import java.io.Serializable;
09:
10: import org.apache.pluto.om.common.ObjectID;
11:
12: /**
13: * Wraps around the internal Object IDs. By holding both
14: * the string and the integer version of an Object ID this class
15: * helps speed up the internal processing. Code copied from Apache Pluto.
16: * @author Ken Weiner, kweiner@unicon.net
17: * @version $Revision: 34757 $
18: */
19: public class ObjectIDImpl implements ObjectID, Serializable {
20:
21: private String stringOID = null;
22: private int intOID;
23:
24: private ObjectIDImpl(int oid) {
25: stringOID = String.valueOf(oid);
26: intOID = oid;
27: }
28:
29: private ObjectIDImpl(int oid, String stringOID) {
30: this .stringOID = stringOID;
31: intOID = oid;
32: }
33:
34: // Addtional methods
35:
36: public boolean equals(Object object) {
37: boolean result = false;
38:
39: if (object instanceof ObjectID)
40: result = (intOID == ((ObjectIDImpl) object).intOID);
41: else if (object instanceof String)
42: result = stringOID.equals(object);
43: else if (object instanceof Integer)
44: result = (intOID == ((Integer) object).intValue());
45: return result;
46: }
47:
48: public int hashCode() {
49: return intOID;
50: }
51:
52: public String toString() {
53: return stringOID;
54: }
55:
56: public int intValue() {
57: return intOID;
58: }
59:
60: static public ObjectID createFromString(String idStr) {
61: char[] id = idStr.toCharArray();
62: int _id = 1;
63: for (int i = 0; i < id.length; i++) {
64: if ((i % 2) == 0)
65: _id *= id[i];
66: else
67: _id ^= id[i];
68: _id = Math.abs(_id);
69: }
70: return new ObjectIDImpl(_id, idStr);
71: }
72: }
|