Top Description Constructors Methods
org.apache.commons.collections4.keyvalue

public Class DefaultKeyValue<K, V>

extends AbstractKeyValue<K, V>
Class Inheritance
Type Parameters
<K>
the type of keys
<V>
the type of values
Imports
java.util.Map, org.apache.commons.collections4.KeyValue

A mutable KeyValue pair that does not implement Map.Entry.

Note that a DefaultKeyValue instance may not contain itself as a key or value.

Since
3.0

Constructor Summary

AccessConstructor and Description
public
DefaultKeyValue()

Constructs a new pair with a null key and null value.

public
DefaultKeyValue(final K
the key for the entry, may be null
key
,
final V
the value for the entry, may be null
value
)

Constructs a new pair with the specified key and given value.

public
DefaultKeyValue(final KeyValue<? extends K, ? extends V>
the pair to copy, must not be null
pair
)

Constructs a new pair from the specified KeyValue.

public
DefaultKeyValue(final Map.Entry<? extends K, ? extends V>
the entry to copy, must not be null
entry
)

Constructs a new pair from the specified Map.Entry.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if equal key and value
equals
(final Object
the object to compare to
obj
)

Overrides java.lang.Object.equals.

Compares this Map.Entry with another Map.Entry.
public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Gets a hashCode compatible with the equals method.
public K

Returns:

the old key
setKey
(final K
the new key
key
)

Overrides org.apache.commons.collections4.keyvalue.AbstractKeyValue.setKey.

Sets the key.
public V

Returns:

the old value of the value
setValue
(final V
the new value
value
)

Overrides org.apache.commons.collections4.keyvalue.AbstractKeyValue.setValue.

Sets the value.
public Map.Entry<K, V>

Returns:

a MapEntry instance
toMapEntry
()

Returns a new Map.Entry object with key and value from this pair.

Inherited from org.apache.commons.collections4.keyvalue.AbstractKeyValue:
getKeygetValuetoString

Constructor Detail

DefaultKeyValueback to summary
public DefaultKeyValue()

Constructs a new pair with a null key and null value.

DefaultKeyValueback to summary
public DefaultKeyValue(final K key, final V value)

Constructs a new pair with the specified key and given value.

Parameters
key:K

the key for the entry, may be null

value:V

the value for the entry, may be null

DefaultKeyValueback to summary
public DefaultKeyValue(final KeyValue<? extends K, ? extends V> pair)

Constructs a new pair from the specified KeyValue.

Parameters
pair:KeyValue<? extends K, ? extends V>

the pair to copy, must not be null

Exceptions
NullPointerException:
if the entry is null
DefaultKeyValueback to summary
public DefaultKeyValue(final Map.Entry<? extends K, ? extends V> entry)

Constructs a new pair from the specified Map.Entry.

Parameters
entry:Map.Entry<? extends K, ? extends V>

the entry to copy, must not be null

Exceptions
NullPointerException:
if the entry is null

Method Detail

equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Compares this Map.Entry with another Map.Entry.

Returns true if the compared object is also a DefaultKeyValue, and its key and value are equal to this object's key and value.

Parameters
obj:Object

the object to compare to

Returns:boolean

true if equal key and value

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Gets a hashCode compatible with the equals method.

Implemented per API documentation of java.util.Map.Entry#hashCode(), however subclasses may override this.

Returns:int

a suitable hash code

Annotations
@Override
setKeyback to summary
public K setKey(final K key)

Overrides org.apache.commons.collections4.keyvalue.AbstractKeyValue.setKey.

Sets the key.

Parameters
key:K

the new key

Returns:K

the old key

Annotations
@Override
Exceptions
IllegalArgumentException:
if key is this object
setValueback to summary
public V setValue(final V value)

Overrides org.apache.commons.collections4.keyvalue.AbstractKeyValue.setValue.

Sets the value.

Parameters
value:V

the new value

Returns:V

the old value of the value

Annotations
@Override
Exceptions
IllegalArgumentException:
if value is this object
toMapEntryback to summary
public Map.Entry<K, V> toMapEntry()

Returns a new Map.Entry object with key and value from this pair.

Returns:Map.Entry<K, V>

a MapEntry instance