org.apache.commons.collections

Class DefaultMapEntry

public class DefaultMapEntry extends Object implements Entry, KeyValue

Deprecated: Use the version in the keyvalue subpackage. Will be removed in v4.0

A default implementation of java.util.Map.Entry

Since: Commons Collections 1.0

Version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $

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

Constructor Summary
DefaultMapEntry()
Constructs a new DefaultMapEntry with a null key and null value.
DefaultMapEntry(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
booleanequals(Object obj)
Compares this Map Entry with another Map Entry.
ObjectgetKey()
Gets the key from the Map Entry.
ObjectgetValue()
Gets the value from the Map Entry.
inthashCode()
Gets a hashCode compatible with the equals method.
voidsetKey(Object key)
Sets the key stored in this Map Entry.
ObjectsetValue(Object value)
Sets the value stored in this Map Entry.
StringtoString()
Written to match the output of the Map.Entry's used in a java.util.HashMap.

Constructor Detail

DefaultMapEntry

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

DefaultMapEntry

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

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

Throws: NullPointerException if the entry is 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 Detail

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.

Returns: the key

getValue

public Object getValue()
Gets the value from the Map Entry.

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-2008 Apache Software Foundation. All Rights Reserved.