public synchronized void put(Object object, int hashCode, int ordinal) { int index = index(hashCode, entries.length); Entry current = entries[index]; Entry prev = null; while (current != null) { if (current.hash() == hashCode) { Object currentObject = current.getKey(); if( currentObject == null){ deleteEntry(index, current, prev); current = current.next; continue; } else if (currentObject == object) { return; } } prev = current; current = current.next; } count++; Entry first = entries[index]; Entry entry = new Entry(object, hashCode, ordinal, first); entries[index] = entry; entry.next = first; checkSize(); return; }
public synchronized Entry get(Object object, int hashCode) { int index = index(hashCode, entries.length); Entry current = entries[index]; Entry prev = null; while (current != null) { if (current.hash() == hashCode) { Object currentObject = current.getKey(); if( currentObject == null){ deleteEntry(index, current, prev); current = current.next; continue; } else if (currentObject == object) { return current; } } prev = current; current = current.next; } return null; }
private void resize(int newCapacity) { Entry[] newEntries = new Entry[newCapacity]; if( entries != null){ for(Entry entry : entries){ Entry current = entry; while(current != null){ Entry newEntry = current; current = current.next; int index = index(newEntry.hash(), newEntries.length); newEntry.next = newEntries[index]; newEntries[index] = newEntry; } } } minThreshold = (newEntries.length == MINIMUM_CAPACITY) ? 0 : (newEntries.length * LOAD_FACTOR_PERCENT / 200); maxThreshold = (newEntries.length == MAXIMUM_CAPACITY) ? Integer.MAX_VALUE : newEntries.length * LOAD_FACTOR_PERCENT / 100; entries = newEntries; }