/**
   * Associate the given object with the given key in this <tt>IdentityWeakHashMap</tt>, replacing
   * any existing mapping.
   *
   * @param key key to map to given object.
   * @param obj object to be associated with key.
   * @return the previous object for key or <tt>null</tt> if this <tt>IdentityWeakHashMap</tt> did
   *     not have one.
   * @throws <tt>NullPointerException</tt> if obj is null</tt>.
   */
  public V put(K key, V obj) {
    if (obj == null || key == null) {
      throw new IllegalArgumentException(
          ExceptionLocalization.buildMessage("null_not_supported_identityweakhashmap"));
    }
    cleanUp();
    WeakEntry[] copyOfEntries = entries;
    int hash = System.identityHashCode(key);
    int index = (hash & 0x7FFFFFFF) % copyOfEntries.length;
    for (WeakEntry e = copyOfEntries[index]; e != null; e = e.next) {
      if (e.key.get() == key) {
        EntryReference<V> old = e.value;
        if (key == obj) {
          e.value = e.key;
        } else {
          e.value = new HardEntryReference<V>(obj);
        }
        return old.get();
      }
    }

    modCount++;
    if (count >= threshold) {
      rehash();
      copyOfEntries = entries;
      index = (hash & 0x7FFFFFFF) % copyOfEntries.length;
    }
    WeakEntry<K, V> e = new WeakEntry<K, V>(hash, key, obj, copyOfEntries[index], referenceQueue);
    copyOfEntries[index] = e;
    count++;
    return null;
  }
 public V setValue(V value) {
   EntryReference<V> oldValue = this.value;
   if (value == this.key.get()) {
     this.value = (EntryReference<V>) this.key;
   } else {
     this.value = new HardEntryReference<V>(value);
   }
   return oldValue.get();
 }
    public boolean equals(Object o) {
      if (!(o instanceof Map.Entry)) {
        return false;
      }

      Map.Entry e = (Map.Entry) o;
      Object v = value.get();
      return (key == e.getKey()) && ((v == null) ? (e.getValue() == null) : v.equals(e.getValue()));
    }
Beispiel #4
0
 public Entry getRealEntry() {
   if (this.dft instanceof EntryReference) {
     Entry entry = null;
     if (this.ref > 0) {
       Print.logStackTrace("Cyclical EntryReference: " + this.getKey());
       entry = NullEntry;
     } else {
       this.ref++;
       try {
         EntryReference entryRef = (EntryReference) this.dft;
         Entry nextEntry = entryRef.getReferencedEntry(); // <-- will display error, if not found
         entry = (nextEntry != null) ? nextEntry.getRealEntry() : NullEntry;
       } finally {
         this.ref--;
       }
     }
     return entry;
   } else {
     return this;
   }
 }
 public boolean shouldBeIgnored() {
   return key.get() == null || value.get() == null;
 }
 public String toString() {
   return key.get() + "=" + value.get();
 }
 public int hashCode() {
   Object v = value.get();
   return hash ^ ((v == null) ? 0 : v.hashCode());
 }
 public V getValue() {
   return value.get();
 }
 // Map.Entry Ops
 public K getKey() {
   return key.get();
 }