⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.keyvalue

Class MultiKey

java.lang.Object
|
+--org.apache.commons.collections.keyvalue.MultiKey

All Implemented Interfaces:
Serializable


public class MultiKey
extends java.lang.Object
implements Serializable

A MultiKey allows multiple map keys to be merged together.

The purpose of this class is to avoid the need to write code to handle maps of maps. An example might be the need to lookup a filename by key and locale. The typical solution might be nested maps. This class can be used instead by creating an instance passing in the key and locale.

Since:
Commons Collections 3.0
Authors:
Howard Lewis Ship
Stephen Colebourne

Constructor Summary

MultiKey(Object key1, Object key2)

Constructor taking two keys.

MultiKey(Object key1, Object key2, Object key3)

Constructor taking three keys.

MultiKey(Object key1, Object key2, Object key3, Object key4)

Constructor taking four keys.

MultiKey(Object key1, Object key2, Object key3, Object key4, Object key5)

Constructor taking five keys.

MultiKey(Object[] keys)

Constructor taking an array of keys.

MultiKey(Object[] keys, boolean makeCopy)

Constructor taking an array of keys.

Method Summary

boolean

equals(Object other)

Compares this object to another.

Object[]

getKeys()

Gets a copy of the individual keys.

int

hashCode()

Gets the combined hash code that is computed from all the keys.

String

toString()

Gets a debugging string version of the key.

Constructor Details

MultiKey

public MultiKey(Object key1, Object key2, Object key3, Object key4, Object key5)

Constructor taking five keys.

Parameters:
key1 - the first key
key2 - the second key
key3 - the third key
key4 - the fourth key
key5 - the fifth key

MultiKey

public MultiKey(Object key1, Object key2, Object key3, Object key4)

Constructor taking four keys.

Parameters:
key1 - the first key
key2 - the second key
key3 - the third key
key4 - the fourth key

MultiKey

public MultiKey(Object key1, Object key2, Object key3)

Constructor taking three keys.

Parameters:
key1 - the first key
key2 - the second key
key3 - the third key

MultiKey

public MultiKey(Object key1, Object key2)

Constructor taking two keys.

Parameters:
key1 - the first key
key2 - the second key

MultiKey

protected MultiKey(Object[] keys, boolean makeCopy)

Constructor taking an array of keys.

If the array is not copied, then it must not be modified.

Parameters:
keys - the array of keys
makeCopy - true to copy the array, false to assign it
Throws:
- if the key array is null

MultiKey

public MultiKey(Object[] keys)

Constructor taking an array of keys.

Parameters:
keys - the array of keys
Throws:
- if the key array is null

Method Details

equals

public boolean equals(Object other)

Compares this object to another.

To be equal, the other object must be a MultiKey with the same number of keys which are also equal.

Parameters:
other - the other object to compare to
Returns:
true if equal

getKeys

public Object[] getKeys()

Gets a copy of the individual keys.

Returns:
the individual keys

hashCode

public int hashCode()

Gets the combined hash code that is computed from all the keys.

This value is computed once and then cached, so elements should not change their hash codes once created (note that this is the same constraint that would be used if the individual keys elements were themselves java.util.Map Map keys.

Returns:
the hash code

toString

public String toString()

Gets a debugging string version of the key.

Returns:
a debugging string