Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (22 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libjava/java/rmi/MarshalledObject.java

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    3939
    4040import java.io.Serializable;
     41
     42
     43
     44
    4145
     46
     47
     48
    4249public final class MarshalledObject
    43         extends Object implements Serializable {
     50  extends Object implements Serializable
     51{
     52 
     53  //The following fields are from Java API Documentation "Serialized form"
     54  private static final long serialVersionUID = 8988374069173025854L;
     55  byte[] objBytes;
     56  byte[] locBytes;
     57  int hash;
     58 
     59  public MarshalledObject(Object obj) throws java.io.IOException
     60  {
     61    ByteArrayOutputStream objStream = new ByteArrayOutputStream();
     62    RMIMarshalledObjectOutputStream stream = new RMIMarshalledObjectOutputStream(objStream);
     63    stream.writeObject(obj);
     64    stream.flush();
     65    objBytes = objStream.toByteArray();
     66    locBytes = stream.getLocBytes();
     67   
     68    //The following algorithm of calculating hashCode is similar to String
     69    hash = 0;
     70    for (int i = 0; i < objBytes.length; i++)
     71      hash = hash * 31 + objBytes[i];
     72    if(locBytes != null)
     73      for (int i = 0; i < locBytes.length; i++)
     74        hash = hash * 31 + locBytes[i];
     75  }
     76 
     77  public boolean equals(Object obj)
     78  {
     79    if(obj == null || !(obj instanceof MarshalledObject) )
     80      return false;
    4481
    45 public MarshalledObject(Object obj) {
    46         throw new Error("Not implemented");
     82    // hashCode even differs, don't do the time-consuming comparisons
     83    if (obj.hashCode() != hash)
     84      return false;
     85   
     86    MarshalledObject aobj = (MarshalledObject)obj;
     87    if (objBytes == null || aobj.objBytes == null)
     88      return objBytes == aobj.objBytes;
     89    if (objBytes.length != aobj.objBytes.length)
     90      return false;
     91    for (int i = 0; i < objBytes.length; i++)
     92      {
     93        if (objBytes[i] != aobj.objBytes[i])
     94          return false;
     95      }
     96    // Ignore comparison of locBytes(annotation)
     97    return true;
     98  }
     99 
     100public Object get()
     101  throws java.io.IOException, java.lang.ClassNotFoundException
     102{
     103  if(objBytes == null)
     104    return null;
     105  RMIMarshalledObjectInputStream stream =
     106    new RMIMarshalledObjectInputStream(objBytes, locBytes);
     107  return stream.readObject();
    47108}
    48 
    49 public boolean equals(Object obj) {
    50         throw new Error("Not implemented");
     109 
     110  public int hashCode() {
     111    return hash;
     112  }
     113 
    51114}
    52 
    53 public Object get() {
    54         throw new Error("Not implemented");
    55 }
    56 
    57 public int hashCode() {
    58         throw new Error("Not implemented");
    59 }
    60 
    61 }
Note: See TracChangeset for help on using the changeset viewer.