java.util

Interface Map.Entry<K,V>

Known Implementing Classes:
AbstractDualBidiMap.MapEntry, AbstractHashedMap.HashEntry, AbstractLinkedMap.LinkEntry, AbstractMapEntry, AbstractMapEntryDecorator, AbstractReferenceMap.ReferenceEntry, BeanMap.Entry, BeanMap.MyMapEntry, BucketingService.MapEntry, DefaultMapEntry, DefaultMapEntry, IdentityMap.IdentityEntry, IdentityMap.IdentityMapEntry, LRUMapEntry, LRUMemoryCache.MapEntryWrapper, MapEntry, TiedMapEntry, TransactionalMapWrapper.HashEntry, UnmodifiableMapEntry

public static interface Map.Entry<K,V>

A map entry (key-value pair). The Map.entrySet method returns a collection-view of the map, whose elements are of this class. The only way to obtain a reference to a map entry is from the iterator of this collection-view. These Map.Entry objects are valid only for the duration of the iteration; more formally, the behavior of a map entry is undefined if the backing map has been modified after the entry was returned by the iterator, except through the setValue operation on the map entry.
Since:
1.2
See Also:
Map.entrySet()

Method Summary

boolean
equals(Object o)
Compares the specified object with this entry for equality.
K
getKey()
Returns the key corresponding to this entry.
V
getValue()
Returns the value corresponding to this entry.
int
hashCode()
Returns the hash code value for this map entry.
V
setValue(V value)
Replaces the value corresponding to this entry with the specified value (optional operation).

Method Details

equals

public boolean equals(Object o)
Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if
     (e1.getKey()==null ?
      e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &&
     (e1.getValue()==null ?
      e2.getValue()==null : e1.getValue().equals(e2.getValue()))
 
This ensures that the equals method works properly across different implementations of the Map.Entry interface.
Overrides:
equals in interface Object
Parameters:
o - object to be compared for equality with this map entry.
Returns:
true if the specified object is equal to this map entry.
Usages and Demos :

View More Examples of equals(Object o)
   1: 
   2:   private static class Entry implements Map.Entry {
   3: 
   4:         ...
   5:       if(obj == this) return true;
   6:       if(!(obj instanceof Map.Entry)) return false;
   7: 
   8:         ...
   9:       Map.Entry other = (Map.Entry)obj;
  10: 
  11:         ...
  12:               other.getKey() == null : 
  13:               getKey().equals(other.getKey()))  &&

View Full Code Here
   1: 
   2:     private static class Entry implements Map.Entry, KeyValue {
   3: 
   4:         ...
   5:                 return true;
   6:             if (!(obj instanceof Map.Entry))
   7:                 return false;
   8:         ...
   9: 
  10:             Map.Entry other = (Map.Entry) obj;
  11: 
  12:         ...
  13:             return (
  14:                 (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey()))

View Full Code Here
   1:             for (Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
   2:                 if (value.equals(pos.getValue())) {
   3:                     return true;
   4:         ...
   5: 
   6:     public Map.Entry getFirst() {
   7:         return (isEmpty()) ? null : sentinel.next;
   8:         ...
   9: 
  10:     public Map.Entry getLast() {
  11:         return (isEmpty()) ? null : sentinel.prev;
  12:         ...
  13:         while (iter.hasNext()) {
  14:             Map.Entry entry = (Map.Entry) iter.next();

View Full Code Here

getKey

public K getKey()
Returns the key corresponding to this entry.
Returns:
the key corresponding to this entry.
Throws:
IllegalStateException - implementations may, but are not required to, throw this exception if the entry has been removed from the backing map
Usages and Demos :

View More Examples of getKey()
   1: 
   2: import java.util.Map.Entry;
   3: 
   4:         ...
   5:         this.value = entry.getValue();
   6:         this.key = entry.getKey();
   7:     }
   8:         ...
   9:             Entry e = (Entry) o;
  10:             Object k = e.getKey();
  11:             if (key == k || (key != null && key.equals(k))) {

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.Map.Entry;
   3: import java.util.Map;
   4:         ...
   5:     while (i.hasNext()) {
   6:       Map.Entry e = (Map.Entry)i.next();
   7:         ...
   8:       Object k = e.getKey();
   9:       Object v = e.getValue();

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.Map.Entry;
   3: import java.util.Properties;
   4:         ...
   5:             Entry entry = (Entry) i.next();
   6:             env.put(entry.getKey(), entry.getValue());
   7:         }
   8: 
   9:         String factoryName = env.getProperty(Context.INITIAL_CONTEXT_FACTORY);

View Full Code Here
   1: import java.util.Map;
   2: import java.util.Map.Entry;
   3: 
   4:         ...
   5:             Entry entry = (Entry) iterator.next();
   6:             Object key = entry.getKey();
   7:             Object counter = entry.getValue();
   8:             out.writeObject(key);
   9:             out.writeObject(counter);

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.Map.Entry;
   3: import java.util.Properties;
   4:         ...
   5:             Entry entry = (Entry) i.next();
   6:             env.put(entry.getKey(), entry.getValue());
   7:         }
   8: 
   9:         String factoryName = env.getProperty(Context.INITIAL_CONTEXT_FACTORY);

View Full Code Here

getValue

public V getValue()
Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.
Returns:
the value corresponding to this entry.
Throws:
IllegalStateException - implementations may, but are not required to, throw this exception if the entry has been removed from the backing map
Usages and Demos :

View More Examples of getValue()
   1: import java.util.Map;
   2: import java.util.Map.Entry;
   3: import java.util.Iterator;
   4:         ...
   5:             while (eItr.hasNext()) {
   6:                 Map.Entry e = (Map.Entry) eItr.next();
   7:                 sBuf.append(  e.getKey().toString() + "=" +
   8:         ...
   9:                 e.getValue().toString() + "\n" );
  10:             }

View Full Code Here
   1: import java.util.Set;
   2: import java.util.Map.Entry;
   3: 
   4:         ...
   5:         {
   6:             Map.Entry entry = (Entry) itr.next();                                
   7:         ...
   8:             windowSet.add((PortletWindow)entry.getValue());
   9:         }

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.Map.Entry;
   3: import java.util.Properties;
   4:         ...
   5:             Entry entry = (Entry) i.next();
   6:             env.put(entry.getKey(), entry.getValue());
   7:         }
   8: 
   9:         String factoryName = env.getProperty(Context.INITIAL_CONTEXT_FACTORY);

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.Map.Entry;
   3: import java.util.Properties;
   4:         ...
   5:             Entry entry = (Entry) i.next();
   6:             env.put(entry.getKey(), entry.getValue());
   7:         }
   8: 
   9:         String factoryName = env.getProperty(Context.INITIAL_CONTEXT_FACTORY);

View Full Code Here
   1: import java.util.Map;
   2: import java.util.Map.Entry;
   3: 
   4:         ...
   5:               Entry entry = (Entry)iter.next();
   6:               transformer.setParameter((String)entry.getKey(), (String)entry.getValue());
   7:           }
   8:       }
   9:       return transformer;

View Full Code Here

hashCode

public int hashCode()
Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:
     (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
     (e.getValue()==null ? 0 : e.getValue().hashCode())
 
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.
Overrides:
hashCode in interface Object
Returns:
the hash code value for this map entry.
Usages and Demos :

View More Examples of hashCode()
   1: 
   2:   private static class Entry implements Map.Entry {
   3: 
   4:         ...
   5:     public int hashCode() { 
   6:       return ((getKey() == null ? 0 : getKey().hashCode()) ^
   7:         ...
   8:               (getValue()==null ? 0 : getValue().hashCode())); 
   9:     }
  10:         ...
  11:       if(obj == this) return true;
  12:       if(!(obj instanceof Map.Entry)) return false;

View Full Code Here
   1: 
   2:     private static class Entry implements Map.Entry, KeyValue {
   3: 
   4:         ...
   5:         public int hashCode() {
   6:             return ((getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()));
   7:         }
   8:         ...
   9:                 return true;
  10:             if (!(obj instanceof Map.Entry))
  11:                 return false;
  12:         ...
  13: 
  14:             Map.Entry other = (Map.Entry) obj;

View Full Code Here
   1: 
   2:     public Map.Entry getFirst() {
   3:         return (isEmpty()) ? null : sentinel.next;
   4:         ...
   5: 
   6:     public Map.Entry getLast() {
   7:         return (isEmpty()) ? null : sentinel.prev;
   8:         ...
   9:         while (iter.hasNext()) {
  10:             Map.Entry entry = (Map.Entry) iter.next();
  11:             put(entry.getKey(), entry.getValue());
  12:         ...
  13:     public int hashCode() {
  14:         return entrySet().hashCode();

View Full Code Here

setValue

public V setValue(V value)
Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).
Parameters:
value - new value to be stored in this entry.
Returns:
old value corresponding to the entry.
Throws:
UnsupportedOperationException - if the put operation is not supported by the backing map.
ClassCastException - if the class of the specified value prevents it from being stored in the backing map.
IllegalArgumentException - if some aspect of this value prevents it from being stored in the backing map.
NullPointerException - if the backing map does not permit null values, and the specified value is null.
IllegalStateException - implementations may, but are not required to, throw this exception if the entry has been removed from the backing map
Usages and Demos :

View More Examples of setValue(V value)
   1: import java.util.Map;
   2: import java.util.Map.Entry;
   3: import java.util.Set;
   4:         ...
   5:         {
   6:             existingEntry.setValue(value);
   7:             
   8:         ...
   9:         
  10:         public SimpleEntry(Map.Entry entry)
  11:         {
  12:         ...
  13:             
  14:             Map.Entry entry = (Map.Entry)object;

View Full Code Here
   1: import java.util.*;
   2: import java.util.Map.Entry;
   3: 
   4:         ...
   5: 
   6:                 Map.Entry entry;
   7:                 for(Iterator it=sent.entrySet().iterator(); it.hasNext();) {
   8:         ...
   9:                     entry=(Map.Entry)it.next();
  10:         ...
  11:                     entry.setValue(max_credits_constant);

View Full Code Here