1 16 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 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 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 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 } 102 | Popular Tags |