1 21 22 package org.apache.derby.iapi.services.classfile; 23 24 import java.io.IOException ; 25 26 import java.util.Hashtable ; 27 import java.util.Vector ; 28 29 30 31 class MemberTable { 32 protected Vector entries; 33 private Hashtable hashtable; 34 private MemberTableHash mutableMTH = null; 35 36 public MemberTable(int count) { 37 entries = new Vector (count); 38 hashtable = new Hashtable ((count > 50) ? count : 50); 39 mutableMTH = new MemberTableHash(null, null); 40 } 41 42 void addEntry(ClassMember item) { 43 MemberTableHash mth= new MemberTableHash( 44 item.getName(), 45 item.getDescriptor(), 46 entries.size()); 47 48 entries.addElement(item); 49 50 51 hashtable.put(mth, mth); 52 } 53 54 ClassMember find(String name, String descriptor) { 55 56 57 mutableMTH.name = name; 58 mutableMTH.descriptor = descriptor; 59 mutableMTH.setHashCode(); 60 61 62 MemberTableHash mth = (MemberTableHash) hashtable.get(mutableMTH); 63 if (mth == null) 64 { 65 return null; 66 } 67 68 return (ClassMember) entries.elementAt(mth.index); 69 } 70 71 void put(ClassFormatOutput out) throws IOException { 72 73 Vector lentries = entries; 74 int count = lentries.size(); 75 for (int i = 0; i < count; i++) { 76 ((ClassMember) lentries.elementAt(i)).put(out); 77 } 78 } 79 80 int size() { 81 return entries.size(); 82 } 83 84 int classFileSize() { 85 int size = 0; 86 87 Vector lentries = entries; 88 int count = lentries.size(); 89 for (int i = 0; i < count; i++) { 90 size += ((ClassMember) lentries.elementAt(i)).classFileSize(); 91 } 92 93 return size; 94 } 95 } 96 97 class MemberTableHash 98 { 99 String name; 100 String descriptor; 101 int index; 102 int hashCode; 103 104 MemberTableHash(String name, String descriptor, int index) 105 { 106 this.name = name; 107 this.descriptor = descriptor; 108 this.index = index; 109 110 if (name != null && descriptor != null) 111 { 112 setHashCode(); 113 } 114 } 115 116 MemberTableHash(String name, String descriptor) 117 { 118 this(name, descriptor, -1); 119 } 120 121 void setHashCode() 122 { 123 hashCode = name.hashCode() + descriptor.hashCode(); 124 } 125 126 public boolean equals(Object other) 127 { 128 MemberTableHash mth = (MemberTableHash) other; 129 130 if (other == null) 131 { 132 return false; 133 } 134 135 if (name.equals(mth.name) && descriptor.equals(mth.descriptor)) 136 { 137 return true; 138 } 139 else 140 { 141 return false; 142 } 143 } 144 145 public int hashCode() 146 { 147 return hashCode; 148 } 149 } 150 151 152 153 154 155 156 | Popular Tags |