/[classpath]/classpath/java/lang/reflect/Proxy.java
ViewVC logotype

Diff of /classpath/java/lang/reflect/Proxy.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by mark, Thu Oct 10 12:52:47 2002 UTC revision 1.6 by mark, Fri Oct 25 22:32:35 2002 UTC
# Line 462  public class Proxy implements Serializab Line 462  public class Proxy implements Serializab
462    private static native Class generateProxyClass0(ClassLoader loader,    private static native Class generateProxyClass0(ClassLoader loader,
463                                                    ProxyData data);                                                    ProxyData data);
464    
   
465    /**    /**
466     * Helper class for mapping unique ClassLoader and interface combinations     * Helper class for mapping unique ClassLoader and interface combinations
467     * to proxy classes.     * to proxy classes.
# Line 490  public class Proxy implements Serializab Line 489  public class Proxy implements Serializab
489       */       */
490      ProxyType(ClassLoader loader, Class[] interfaces)      ProxyType(ClassLoader loader, Class[] interfaces)
491      {      {
492          if (loader == null)
493             loader = ClassLoader.getSystemClassLoader();
494        this.loader = loader;        this.loader = loader;
495        this.interfaces = interfaces;        this.interfaces = interfaces;
496      }      }
# Line 501  public class Proxy implements Serializab Line 502  public class Proxy implements Serializab
502       */       */
503      public int hashCode()      public int hashCode()
504      {      {
505        int hash = (loader == null) ? 0 : loader.hashCode();        //loader is always not null
506          int hash = loader.hashCode();
507        for (int i = 0; i < interfaces.length; i++)        for (int i = 0; i < interfaces.length; i++)
508          hash = hash * 31 + interfaces[i].hashCode();          hash = hash * 31 + interfaces[i].hashCode();
509        return hash;        return hash;
510      }      }
511    
512        // A more comprehensive comparison of two arrays,
513        //   ignore array element order, and
514        //   ignore redundant elements
515        private static boolean sameTypes(Class arr1[], Class arr2[]) {
516          if (arr1.length == 1 && arr2.length == 1) {
517            return arr1[0] == arr2[0];
518          }
519            
520          // total occurrance of elements of arr1 in arr2
521          int total_occ_of_arr1_in_arr2 = 0;
522        each_type:
523          for (int i = arr1.length; --i >= 0; )
524          {
525            Class t = arr1[i];
526            for (int j = i; --j >= 0; )
527            {
528              if (t == arr1[j])
529              { //found duplicate type
530                continue each_type;  
531              }
532            }
533                
534            // count c(a unique element of arr1)'s
535            //   occurrences in arr2
536            int occ_in_arr2 = 0;
537            for (int j = arr2.length; --j >= 0; )
538            {
539              if (t == arr2[j])
540              {
541                ++occ_in_arr2;
542              }
543            }
544            if (occ_in_arr2 == 0)
545            { // t does not occur in arr2
546              return false;
547            }
548            
549            total_occ_of_arr1_in_arr2 += occ_in_arr2;
550          }
551          // now, each element of arr2 must have been visited
552          return total_occ_of_arr1_in_arr2 == arr2.length;
553        }
554    
555      /**      /**
556       * Calculates equality.       * Calculates equality.
557       *       *
# Line 518  public class Proxy implements Serializab Line 563  public class Proxy implements Serializab
563        ProxyType pt = (ProxyType) other;        ProxyType pt = (ProxyType) other;
564        if (loader != pt.loader || interfaces.length != pt.interfaces.length)        if (loader != pt.loader || interfaces.length != pt.interfaces.length)
565          return false;          return false;
566        int i = interfaces.length;            return sameTypes(interfaces, pt.interfaces);
       while (--i >= 0)  
         if (interfaces[i] != pt.interfaces[i])  
           return false;  
       return true;  
567      }      }
568    } // class ProxyType    } // class ProxyType
569    
   
570    /**    /**
571     * Helper class which allows hashing of a method name and signature     * Helper class which allows hashing of a method name and signature
572     * without worrying about return type, declaring class, or throws clause,     * without worrying about return type, declaring class, or throws clause,
# Line 681  public class Proxy implements Serializab Line 721  public class Proxy implements Serializab
721      }      }
722    } // class ProxySignature    } // class ProxySignature
723    
   
724    /**    /**
725     * A flat representation of all data needed to generate bytecode/instantiate     * A flat representation of all data needed to generate bytecode/instantiate
726     * a proxy class.  This is basically a struct.     * a proxy class.  This is basically a struct.
# Line 820  public class Proxy implements Serializab Line 859  public class Proxy implements Serializab
859      }      }
860    } // class ProxyData    } // class ProxyData
861    
   
862    /**    /**
863     * Does all the work of building a class. By making this a nested class,     * Does all the work of building a class. By making this a nested class,
864     * this code is not loaded in memory if the VM has a native     * this code is not loaded in memory if the VM has a native

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26