1 22 package org.jboss.aop.proxy.container; 23 24 import java.lang.ref.WeakReference ; 25 import java.util.Arrays ; 26 import java.util.Comparator ; 27 28 33 public class ContainerCacheUtil 34 { 35 36 40 public static WeakReference [] getSortedWeakReferenceForInterfaces(Class [] ifaces) 41 { 42 if (ifaces == null) 43 { 44 return null; 45 } 46 47 WeakReference [] interfaces = new WeakReference [ifaces.length]; 48 49 for (int i = 0 ; i < ifaces.length ; i++) 50 { 51 interfaces[i] = new WeakReference (ifaces[i]); 52 } 53 54 Arrays.sort(interfaces, Alphabetical.singleton); 55 return interfaces; 56 } 57 58 public static boolean compareClassRefs(WeakReference my, WeakReference other) 59 { 60 Class myClass = (Class )my.get(); 61 Class otherClass = (Class )other.get(); 62 63 if (myClass == null || otherClass == null) 64 { 65 return false; 66 } 67 68 if (!myClass.equals(otherClass)) 69 { 70 return false; 71 } 72 return true; 73 } 74 75 public static boolean compareInterfaceRefs(WeakReference [] my, WeakReference [] other) 76 { 77 if ((my == null && other != null) || 78 (my == null && other != null)) 79 { 80 return false; 81 } 82 83 if (my != null && my != null) 84 { 85 if (my.length != other.length) 86 { 87 return false; 88 } 89 90 for (int i = 0 ; i < my.length ; i++) 91 { 92 Class myIf = (Class )my[i].get(); 93 Class otherIf = (Class )other[i].get(); 94 95 if (!myIf.equals(otherIf)) 96 { 97 return false; 98 } 99 } 100 } 101 102 return true; 103 } 104 105 static class Alphabetical implements Comparator 106 { 107 static Alphabetical singleton = new Alphabetical(); 108 109 public int compare(Object o1, Object o2) 110 { 111 String name1 = ((Class )((WeakReference )o1).get()).getName(); 112 String name2 = ((Class )((WeakReference )o2).get()).getName(); 113 return (name1).compareTo(name2); 114 } 115 } 116 117 } 118 | Popular Tags |