org.apache.commons.collections.keyvalue
Class MultiKey

java.lang.Object
  |
  +--org.apache.commons.collections.keyvalue.MultiKey
All Implemented Interfaces:
Serializable

public class MultiKey
extends 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
Version:
$Revision: 1.3 $ $Date: 2004/01/14 21:43:15 $
Author:
Howard Lewis Ship, Stephen Colebourne
See Also:
Serialized Form

Constructor Summary
  MultiKey(Object[] keys)
          Constructor taking an array of keys.
protected MultiKey(Object[] keys, boolean makeCopy)
          Constructor taking an array of keys.
  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.
 
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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiKey

public MultiKey(Object key1,
                Object key2)
Constructor taking two keys.
Parameters:
key1 - the first key
key2 - the second 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,
                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,
                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[] keys)
Constructor taking an array of keys.
Parameters:
keys - the array of keys
Throws:
IllegalArgumentException - if the key array is null

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:
IllegalArgumentException - if the key array is null
Method Detail

getKeys

public Object[] getKeys()
Gets a copy of the individual keys.
Returns:
the individual keys

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.

Overrides:
equals in class Object
Parameters:
other - the other object to compare to
Returns:
true if equal

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 Map keys.

Overrides:
hashCode in class Object
Returns:
the hash code

toString

public String toString()
Gets a debugging string version of the key.
Overrides:
toString in class Object
Returns:
a debugging string


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