Java Doc for MultiKeyMap.java in  » Library » Apache-common-Collections » org » apache » commons » collections » map » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common Collections » org.apache.commons.collections.map 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.collections.map.MultiKeyMap

MultiKeyMap
public class MultiKeyMap implements IterableMap,Serializable(Code)
A Map implementation that uses multiple keys to map the value.

This class is the most efficient way to uses multiple keys to map to a value. The best way to use this class is via the additional map-style methods. These provide get, containsKey, put and remove for individual keys which operate without extra object creation.

The additional methods are the main interface of this map. As such, you will not normally hold this map in a variable of type Map.

The normal map methods take in and return a MultiKey . If you try to use put() with any other object type a ClassCastException is thrown. If you try to use null as the key in put() a NullPointerException is thrown.

This map is implemented as a decorator of a AbstractHashedMap which enables extra behaviour to be added easily.

  • MultiKeyMap.decorate(new LinkedMap()) creates an ordered map.
  • MultiKeyMap.decorate(new LRUMap()) creates an least recently used map.
  • MultiKeyMap.decorate(new ReferenceMap()) creates a garbage collector sensitive map.
Note that IdentityMap and ReferenceIdentityMap are unsuitable for use as the key comparison would work on the whole MultiKey, not the elements within.

As an example, consider a least recently used cache that uses a String airline code and a Locale to lookup the airline's name:

 private MultiKeyMap cache = MultiKeyMap.decorate(new LRUMap(50));
 public String getAirlineName(String code, String locale) {
 String name = (String) cache.get(code, locale);
 if (name == null) {
 name = getAirlineNameFromDB(code, locale);
 cache.put(code, locale, name);
 }
 return name;
 }
 

Note that MultiKeyMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. This class may throw exceptions when accessed by concurrent threads without synchronization.
since:
   Commons Collections 3.1
version:
   $Revision: 348007 $ $Date: 2005-11-21 22:52:57 +0000 (Mon, 21 Nov 2005) $
author:
   Stephen Colebourne



Field Summary
final protected  AbstractHashedMapmap
    

Constructor Summary
public  MultiKeyMap()
     Constructs a new MultiKeyMap that decorates a HashedMap.
protected  MultiKeyMap(AbstractHashedMap map)
     Constructor that decorates the specified map and is called from MultiKeyMap.decorate(AbstractHashedMap) .

Method Summary
protected  voidcheckKey(Object key)
     Check to ensure that input keys are valid MultiKey objects.
public  voidclear()
    
public  Objectclone()
     Clones the map without cloning the keys or values.
public  booleancontainsKey(Object key1, Object key2)
     Checks whether the map contains the specified multi-key.
public  booleancontainsKey(Object key1, Object key2, Object key3)
     Checks whether the map contains the specified multi-key.
public  booleancontainsKey(Object key1, Object key2, Object key3, Object key4)
     Checks whether the map contains the specified multi-key.
public  booleancontainsKey(Object key1, Object key2, Object key3, Object key4, Object key5)
     Checks whether the map contains the specified multi-key.
public  booleancontainsKey(Object key)
    
public  booleancontainsValue(Object value)
    
public static  MultiKeyMapdecorate(AbstractHashedMap map)
     Decorates the specified map to add the MultiKeyMap API and fast query.
public  SetentrySet()
    
public  booleanequals(Object obj)
    
public  Objectget(Object key1, Object key2)
     Gets the value mapped to the specified multi-key.
public  Objectget(Object key1, Object key2, Object key3)
     Gets the value mapped to the specified multi-key.
public  Objectget(Object key1, Object key2, Object key3, Object key4)
     Gets the value mapped to the specified multi-key.
public  Objectget(Object key1, Object key2, Object key3, Object key4, Object key5)
     Gets the value mapped to the specified multi-key.
public  Objectget(Object key)
    
protected  inthash(Object key1, Object key2)
     Gets the hash code for the specified multi-key.
protected  inthash(Object key1, Object key2, Object key3)
     Gets the hash code for the specified multi-key.
protected  inthash(Object key1, Object key2, Object key3, Object key4)
     Gets the hash code for the specified multi-key.
protected  inthash(Object key1, Object key2, Object key3, Object key4, Object key5)
     Gets the hash code for the specified multi-key.
public  inthashCode()
    
public  booleanisEmpty()
    
protected  booleanisEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2)
     Is the key equal to the combined key.
protected  booleanisEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3)
     Is the key equal to the combined key.
protected  booleanisEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3, Object key4)
     Is the key equal to the combined key.
protected  booleanisEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3, Object key4, Object key5)
     Is the key equal to the combined key.
public  SetkeySet()
    
public  MapIteratormapIterator()
    
public  Objectput(Object key1, Object key2, Object value)
     Stores the value against the specified multi-key.
public  Objectput(Object key1, Object key2, Object key3, Object value)
     Stores the value against the specified multi-key.
public  Objectput(Object key1, Object key2, Object key3, Object key4, Object value)
     Stores the value against the specified multi-key.
public  Objectput(Object key1, Object key2, Object key3, Object key4, Object key5, Object value)
     Stores the value against the specified multi-key.
public  Objectput(Object key, Object value)
     Puts the key and value into the map, where the key must be a non-null MultiKey object.
public  voidputAll(Map mapToCopy)
     Copies all of the keys and values from the specified map to this map.
public  Objectremove(Object key1, Object key2)
     Removes the specified multi-key from this map.
public  Objectremove(Object key1, Object key2, Object key3)
     Removes the specified multi-key from this map.
public  Objectremove(Object key1, Object key2, Object key3, Object key4)
     Removes the specified multi-key from this map.
public  Objectremove(Object key1, Object key2, Object key3, Object key4, Object key5)
     Removes the specified multi-key from this map.
public  Objectremove(Object key)
    
public  booleanremoveAll(Object key1)
     Removes all mappings where the first key is that specified.
public  booleanremoveAll(Object key1, Object key2)
     Removes all mappings where the first two keys are those specified.
public  booleanremoveAll(Object key1, Object key2, Object key3)
     Removes all mappings where the first three keys are those specified.
public  booleanremoveAll(Object key1, Object key2, Object key3, Object key4)
     Removes all mappings where the first four keys are those specified.
public  intsize()
    
public  StringtoString()
    
public  Collectionvalues()
    

Field Detail
map
final protected AbstractHashedMap map(Code)
The decorated map




Constructor Detail
MultiKeyMap
public MultiKeyMap()(Code)
Constructs a new MultiKeyMap that decorates a HashedMap.



MultiKeyMap
protected MultiKeyMap(AbstractHashedMap map)(Code)
Constructor that decorates the specified map and is called from MultiKeyMap.decorate(AbstractHashedMap) . The map must not be null and should be empty or only contain valid keys. This constructor performs no validation.
Parameters:
  map - the map to decorate




Method Detail
checkKey
protected void checkKey(Object key)(Code)
Check to ensure that input keys are valid MultiKey objects.
Parameters:
  key - the key to check



clear
public void clear()(Code)



clone
public Object clone()(Code)
Clones the map without cloning the keys or values. a shallow clone



containsKey
public boolean containsKey(Object key1, Object key2)(Code)
Checks whether the map contains the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key true if the map contains the key



containsKey
public boolean containsKey(Object key1, Object key2, Object key3)(Code)
Checks whether the map contains the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key true if the map contains the key



containsKey
public boolean containsKey(Object key1, Object key2, Object key3, Object key4)(Code)
Checks whether the map contains the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key
Parameters:
  key4 - the fourth key true if the map contains the key



containsKey
public boolean containsKey(Object key1, Object key2, Object key3, Object key4, Object key5)(Code)
Checks whether the map contains the specified multi-key.
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 true if the map contains the key



containsKey
public boolean containsKey(Object key)(Code)



containsValue
public boolean containsValue(Object value)(Code)



decorate
public static MultiKeyMap decorate(AbstractHashedMap map)(Code)
Decorates the specified map to add the MultiKeyMap API and fast query. The map must not be null and must be empty.
Parameters:
  map - the map to decorate, not null
throws:
  IllegalArgumentException - if the map is null or not empty



entrySet
public Set entrySet()(Code)



equals
public boolean equals(Object obj)(Code)



get
public Object get(Object key1, Object key2)(Code)
Gets the value mapped to the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key the mapped value, null if no match



get
public Object get(Object key1, Object key2, Object key3)(Code)
Gets the value mapped to the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key the mapped value, null if no match



get
public Object get(Object key1, Object key2, Object key3, Object key4)(Code)
Gets the value mapped to the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key
Parameters:
  key4 - the fourth key the mapped value, null if no match



get
public Object get(Object key1, Object key2, Object key3, Object key4, Object key5)(Code)
Gets the value mapped to the specified multi-key.
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 the mapped value, null if no match



get
public Object get(Object key)(Code)



hash
protected int hash(Object key1, Object key2)(Code)
Gets the hash code for the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key the hash code



hash
protected int hash(Object key1, Object key2, Object key3)(Code)
Gets the hash code for the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key the hash code



hash
protected int hash(Object key1, Object key2, Object key3, Object key4)(Code)
Gets the hash code for the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key
Parameters:
  key4 - the fourth key the hash code



hash
protected int hash(Object key1, Object key2, Object key3, Object key4, Object key5)(Code)
Gets the hash code for the specified multi-key.
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 the hash code



hashCode
public int hashCode()(Code)



isEmpty
public boolean isEmpty()(Code)



isEqualKey
protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2)(Code)
Is the key equal to the combined key.
Parameters:
  entry - the entry to compare to
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key true if the key matches



isEqualKey
protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3)(Code)
Is the key equal to the combined key.
Parameters:
  entry - the entry to compare to
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key true if the key matches



isEqualKey
protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3, Object key4)(Code)
Is the key equal to the combined key.
Parameters:
  entry - the entry to compare to
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key
Parameters:
  key4 - the fourth key true if the key matches



isEqualKey
protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3, Object key4, Object key5)(Code)
Is the key equal to the combined key.
Parameters:
  entry - the entry to compare to
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 true if the key matches



keySet
public Set keySet()(Code)



mapIterator
public MapIterator mapIterator()(Code)



put
public Object put(Object key1, Object key2, Object value)(Code)
Stores the value against the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  value - the value to store the value previously mapped to this combined key, null if none



put
public Object put(Object key1, Object key2, Object key3, Object value)(Code)
Stores the value against the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key
Parameters:
  value - the value to store the value previously mapped to this combined key, null if none



put
public Object put(Object key1, Object key2, Object key3, Object key4, Object value)(Code)
Stores the value against the specified multi-key.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key
Parameters:
  key4 - the fourth key
Parameters:
  value - the value to store the value previously mapped to this combined key, null if none



put
public Object put(Object key1, Object key2, Object key3, Object key4, Object key5, Object value)(Code)
Stores the value against the specified multi-key.
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
Parameters:
  value - the value to store the value previously mapped to this combined key, null if none



put
public Object put(Object key, Object value)(Code)
Puts the key and value into the map, where the key must be a non-null MultiKey object.
Parameters:
  key - the non-null MultiKey object
Parameters:
  value - the value to store the previous value for the key
throws:
  NullPointerException - if the key is null
throws:
  ClassCastException - if the key is not a MultiKey



putAll
public void putAll(Map mapToCopy)(Code)
Copies all of the keys and values from the specified map to this map. Each key must be non-null and a MultiKey object.
Parameters:
  mapToCopy - to this map
throws:
  NullPointerException - if the mapToCopy or any key within is null
throws:
  ClassCastException - if any key in mapToCopy is not a MultiKey



remove
public Object remove(Object key1, Object key2)(Code)
Removes the specified multi-key from this map.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key the value mapped to the removed key, null if key not in map



remove
public Object remove(Object key1, Object key2, Object key3)(Code)
Removes the specified multi-key from this map.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key the value mapped to the removed key, null if key not in map



remove
public Object remove(Object key1, Object key2, Object key3, Object key4)(Code)
Removes the specified multi-key from this map.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key
Parameters:
  key4 - the fourth key the value mapped to the removed key, null if key not in map



remove
public Object remove(Object key1, Object key2, Object key3, Object key4, Object key5)(Code)
Removes the specified multi-key from this map.
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 the value mapped to the removed key, null if key not in map



remove
public Object remove(Object key)(Code)



removeAll
public boolean removeAll(Object key1)(Code)
Removes all mappings where the first key is that specified.

This method removes all the mappings where the MultiKey has one or more keys, and the first matches that specified.
Parameters:
  key1 - the first key true if any elements were removed




removeAll
public boolean removeAll(Object key1, Object key2)(Code)
Removes all mappings where the first two keys are those specified.

This method removes all the mappings where the MultiKey has two or more keys, and the first two match those specified.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key true if any elements were removed




removeAll
public boolean removeAll(Object key1, Object key2, Object key3)(Code)
Removes all mappings where the first three keys are those specified.

This method removes all the mappings where the MultiKey has three or more keys, and the first three match those specified.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key true if any elements were removed




removeAll
public boolean removeAll(Object key1, Object key2, Object key3, Object key4)(Code)
Removes all mappings where the first four keys are those specified.

This method removes all the mappings where the MultiKey has four or more keys, and the first four match those specified.
Parameters:
  key1 - the first key
Parameters:
  key2 - the second key
Parameters:
  key3 - the third key
Parameters:
  key4 - the fourth key true if any elements were removed




size
public int size()(Code)



toString
public String toString()(Code)



values
public Collection values()(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.