List of usage examples for java.util AbstractSet AbstractSet
protected AbstractSet()
From source file:IntHashMap.java
/** * Returns a collection view of the mappings contained in this map. Each * element in the returned collection is a <tt>Map.Entry</tt>. The * collection is backed by the map, so changes to the map are reflected in * the collection, and vice-versa. The collection supports element * removal, which removes the corresponding mapping from the map, via the * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>, * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations. * It does not support the <tt>add</tt> or <tt>addAll</tt> operations. * * @return a collection view of the mappings contained in this map. *///from www . j av a 2 s.com public Set<Map.Entry<Integer, V>> entrySet() { if (entrySet == null) { entrySet = new AbstractSet<Map.Entry<Integer, V>>() { public Iterator iterator() { return (Iterator) new IntHashIterator(ENTRIES); } public boolean contains(Object o) { if (!(o instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) o; Integer key = (Integer) entry.getKey(); Entry tab[] = table; int hash = (key == null ? 0 : key.hashCode()); int index = (hash & 0x7fffffff) % tab.length; for (Entry e = tab[index]; e != null; e = e.next) { if (e.key == hash && e.equals(entry)) { return true; } } return false; } public boolean remove(Object o) { if (!(o instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) o; Integer key = (Integer) entry.getKey(); Entry tab[] = table; int hash = (key == null ? 0 : key.hashCode()); int index = (hash & 0x7fffffff) % tab.length; for (Entry e = tab[index], prev = null; e != null; prev = e, e = e.next) { if (e.key == 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 int size() { return count; } public void clear() { IntHashMap.this.clear(); } }; } return entrySet; }
From source file:org.elasticsearch.common.collect.CopyOnWriteHashMap.java
@Override public Set<Map.Entry<K, V>> entrySet() { return new AbstractSet<Map.Entry<K, V>>() { @Override/* w w w .j a v a 2 s. c o m*/ public Iterator<java.util.Map.Entry<K, V>> iterator() { return new EntryIterator<>(root); } @Override public boolean contains(Object o) { if (o == null || !(o instanceof Map.Entry)) { return false; } Map.Entry<?, ?> entry = (java.util.Map.Entry<?, ?>) o; return entry.getValue().equals(CopyOnWriteHashMap.this.get(entry.getKey())); } @Override public int size() { return CopyOnWriteHashMap.this.size(); } }; }
From source file:IntHashMap.java
/** * Returns a collection view of the mappings contained in this map. Each * element in the returned collection is a <code>Map.Entry</code>. The * collection is backed by the map, so changes to the map are reflected in * the collection, and vice-versa. The collection supports element removal, * which removes the corresponding mapping from the map, via the * <code>Iterator.remove</code>, <code>Collection.remove</code>, * <code>removeAll</code>, <code>retainAll</code>, and <code>clear</code> * operations. It does not support the <code>add</code> or * <code>addAll</code> operations. * * @return a collection view of the mappings contained in this map. * @see java.util.Map.Entry/*from www . j a va 2 s. c o m*/ */ @Override public Set entrySet() { if (entrySet == null) { entrySet = new AbstractSet() { @Override public Iterator iterator() { return new IntHashIterator(ENTRIES); } @Override 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 == null ? 0 : key.hashCode()); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry e = tab[index]; e != null; e = e.next) { if (e.key == hash && e.equals(entry)) { return true; } } return false; } @Override 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 == null ? 0 : key.hashCode()); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry e = tab[index], prev = null; e != null; prev = e, e = e.next) { if (e.key == 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; } @Override public int size() { return count; } @Override public void clear() { IntHashMap.this.clear(); } }; } return entrySet; }
From source file:org.apache.ojb.broker.util.ReferenceMap.java
/** * Returns a set view of this map's entries. * * @return a set view of this map's entries */// w w w. j a v a 2 s. c om public Set entrySet() { if (entrySet != null) return entrySet; entrySet = new AbstractSet() { public int size() { return ReferenceMap.this.size(); } public void clear() { ReferenceMap.this.clear(); } public boolean contains(Object o) { if (o == null) return false; if (!(o instanceof Map.Entry)) return false; Map.Entry e = (Map.Entry) o; Entry e2 = getEntry(e.getKey()); return (e2 != null) && e.equals(e2); } public boolean remove(Object o) { boolean r = contains(o); if (r) { Map.Entry e = (Map.Entry) o; ReferenceMap.this.remove(e.getKey()); } return r; } public Iterator iterator() { return new EntryIterator(); } public Object[] toArray() { return toArray(new Object[0]); } public Object[] toArray(Object[] arr) { ArrayList list = new ArrayList(); Iterator iterator = iterator(); while (iterator.hasNext()) { Entry e = (Entry) iterator.next(); list.add(new DefaultMapEntry(e.getKey(), e.getValue())); } return list.toArray(arr); } }; return entrySet; }
From source file:IdentityHashMap.java
/** * Returns a collection view of the mappings contained in this map. Each * element in the returned collection is a <tt>Map.Entry</tt>. The * collection is backed by the map, so changes to the map are reflected in * the collection, and vice-versa. The collection supports element * removal, which removes the corresponding mapping from the map, via the * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>, * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations. * It does not support the <tt>add</tt> or <tt>addAll</tt> operations. * * @return a collection view of the mappings contained in this map. * @see Map.Entry/*from ww w . j a va2s . c o m*/ */ public Set entrySet() { if (entrySet == null) { entrySet = new AbstractSet() { public Iterator iterator() { return getHashIterator(ENTRIES); } 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==null ? 0 : key.hashCode()); int hash = (key == null ? 0 : System.identityHashCode(key)); 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; } 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==null ? 0 : key.hashCode()); int hash = (key == null ? 0 : System.identityHashCode(key)); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry 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 int size() { return count; } public void clear() { IdentityHashMap.this.clear(); } }; } return entrySet; }
From source file:SequencedHashMap.java
/** * Implements {@link Map#keySet()}./*from www.ja v a2s . c o m*/ */ public Set keySet() { return new AbstractSet() { // required impls public Iterator iterator() { return new OrderedIterator(KEY); } public boolean remove(Object o) { Entry e = SequencedHashMap.this.removeImpl(o); return (e != null); } // more efficient impls than abstract set public void clear() { SequencedHashMap.this.clear(); } public int size() { return SequencedHashMap.this.size(); } public boolean isEmpty() { return SequencedHashMap.this.isEmpty(); } public boolean contains(Object o) { return SequencedHashMap.this.containsKey(o); } }; }
From source file:org.apache.ojb.broker.util.ReferenceMap.java
/** * Returns a set view of this map's keys. * * @return a set view of this map's keys *///from ww w . j a va 2 s.com public Set keySet() { if (keySet != null) return keySet; keySet = new AbstractSet() { public int size() { return size; } public Iterator iterator() { return new KeyIterator(); } public boolean contains(Object o) { return containsKey(o); } public boolean remove(Object o) { Object r = ReferenceMap.this.remove(o); return r != null; } public void clear() { ReferenceMap.this.clear(); } }; return keySet; }
From source file:com.baobao.utils.cache.SequencedHashMap.java
/** * Implements {@link Map#keySet()}.// w w w. j a v a2 s . co m */ public Set keySet() { return new AbstractSet() { // required impls public Iterator iterator() { return new OrderedIterator(KEY); } public boolean remove(Object o) { Entry e = SequencedHashMap.this.removeImpl(o); return (e != null); } // more efficient impls than abstract set public void clear() { SequencedHashMap.this.clear(); } public int size() { return SequencedHashMap.this.size(); } public boolean isEmpty() { return SequencedHashMap.this.isEmpty(); } public boolean contains(Object o) { return SequencedHashMap.this.containsKey(o); } }; }
From source file:SoftValuedHashMap.java
public Set<K> keySet() { if (this.keySet == null) { this.keySet = new AbstractSet<K>() { public Iterator iterator() { return createHashIterator(WeakIdentityMap.KEYS); }/* ww w . ja v a 2s . c o m*/ public int size() { return ReferencedValueHashMap.this.count; } public boolean contains(Object o) { return containsKey(o); } public boolean remove(Object o) { if (o == null) { if (ReferencedValueHashMap.this.containsKey(null)) { ReferencedValueHashMap.this.remove(null); return true; } else { return false; } } else { return ReferencedValueHashMap.this.remove(o) != null; } } public void clear() { ReferencedValueHashMap.this.clear(); } public String toString() { return WeakIdentityMap.toString(this); } }; } return this.keySet; }
From source file:SequencedHashMap.java
/** * Implements {@link Map#entrySet()}.// w w w .j ava 2s . c om */ public Set entrySet() { return new AbstractSet() { // helper private Entry findEntry(Object o) { if (o == null) { return null; } if (!(o instanceof Map.Entry)) { return null; } Map.Entry e = (Map.Entry) o; Entry entry = (Entry) entries.get(e.getKey()); if ((entry != null) && entry.equals(e)) { return entry; } else { return null; } } // required impl public Iterator iterator() { return new OrderedIterator(ENTRY); } public boolean remove(Object o) { Entry e = findEntry(o); if (e == null) { return false; } return SequencedHashMap.this.removeImpl(e.getKey()) != null; } // more efficient impls than abstract collection public void clear() { SequencedHashMap.this.clear(); } public int size() { return SequencedHashMap.this.size(); } public boolean isEmpty() { return SequencedHashMap.this.isEmpty(); } public boolean contains(Object o) { return findEntry(o) != null; } }; }