/** * Tests the equality is realm independant * * @throws Exception */ public void testEquals() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r1 = cw.newRealm("test1"); ClassRealm r2 = cw.newRealm("test2"); Entry entry1 = new Entry(r1, "org.test"); Entry entry2 = new Entry(r2, "org.test"); assertTrue("entry1 == entry2", entry1.equals(entry2)); assertTrue("entry1.hashCode() == entry2.hashCode()", entry1.hashCode() == entry2.hashCode()); }
/** * Returns the hash code value for this Map as per the definition in the Map interface. * * @see Map#hashCode() * @since 1.2 */ public synchronized int hashCode() { /* * This code detects the recursion caused by computing the hash code * of a self-referential hash table and prevents the stack overflow * that would otherwise result. This allows certain 1.1-era * applets with self-referential hash tables to work. This code * abuses the loadFactor field to do double-duty as a hashCode * in progress flag, so as not to worsen the space performance. * A negative load factor indicates that hash code computation is * in progress. */ int h = 0; if (count == 0 || loadFactor < 0) return h; // Returns zero loadFactor = -loadFactor; // Mark hashCode computation in progress Entry<?, ?>[] tab = table; for (Entry<?, ?> entry : tab) { while (entry != null) { h += entry.hashCode(); entry = entry.next; } } loadFactor = -loadFactor; // Mark hashCode computation complete return h; }
/* */ public String addSymbol(String symbol) /* */ { /* 97 */ int hash = hash(symbol); /* 98 */ int bucket = hash % this.fTableSize; /* 99 */ int length = symbol.length(); /* 100 */ for (Entry entry = this.fBuckets[bucket]; entry != null; entry = entry.next) { /* 101 */ if ((length == entry.characters.length) && (hash == entry.hashCode) && /* 102 */ (symbol.regionMatches(0, entry.symbol, 0, length))) { /* 103 */ return entry.symbol; /* */ } /* */ /* */ } /* */ /* 121 */ Entry entry = new Entry(symbol, this.fBuckets[bucket]); /* 122 */ entry.hashCode = hash; /* 123 */ this.fBuckets[bucket] = entry; /* 124 */ return entry.symbol; /* */ }
/* */ public String addSymbol(char[] buffer, int offset, int length) /* */ { /* 140 */ int hash = hash(buffer, offset, length); /* 141 */ int bucket = hash % this.fTableSize; /* 142 */ label93: for (Entry entry = this.fBuckets[bucket]; entry != null; entry = entry.next) { /* 143 */ if ((length == entry.characters.length) && (hash == entry.hashCode)) { /* 144 */ for (int i = 0; i < length; i++) { /* 145 */ if (buffer[(offset + i)] != entry.characters[i]) { /* */ break label93; /* */ } /* */ } /* 149 */ return entry.symbol; /* */ } /* */ /* */ } /* */ /* 154 */ Entry entry = new Entry(buffer, offset, length, this.fBuckets[bucket]); /* 155 */ this.fBuckets[bucket] = entry; /* 156 */ entry.hashCode = hash; /* 157 */ return entry.symbol; /* */ }