List of usage examples for java.util AbstractSet AbstractSet
protected AbstractSet()
From source file:edu.scripps.fl.collections.FuzzyMap.java
@Override public Set<Map.Entry<K, V>> entrySet() { return new AbstractSet<Map.Entry<K, V>>() { public Iterator<Map.Entry<K, V>> iterator() { return list.iterator(); }// www. j a v a2s .c o m public int size() { return list.size(); } }; }
From source file:ListOrderedMap.java
public Set entrySet() { return new AbstractSet() { Set delegate = ListOrderedMap.this.map.entrySet(); public int size() { return ListOrderedMap.this.size(); }//from w w w . j av a 2 s .c om public boolean contains(Object obj) { return delegate.contains(obj); } public boolean remove(Object obj) { boolean result = contains(obj); if (result) { ListOrderedMap.this.remove(((Map.Entry) obj).getKey()); } return result; } public void clear() { ListOrderedMap.this.clear(); } public boolean equals(Object obj) { return obj == this ? true : delegate.equals(obj); } public int hashCode() { return delegate.hashCode(); } public String toString() { return delegate.toString(); } public Iterator iterator() { return new Iterator() { Iterator keys = lst.iterator(); Object last = null; public Object next() { last = keys.next(); return new Map.Entry() { Object key = last; public Object getKey() { return key; } public Object getValue() { return map.get(key); } public Object setValue(Object value) { return map.put(key, value); } }; } public boolean hasNext() { return keys.hasNext(); } public void remove() { keys.remove(); map.remove(last); } }; } }; }
From source file:MicroMap.java
/** * @see java.util.Map#entrySet()/*ww w . j a v a2 s.c o m*/ */ public Set entrySet() { return new AbstractSet() { public Iterator iterator() { return new Iterator() { public boolean hasNext() { return index < MicroMap.this.size(); } public Object next() { index++; return new Map.Entry() { public Object getKey() { return key; } public Object getValue() { return value; } public Object setValue(final Object value) { final Object oldValue = MicroMap.this.value; MicroMap.this.value = value; return oldValue; } }; } public void remove() { clear(); } int index = 0; }; } public int size() { return MicroMap.this.size(); } }; }
From source file:MiniMap.java
/** * @see java.util.Map#keySet()/* w w w .j a v a 2 s . com*/ */ public Set<K> keySet() { return new AbstractSet<K>() { @Override public Iterator<K> iterator() { return new Iterator<K>() { public boolean hasNext() { return i < size - 1; } public K next() { // Just in case... (WICKET-428) if (!hasNext()) { throw new NoSuchElementException(); } // Find next key i = nextKey(nextIndex(i)); // Get key return keys[i]; } public void remove() { keys[i] = null; values[i] = null; size--; } int i = -1; }; } @Override public int size() { return size; } }; }
From source file:MicroMap.java
/** * @see java.util.Map#entrySet()// w w w .j a va 2 s . c o m */ public Set<Entry<K, V>> entrySet() { return new AbstractSet<Entry<K, V>>() { @Override public Iterator<Entry<K, V>> iterator() { return new Iterator<Entry<K, V>>() { public boolean hasNext() { return index < MicroMap.this.size(); } public Entry<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } index++; return new Map.Entry<K, V>() { public K getKey() { return key; } public V getValue() { return value; } public V setValue(final V value) { final V oldValue = MicroMap.this.value; MicroMap.this.value = value; return oldValue; } }; } public void remove() { clear(); } int index = 0; }; } @Override public int size() { return MicroMap.this.size(); } }; }
From source file:com.conwet.silbops.model.Subscription.java
/** * Returns the set of attribute-constraint pairs * * @return the set of attribute-constraint pairs *///from ww w . j a va2 s . c o m @Override public Set<Entry<Attribute, Constraint>> entries() { return new AbstractSet<Entry<Attribute, Constraint>>() { @Override public Iterator<Entry<Attribute, Constraint>> iterator() { return new Iterator<Entry<Attribute, Constraint>>() { private Iterator<Entry<Attribute, Set<Constraint>>> attrIt = constraints.entrySet().iterator(); private Iterator<Constraint> constrIt = null; private Attribute current = null; @Override public boolean hasNext() { return attrIt.hasNext() || (constrIt != null && constrIt.hasNext()); } @Override public Entry<Attribute, Constraint> next() { if (current == null) { Entry<Attribute, Set<Constraint>> entry = attrIt.next(); current = entry.getKey(); constrIt = entry.getValue().iterator(); } final Attribute attr = current; final Constraint cons = constrIt.next(); if (!constrIt.hasNext()) { // set null to go to next attribute current = null; } return new SimpleImmutableEntry<>(attr, cons); } @Override public void remove() { throw new UnsupportedOperationException("Read-only iterator"); } }; } @Override public int size() { int size = 0; for (Set<Constraint> constrSet : constraints.values()) { size += constrSet.size(); } return size; } }; }
From source file:org.jboss.dashboard.workspace.PanelInstance.java
public Map<String, String> getTitle() { LocaleManager localeManager = LocaleManager.lookup(); final String[] langs = localeManager.getPlatformAvailableLangs(); Map<String, String> title = new AbstractMap<String, String>() { public Set<Entry<String, String>> entrySet() { return new AbstractSet<Entry<String, String>>() { public int size() { return langs.length; }/*from w w w. jav a2 s.com*/ public Iterator<Map.Entry<String, String>> iterator() { return new Iterator<Map.Entry<String, String>>() { int i = 0; public void remove() { throw new UnsupportedOperationException(); } public boolean hasNext() { return i < langs.length; } public Map.Entry<String, String> next() { i++; return new Map.Entry<String, String>() { int index = i - 1; public String getKey() { return langs[index]; } public String getValue() { return getParameterValue(PARAMETER_TITLE, langs[index]); } public String setValue(String value) { throw new UnsupportedOperationException(); } }; } }; } }; } }; return title; }
From source file:MiniMap.java
/** * @see java.util.Map#entrySet()/*from w w w . j a v a2s . c om*/ */ public Set<Entry<K, V>> entrySet() { return new AbstractSet<Entry<K, V>>() { @Override public Iterator<Entry<K, V>> iterator() { return new Iterator<Entry<K, V>>() { public boolean hasNext() { return index < size; } public Entry<K, V> next() { if (!hasNext()) { throw new NoSuchElementException(); } keyIndex = nextKey(nextIndex(keyIndex)); index++; return new Map.Entry<K, V>() { public K getKey() { return keys[keyIndex]; } public V getValue() { return values[keyIndex]; } public V setValue(final V value) { final V oldValue = values[keyIndex]; values[keyIndex] = value; return oldValue; } }; } public void remove() { keys[keyIndex] = null; values[keyIndex] = null; } int keyIndex = -1; int index = 0; }; } @Override public int size() { return size; } }; }
From source file:org.t2framework.commons.util.ArrayMap.java
@SuppressWarnings("unchecked") public final Set entrySet() { if (entrySet == null) { entrySet = new AbstractSet() { public Iterator iterator() { return new ArrayMapIterator(); }/*from www.jav a 2 s . co m*/ public boolean contains(Object o) { if (!(o instanceof Entry)) { return false; } Entry entry = (Entry) o; int index = (entry.hashCode_ & 0x7FFFFFFF) % mapTable.length; for (Entry e = mapTable[index]; e != null; e = e.next_) { if (e.equals(entry)) { return true; } } return false; } public boolean remove(Object o) { if (!(o instanceof Entry)) { return false; } Entry entry = (Entry) o; return ArrayMap.this.remove(entry.key_) != null; } public int size() { return size; } public void clear() { ArrayMap.this.clear(); } }; } return entrySet; }
From source file:org.apache.openjpa.util.AbstractLRSProxyMap.java
public Set<K> keySet() { return new AbstractSet<K>() { public int size() { return AbstractLRSProxyMap.this.size(); }// ww w .j a v a 2 s .c o m public boolean remove(Object o) { return AbstractLRSProxyMap.this.remove(o) != null; } public Iterator<K> iterator() { return AbstractLRSProxyMap.this.iterator(MODE_KEY); } }; }