org.apache.commons.collections

Class DefaultMapEntry

Implemented Interfaces:
Map.Entry, KeyValue

public class DefaultMapEntry
extends java.lang.Object
implements Map.Entry, KeyValue

A default implementation of java.util.Map.Entry

Version:
$Revision: 1.21 $ $Date: 2004/02/18 01:15:42 $

Authors:
James Strachan
Michael A. Smith
Neil O'Toole
Stephen Colebourne

Since:
Commons Collections 1.0

Constructor Summary

DefaultMapEntry()
Constructs a new DefaultMapEntry with a null key and null value.
DefaultMapEntry(Map.Entry entry)
Constructs a new DefaultMapEntry with the given key and given value.
DefaultMapEntry(Object key, Object value)
Constructs a new DefaultMapEntry with the given key and given value.

Method Summary

boolean
equals(Object obj)
Compares this Map Entry with another Map Entry.
Object
getKey()
Gets the key from the Map Entry.
Object
getValue()
Gets the value from the Map Entry.
int
hashCode()
Gets a hashCode compatible with the equals method.
void
setKey(Object key)
Sets the key stored in this Map Entry.
Object
setValue(Object value)
Sets the value stored in this Map Entry.
String
toString()
Written to match the output of the Map.Entry's used in a java.util.HashMap.

Constructor Details

DefaultMapEntry

public DefaultMapEntry()
Constructs a new DefaultMapEntry with a null key and null value.


DefaultMapEntry

public DefaultMapEntry(Map.Entry entry)
Constructs a new DefaultMapEntry with the given key and given value.

Parameters:
entry - the entry to copy, must not be null


DefaultMapEntry

public DefaultMapEntry(Object key,
                       Object value)
Constructs a new DefaultMapEntry with the given key and given value.

Parameters:
key - the key for the entry, may be null
value - the value for the entry, may be null

Method Details

equals

public boolean equals(Object obj)
Compares this Map Entry with another Map Entry.

Implemented per API documentation of java.util.Map.Entry.equals(Object)

Parameters:
obj - the object to compare to

Returns:
true if equal key and value


getKey

public Object getKey()
Gets the key from the Map Entry.
Specified by:
getKey in interface KeyValue

Returns:
the key


getValue

public Object getValue()
Gets the value from the Map Entry.
Specified by:
getValue in interface KeyValue

Returns:
the value


hashCode

public int hashCode()
Gets a hashCode compatible with the equals method.

Implemented per API documentation of java.util.Map.Entry.hashCode()

Returns:
a suitable hash code


setKey

public void setKey(Object key)
Sets the key stored in this Map Entry.

This Map Entry is not connected to a Map, so only the local data is changed.

Parameters:
key - the new key


setValue

public Object setValue(Object value)
Sets the value stored in this Map Entry.

This Map Entry is not connected to a Map, so only the local data is changed.

Parameters:
value - the new value

Returns:
the previous value


toString

public String toString()
Written to match the output of the Map.Entry's used in a java.util.HashMap.

Since:
3.0


Copyright © 2001-2005 Apache Software Foundation. All Rights Reserved.