示例#1
0
 public boolean contains(Object o) {
   if (!(o instanceof Map.Entry)) return false;
   Map.Entry e = (Map.Entry) o;
   Object k = e.getKey();
   Entry candidate = getEntry(e.getKey());
   return candidate != null && candidate.equals(e);
 }
示例#2
0
  /** Special version of remove for EntrySet. */
  final Entry<T> removeMapping(Object o) {
    if (!(o instanceof Entry)) {
      return null;
    }

    Entry<T> entry = (Entry<T>) o;
    int key = entry.getKey();
    Entry<T> prev = getEntry(key);
    Entry<T> e = prev;

    while (e != null) {
      Entry<T> next = e.next;
      if (e.hash == key && e.equals(entry)) {
        count--;
        if (prev == e) {
          table[getIndex(key)] = next;
        } else {
          prev.next = next;
        }
        return e;
      }
      prev = e;
      e = next;
    }

    return e;
  }
示例#3
0
  /** Special version of remove for EntrySet using {@code Map.Entry.equals()} for matching. */
  final Entry<K, V> removeMapping(Object o) {
    if (!(o instanceof Map.Entry)) return null;

    Map.Entry<K, V> entry = (Map.Entry<K, V>) o;
    Object key = entry.getKey();
    int hash = (key == null) ? 0 : hash(key);
    int i = indexFor(hash, table.length);
    Entry<K, V> prev = table[i];
    Entry<K, V> e = prev;

    while (e != null) {
      Entry<K, V> next = e.next;
      if (e.hash == hash && e.equals(entry)) {
        modCount++;
        size--;
        if (prev == e) table[i] = next;
        else prev.next = next;
        e.recordRemoval(this);
        return e;
      }
      prev = e;
      e = next;
    }

    return e;
  }
示例#4
0
  /** Special version of remove needed by Entry set */
  Entry<K, V> removeMapping(Object o) {
    if (!(o instanceof Map.Entry)) return null;
    Entry[] tab = getTable();
    Map.Entry entry = (Map.Entry) o;
    Object k = maskNull(entry.getKey());
    int h = hash(k.hashCode());
    int i = indexFor(h, tab.length);
    Entry<K, V> prev = tab[i];
    Entry<K, V> e = prev;

    while (e != null) {
      Entry<K, V> next = e.next;
      if (h == e.hash && e.equals(entry)) {
        modCount++;
        size--;
        if (prev == e) tab[i] = next;
        else {
          prev.next = next;
          if (prev == next) {
            throw new RuntimeException("circular");
          }
        }
        return e;
      }
      prev = e;
      e = next;
    }

    return null;
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  Entry<K, V> removeMapping(Object o) {
    if (!(o instanceof Map.Entry)) {
      return null;
    }
    Entry[] tab = getTable();
    Map.Entry entry = (Map.Entry) o;
    Object k = maskNull(entry.getKey());
    int h = HashMap.hash(k.hashCode());
    int i = indexFor(h, tab.length);

    Entry<K, V> prev = tab[i];
    Entry<K, V> e = prev;

    while (e != null) {
      Entry<K, V> next = e.next;
      if (h == e.hash && e.equals(entry)) {
        modCount++;
        size--;
        if (prev == e) {
          tab[i] = next;
        } else {
          prev.next = next;
        }
        return e;
      }
      prev = e;
      e = next;
    }

    return null;
  }
示例#6
0
  /**
   * Removes and returns the entry with a specified value.
   *
   * @param e the value of the entry to remove
   * @return the entry.
   */
  public Entry remove(E e) {
    // First check to see if such value even exists.
    if (!exists(e)) {
      P.pp("MINOR: Attempted to remove an Entry that does not exist in bucket");
      return null;
    }
    Entry x = null; // The Entry to return and remove.

    // Check the first value.
    if (first.equals(e)) {
      x = first;
      first = first.next;
    } else {
      // Traverse the list until we find the value.
      Entry position = first;
      for (boolean found = false; found == true; position = position.next) {
        if (position.next.value.equals(e)) {
          x = position.next;
          position.next = position.next.next; // Remove it from the list.
          found = true;
        }
      }
    }
    size--;
    return x;
  }
示例#7
0
 @Override
 public boolean contains(Object o) {
   if (!(o instanceof Entry)) {
     return false;
   }
   Entry<T> e = (Entry<T>) o;
   Entry<T> candidate = getEntry(e.getKey());
   return candidate != null && candidate.equals(e);
 }
示例#8
0
  /**
   * 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());
  }
 @SuppressWarnings({"rawtypes", "unused"})
 @Override
 public boolean contains(Object o) {
   if (!(o instanceof Map.Entry)) {
     return false;
   }
   Map.Entry e = (Map.Entry) o;
   Object k = e.getKey();
   Entry candidate = getEntry(e.getKey());
   return candidate != null && candidate.equals(e);
 }
    public boolean contains(Object o) {
      if (!(o instanceof Map.Entry)) return false;
      Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
      Object key = entry.getKey();
      Entry<?, ?>[] tab = table;
      int hash = key.hashCode();
      int index = (hash & 0x7FFFFFFF) % tab.length;

      for (Entry<?, ?> e = tab[index]; e != null; e = e.next)
        if (e.hash == hash && e.equals(entry)) return true;
      return false;
    }
示例#11
0
    public boolean remove(Object o) {
      if (!(o instanceof Map.Entry)) return false;
      Map.Entry<K, V> entry = (Map.Entry<K, V>) o;
      K key = entry.getKey();
      Entry[] tab = table;
      int hash = key.hashCode();
      int index = (hash & 0x7FFFFFFF) % tab.length;

      for (Entry<K, V> e = tab[index], prev = null; e != null; prev = e, e = e.next) {
        if (e.hash == hash && e.equals(entry)) {
          modCount++;
          if (prev != null) prev.next = e.next;
          else tab[index] = e.next;

          count--;
          e.value = null;
          return true;
        }
      }
      return false;
    }
    public boolean remove(Object o) {
      if (!(o instanceof Map.Entry)) return false;
      Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
      Object key = entry.getKey();
      Entry<?, ?>[] tab = table;
      int hash = key.hashCode();
      int index = (hash & 0x7FFFFFFF) % tab.length;

      @SuppressWarnings("unchecked")
      Entry<K, V> e = (Entry<K, V>) tab[index];
      for (Entry<K, V> prev = null; e != null; prev = e, e = e.next) {
        if (e.hash == hash && e.equals(entry)) {
          if (prev != null) prev.next = e.next;
          else tab[index] = e.next;

          e.value = null; // clear for gc.
          modCount++;
          count--;
          return true;
        }
      }
      return false;
    }
示例#13
0
 private Entry<K, V> removeMapping(Object o) {
   if (!(o instanceof Map.Entry)) return null;
   Entry<K, V>[] tab = getTable();
   Map.Entry entry = (Map.Entry) o;
   Object k = maskNull(entry.getKey());
   int h = hash(k);
   int i = indexFor(h, tab.length);
   Entry<K, V> prev = tab[i];
   Entry<K, V> e = prev;
   while (e != null) {
     Entry<K, V> next = e.next;
     if (h == e.hash && e.equals(entry)) {
       modCount++;
       size--;
       if (prev == e) tab[i] = next;
       else prev.next = next;
       return e;
     }
     prev = e;
     e = next;
   }
   return null;
 }
示例#14
0
 private Entry getEntry(Object key, GraphicsConfiguration config, int w, int h, Object[] args) {
   Entry entry;
   Iterator<SoftReference<Entry>> iter = entries.listIterator();
   while (iter.hasNext()) {
     SoftReference<Entry> ref = iter.next();
     entry = ref.get();
     if (entry == null) {
       // SoftReference was invalidated, remove the entry
       iter.remove();
     } else if (entry.equals(config, w, h, args)) {
       // Put most recently used entries at the head
       iter.remove();
       entries.addFirst(ref);
       return entry;
     }
   }
   // Entry doesn't exist
   entry = new Entry(config, w, h, args);
   if (entries.size() >= maxCount) {
     entries.removeLast();
   }
   entries.addFirst(new SoftReference<Entry>(entry));
   return entry;
 }