1 16 package org.apache.cocoon.portal.pluto.om.common; 17 18 import java.io.IOException ; 19 import java.io.ObjectInputStream ; 20 import java.io.ObjectOutputStream ; 21 22 31 public class ObjectIDImpl 32 implements org.apache.pluto.om.common.ObjectID, java.io.Serializable { 33 34 private String stringOID; 35 private int intOID; 36 37 private ObjectIDImpl (int oid, String stringOID) { 38 this.stringOID = stringOID; 39 intOID = oid; 40 } 41 42 44 private void readObject (ObjectInputStream stream) throws IOException { 45 intOID = stream.readInt (); 46 47 stringOID = String.valueOf (intOID); 48 } 49 50 private void writeObject (ObjectOutputStream stream) throws IOException { 51 stream.write (intOID); 52 } 53 54 55 57 public boolean equals (Object object) { 58 boolean result = false; 59 60 if (object instanceof ObjectIDImpl) { 61 result = (intOID == ((ObjectIDImpl) object).intOID); 62 } else if (object instanceof String ) { 63 result = stringOID.equals (object); 64 } else if (object instanceof Integer ) { 65 result = (intOID == ((Integer )object).intValue()); 66 } 67 return (result); 68 } 69 70 73 public int hashCode () { 74 return intOID; 75 } 76 77 80 public String toString () { 81 return stringOID; 82 } 83 84 public int intValue () { 85 return (intOID); 86 } 87 88 static public ObjectIDImpl createFromString(String idStr) { 89 char[] id = idStr.toCharArray(); 90 int _id = 1; 91 for (int i=0; i<id.length; i++) { 92 if ((i%2)==0) _id *= id[i]; 93 else _id ^= id[i]; 94 _id = Math.abs(_id); 95 } 96 return new ObjectIDImpl(_id, idStr); 97 } 98 } 99 | Popular Tags |