Methods Summary |
---|
public void | clear()Removes all elements from this map, leaving it empty.
entrySet().clear();
|
protected java.lang.Object | clone()Returns a new instance of the same class as this instance, whose slots
have been filled in with the values of the slots of this instance.
AbstractMap<K, V> result = (AbstractMap<K, V>) super.clone();
result.keySet = null;
result.valuesCollection = null;
return result;
|
public boolean | containsKey(java.lang.Object key)Returns whether this map contains the specified key.
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
if (key != null) {
while (it.hasNext()) {
if (key.equals(it.next().getKey())) {
return true;
}
}
} else {
while (it.hasNext()) {
if (it.next().getKey() == null) {
return true;
}
}
}
return false;
|
public boolean | containsValue(java.lang.Object value)Returns whether this map contains the specified value.
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
if (value != null) {
while (it.hasNext()) {
if (value.equals(it.next().getValue())) {
return true;
}
}
} else {
while (it.hasNext()) {
if (it.next().getValue() == null) {
return true;
}
}
}
return false;
|
public abstract java.util.Set | entrySet()Returns a set containing all of the mappings in this map. Each mapping is
an instance of {@link Map.Entry}. As the set is backed by this map,
changes in one will be reflected in the other.
|
public boolean | equals(java.lang.Object object)Compares the specified object to this instance, and returns {@code true}
if the specified object is a map and both maps contain the same mappings.
if (this == object) {
return true;
}
if (object instanceof Map) {
Map<?, ?> map = (Map<?, ?>) object;
if (size() != map.size()) {
return false;
}
// BEGIN android-changed
// copied from newer version of harmony
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
while (it.hasNext()) {
Entry<K, V> entry = it.next();
K key = entry.getKey();
V value = entry.getValue();
Object obj = map.get(key);
if( null != obj && (!obj.equals(value)) || null == obj && obj != value) {
return false;
}
}
// END android-changed
return true;
}
return false;
|
public V | get(java.lang.Object key)Returns the value of the mapping with the specified key.
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
if (key != null) {
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
if (key.equals(entry.getKey())) {
return entry.getValue();
}
}
} else {
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
if (entry.getKey() == null) {
return entry.getValue();
}
}
}
return null;
|
public int | hashCode()Returns the hash code for this object. Objects which are equal must
return the same value for this method.
int result = 0;
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
while (it.hasNext()) {
result += it.next().hashCode();
}
return result;
|
public boolean | isEmpty()Returns whether this map is empty.
return size() == 0;
|
public java.util.Set | keySet()Returns a set of the keys contained in this map. The set is backed by
this map so changes to one are reflected by the other. The returned set
does not support adding.
if (keySet == null) {
keySet = new AbstractSet<K>() {
@Override
public boolean contains(Object object) {
return containsKey(object);
}
@Override
public int size() {
return AbstractMap.this.size();
}
@Override
public Iterator<K> iterator() {
return new Iterator<K>() {
Iterator<Map.Entry<K, V>> setIterator = entrySet()
.iterator();
public boolean hasNext() {
return setIterator.hasNext();
}
public K next() {
return setIterator.next().getKey();
}
public void remove() {
setIterator.remove();
}
};
}
};
}
return keySet;
|
public V | put(K key, V value)Maps the specified key to the specified value.
throw new UnsupportedOperationException();
|
public void | putAll(java.util.Map map)Copies every mapping in the specified map to this map.
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
|
public V | remove(java.lang.Object key)Removes a mapping with the specified key from this Map.
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
if (key != null) {
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
if (key.equals(entry.getKey())) {
it.remove();
return entry.getValue();
}
}
} else {
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
if (entry.getKey() == null) {
it.remove();
return entry.getValue();
}
}
}
return null;
|
public int | size()Returns the number of elements in this map.
return entrySet().size();
|
public java.lang.String | toString()Returns the string representation of this map.
if (isEmpty()) {
return "{}"; //$NON-NLS-1$
}
StringBuilder buffer = new StringBuilder(size() * 28);
buffer.append('{");
Iterator<Map.Entry<K, V>> it = entrySet().iterator();
while (it.hasNext()) {
Map.Entry<K, V> entry = it.next();
Object key = entry.getKey();
if (key != this) {
buffer.append(key);
} else {
buffer.append("(this Map)"); //$NON-NLS-1$
}
buffer.append('=");
Object value = entry.getValue();
if (value != this) {
buffer.append(value);
} else {
buffer.append("(this Map)"); //$NON-NLS-1$
}
if (it.hasNext()) {
buffer.append(", "); //$NON-NLS-1$
}
}
buffer.append('}");
return buffer.toString();
|
public java.util.Collection | values()Returns a collection of the values contained in this map. The collection
is backed by this map so changes to one are reflected by the other. The
collection supports remove, removeAll, retainAll and clear operations,
and it does not support add or addAll operations.
This method returns a collection which is the subclass of
AbstractCollection. The iterator method of this subclass returns a
"wrapper object" over the iterator of map's entrySet(). The {@code size}
method wraps the map's size method and the {@code contains} method wraps
the map's containsValue method.
The collection is created when this method is called for the first time
and returned in response to all subsequent calls. This method may return
different collections when multiple concurrent calls occur to this
method, since no synchronization is performed.
if (valuesCollection == null) {
valuesCollection = new AbstractCollection<V>() {
@Override
public int size() {
return AbstractMap.this.size();
}
@Override
public boolean contains(Object object) {
return containsValue(object);
}
@Override
public Iterator<V> iterator() {
return new Iterator<V>() {
Iterator<Map.Entry<K, V>> setIterator = entrySet()
.iterator();
public boolean hasNext() {
return setIterator.hasNext();
}
public V next() {
return setIterator.next().getValue();
}
public void remove() {
setIterator.remove();
}
};
}
};
}
return valuesCollection;
|