com.artima.lookup.util
Class ConsistentMapEntry

java.lang.Object
  extended by com.artima.lookup.util.ConsistentMapEntry
All Implemented Interfaces:
Serializable, Map.Entry

final class ConsistentMapEntry
extends Object
implements Map.Entry, Serializable

An implementation of the java.util.Map.Entry interface that has a serialized form consistent in all virtual machines. ConsistentMapEntry instances are unmodifiable. The setValue mutator method throws UnsupportedOperationException. This class permits null for values and keys.

Although instances of this class are unmodifiable, they are not necessarily immutable. If a client retrieves a mutable object (either a key or value) contained in a ConsistentMapEntry and mutates that object, the client in effect mutates the state of the ConsistentMapEntry. In this case, the serialized form of the ConsistentMapEntry will most likely also have been mutated. A ConsistentMapEntry that contains only immutable objects will maintain a consistent serialized form indefinitely. But a ConsistentMapEntry that contains mutable objects will maintain a consistent serialized form only so long as the mutable objects are not mutated.

Author:
Bill Venners

Field Summary
private  Object key
           
private static long serialVersionUID
           
private  Object value
           
 
Constructor Summary
ConsistentMapEntry(Object key, Object value)
          Constructs a new ConsistentMapEntry with passed key and value.
 
Method Summary
 boolean equals(Object o)
          Compares the specified object (the Object passed in o) with this ConsistentMapEntry object for equality.
private static boolean equalsOrNull(Object o1, Object o2)
           
 Object getKey()
          Returns the key.
 Object getValue()
          Returns the value.
 int hashCode()
          Returns the hash code value for this ConsistentMapEntry object.
 Object setValue(Object value)
          Replaces the value corresponding to this entry with the specified value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

key

private Object key

value

private Object value
Constructor Detail

ConsistentMapEntry

public ConsistentMapEntry(Object key,
                          Object value)
Constructs a new ConsistentMapEntry with passed key and value. null is allowed in either (or both) parameters.

Parameters:
key - the key (null key is OK)
value - the value (null value is OK) associated with the key
Method Detail

getKey

public Object getKey()
Returns the key.

Specified by:
getKey in interface Map.Entry
Returns:
the key.

getValue

public Object getValue()
Returns the value.

Specified by:
getValue in interface Map.Entry
Returns:
the value.

setValue

public Object setValue(Object value)
Replaces the value corresponding to this entry with the specified value. Because all instances of this class are unmodifiable, this method always throws UnsupportedOperationException.

Specified by:
setValue in interface Map.Entry
Throws:
UnsupportedOperationException - always

equals

public boolean equals(Object o)
Compares the specified object (the Object passed in o) with this ConsistentMapEntry object for equality. Returns true if the specified object is not null, if the specified object's class is ConsistentMapEntry, if the keys of this object and the specified object are either both null or semantically equal, and the values of this object and the specified object are either both null or semantically equal.

Specified by:
equals in interface Map.Entry
Overrides:
equals in class Object
Parameters:
o - the object to compare against
Returns:
true if the objects are the semantically equal, false otherwise.

equalsOrNull

private static boolean equalsOrNull(Object o1,
                                    Object o2)

hashCode

public int hashCode()
Returns the hash code value for this ConsistentMapEntry object.

Specified by:
hashCode in interface Map.Entry
Overrides:
hashCode in class Object
Returns:
the hashcode for this object


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.