1 7 8 package com.sun.corba.se.impl.ior; 9 10 import java.util.Arrays ; 11 12 import org.omg.CORBA_2_3.portable.InputStream ; 13 import org.omg.CORBA_2_3.portable.OutputStream ; 14 15 import com.sun.corba.se.spi.ior.Identifiable ; 16 17 21 public abstract class GenericIdentifiable implements Identifiable 22 { 23 private int id; 24 private byte data[]; 25 26 public GenericIdentifiable(int id, InputStream is) 27 { 28 this.id = id ; 29 data = EncapsulationUtility.readOctets( is ) ; 30 } 31 32 public int getId() 33 { 34 return id ; 35 } 36 37 public void write(OutputStream os) 38 { 39 os.write_ulong( data.length ) ; 40 os.write_octet_array( data, 0, data.length ) ; 41 } 42 43 public String toString() 44 { 45 return "GenericIdentifiable[id=" + getId() + "]" ; 46 } 47 48 public boolean equals(Object obj) 49 { 50 if (obj == null) 51 return false ; 52 53 if (!(obj instanceof GenericIdentifiable)) 54 return false ; 55 56 GenericIdentifiable encaps = (GenericIdentifiable)obj ; 57 58 return (getId() == encaps.getId()) && 59 Arrays.equals( getData(), encaps.getData() ) ; 60 } 61 62 public int hashCode() 63 { 64 int result = 17 ; 65 for (int ctr=0; ctr<data.length; ctr++ ) 66 result = 37*result + data[ctr] ; 67 return result ; 68 } 69 70 public GenericIdentifiable(int id, byte[] data) 71 { 72 this.id = id ; 73 this.data = (byte[])(data.clone()) ; 74 } 75 76 public byte[] getData() 77 { 78 return data ; 79 } 80 } 81 | Popular Tags |