| java.lang.Object org.apache.commons.collections.keyvalue.MultiKey
MultiKey | public class MultiKey implements Serializable(Code) | | 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.
Example usage:
// populate map with data mapping key+locale to localizedText
Map map = new HashMap();
MultiKey multiKey = new MultiKey(key, locale);
map.put(multiKey, localizedText);
// later retireve the localized text
MultiKey multiKey = new MultiKey(key, locale);
String localizedText = (String) map.get(multiKey);
since: Commons Collections 3.0 version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $ author: Howard Lewis Ship author: Stephen Colebourne |
Constructor Summary | |
public | MultiKey(Object key1, Object key2) Constructor taking two keys. | public | MultiKey(Object key1, Object key2, Object key3) Constructor taking three keys. | public | MultiKey(Object key1, Object key2, Object key3, Object key4) Constructor taking four keys. | public | MultiKey(Object key1, Object key2, Object key3, Object key4, Object key5) Constructor taking five keys. | public | MultiKey(Object[] keys) Constructor taking an array of keys which is cloned. | public | MultiKey(Object[] keys, boolean makeClone) Constructor taking an array of keys, optionally choosing whether to clone. |
Method Summary | |
public boolean | equals(Object other) Compares this object to another. | public Object | getKey(int index) Gets the key at the specified index. | public Object[] | getKeys() Gets a clone of the array of keys. | public int | hashCode() Gets the combined hash code that is computed from all the keys. | public int | size() Gets the size of the list of keys. | public String | toString() Gets a debugging string version of the key. |
MultiKey | public MultiKey(Object key1, Object key2)(Code) | | Constructor taking two keys.
The keys should be immutable
If they are not then they must not be changed after adding to the MultiKey.
Parameters: key1 - the first key Parameters: key2 - the second key |
MultiKey | public MultiKey(Object key1, Object key2, Object key3)(Code) | | Constructor taking three keys.
The keys should be immutable
If they are not then they must not be changed after adding to the MultiKey.
Parameters: key1 - the first key Parameters: key2 - the second key Parameters: key3 - the third key |
MultiKey | public MultiKey(Object key1, Object key2, Object key3, Object key4)(Code) | | Constructor taking four keys.
The keys should be immutable
If they are not then they must not be changed after adding to the MultiKey.
Parameters: key1 - the first key Parameters: key2 - the second key Parameters: key3 - the third key Parameters: key4 - the fourth key |
MultiKey | public MultiKey(Object key1, Object key2, Object key3, Object key4, Object key5)(Code) | | Constructor taking five keys.
The keys should be immutable
If they are not then they must not be changed after adding to the MultiKey.
Parameters: key1 - the first key Parameters: key2 - the second key Parameters: key3 - the third key Parameters: key4 - the fourth key Parameters: key5 - the fifth key |
MultiKey | public MultiKey(Object[] keys)(Code) | | Constructor taking an array of keys which is cloned.
The keys should be immutable
If they are not then they must not be changed after adding to the MultiKey.
This is equivalent to new MultiKey(keys, true) .
Parameters: keys - the array of keys, not null throws: IllegalArgumentException - if the key array is null |
MultiKey | public MultiKey(Object[] keys, boolean makeClone)(Code) | | Constructor taking an array of keys, optionally choosing whether to clone.
If the array is not cloned, then it must not be modified.
This method is public for performance reasons only, to avoid a clone.
The hashcode is calculated once here in this method.
Therefore, changing the array passed in would not change the hashcode but
would change the equals method, which is a bug.
This is the only fully safe usage of this constructor, as the object array
is never made available in a variable:
new MultiKey(new Object[] {...}, false);
The keys should be immutable
If they are not then they must not be changed after adding to the MultiKey.
Parameters: keys - the array of keys, not null Parameters: makeClone - true to clone the array, false to assign it throws: IllegalArgumentException - if the key array is null since: Commons Collections 3.1 |
equals | public boolean equals(Object other)(Code) | | 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 true if equal |
getKey | public Object getKey(int index)(Code) | | Gets the key at the specified index.
The key should be immutable.
If it is not then it must not be changed.
Parameters: index - the index to retrieve the key at the index throws: IndexOutOfBoundsException - if the index is invalid since: Commons Collections 3.1 |
getKeys | public Object[] getKeys()(Code) | | Gets a clone of the array of keys.
The keys should be immutable
If they are not then they must not be changed.
the individual keys |
hashCode | public int hashCode()(Code) | | 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.
the hash code |
size | public int size()(Code) | | Gets the size of the list of keys.
the size of the list of keys since: Commons Collections 3.1 |
toString | public String toString()(Code) | | Gets a debugging string version of the key.
a debugging string |
|
|