Java Doc for DoubleOrderedMap.java in  » Library » Apache-common-Collections » org » apache » commons » collections » 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 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.AbstractMap
      org.apache.commons.collections.DoubleOrderedMap

DoubleOrderedMap
final public class DoubleOrderedMap extends AbstractMap (Code)
Red-Black tree-based implementation of Map. This class guarantees that the map will be in both ascending key order and ascending value order, sorted according to the natural order for the key's and value's classes.

This Map is intended for applications that need to be able to look up a key-value pairing by either key or value, and need to do so with equal efficiency.

While that goal could be accomplished by taking a pair of TreeMaps and redirecting requests to the appropriate TreeMap (e.g., containsKey would be directed to the TreeMap that maps values to keys, containsValue would be directed to the TreeMap that maps keys to values), there are problems with that implementation, particularly when trying to keep the two TreeMaps synchronized with each other. And if the data contained in the TreeMaps is large, the cost of redundant storage becomes significant. (See also the new org.apache.commons.collections.bidimap.DualTreeBidiMap DualTreeBidiMap and org.apache.commons.collections.bidimap.DualHashBidiMap DualHashBidiMap implementations.)

This solution keeps the data properly synchronized and minimizes the data storage. The red-black algorithm is based on TreeMap's, but has been modified to simultaneously map a tree node by key and by value. This doubles the cost of put operations (but so does using two TreeMaps), and nearly doubles the cost of remove operations (there is a savings in that the lookup of the node to be removed only has to be performed once). And since only one node contains the key and value, storage is significantly less than that required by two TreeMaps.

There are some limitations placed on data kept in this Map. The biggest one is this:

When performing a put operation, neither the key nor the value may already exist in the Map. In the java.util Map implementations (HashMap, TreeMap), you can perform a put with an already mapped key, and neither cares about duplicate values at all ... but this implementation's put method with throw an IllegalArgumentException if either the key or the value is already in the Map.

Obviously, that same restriction (and consequence of failing to heed that restriction) applies to the putAll method.

The Map.Entry instances returned by the appropriate methods will not allow setValue() and will throw an UnsupportedOperationException on attempts to call that method.

New methods are added to take advantage of the fact that values are kept sorted independently of their keys:

Object getKeyForValue(Object value) is the opposite of get; it takes a value and returns its key, if any.

Object removeValue(Object value) finds and removes the specified value and returns the now un-used key.

Set entrySetByValue() returns the Map.Entry's in a Set whose iterator will iterate over the Map.Entry's in ascending order by their corresponding values.

Set keySetByValue() returns the keys in a Set whose iterator will iterate over the keys in ascending order by their corresponding values.

Collection valuesByValue() returns the values in a Collection whose iterator will iterate over the values in ascending order.
See Also:   BidiMap
See Also:   org.apache.commons.collections.bidimap.DualTreeBidiMap
See Also:   org.apache.commons.collections.bidimap.DualHashBidiMap
since:
   Commons Collections 2.0
version:
   $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
author:
   Marc Johnson




Constructor Summary
public  DoubleOrderedMap()
    
public  DoubleOrderedMap(Map map)
    

Method Summary
public  voidclear()
    
public  booleancontainsKey(Object key)
     Returns true if this map contains a mapping for the specified key.
Parameters:
  key - key whose presence in this map is to be tested.
public  booleancontainsValue(Object value)
     Returns true if this map maps one or more keys to the specified value.
Parameters:
  value - value whose presence in this map is to be tested.
public  SetentrySet()
     Returns a set view of the mappings contained in this map.
public  SetentrySetByValue()
     Returns a set view of the mappings contained in this map.
public  Objectget(Object key)
     Returns the value to which this map maps the specified key.
public  ObjectgetKeyForValue(Object value)
     Returns the key to which this map maps the specified value. Returns null if the map contains no mapping for this value.
Parameters:
  value - value whose associated key is to be returned.
public  SetkeySet()
     Returns a set view of the keys contained in this map.
public  SetkeySetByValue()
     Returns a set view of the keys contained in this map.
public  Objectput(Object key, Object value)
     Associates the specified value with the specified key in this map.
Parameters:
  key - key with which the specified value is to beassociated.
Parameters:
  value - value to be associated with the specified key.
public  Objectremove(Object key)
     Removes the mapping for this key from this map if present
Parameters:
  key - key whose mapping is to be removed from the map.
public  ObjectremoveValue(Object value)
     Removes the mapping for this value from this map if present
Parameters:
  value - value whose mapping is to be removed from the map.
public  intsize()
     Returns the number of key-value mappings in this map.
public  Collectionvalues()
     Returns a collection view of the values contained in this map.
public  CollectionvaluesByValue()
     Returns a collection view of the values contained in this map.


Constructor Detail
DoubleOrderedMap
public DoubleOrderedMap()(Code)
Construct a new DoubleOrderedMap



DoubleOrderedMap
public DoubleOrderedMap(Map map) throws ClassCastException, NullPointerException, IllegalArgumentException(Code)
Constructs a new DoubleOrderedMap from an existing Map, with keys and values sorted
Parameters:
  map - the map whose mappings are to be placed in this map.
throws:
  ClassCastException - if the keys in the map are notComparable, or are not mutuallycomparable; also if the values inthe map are not Comparable, orare not mutually Comparable
throws:
  NullPointerException - if any key or value in the mapis null
throws:
  IllegalArgumentException - if there are duplicate keysor duplicate values in themap




Method Detail
clear
public void clear()(Code)
Removes all mappings from this map



containsKey
public boolean containsKey(Object key) throws ClassCastException, NullPointerException(Code)
Returns true if this map contains a mapping for the specified key.
Parameters:
  key - key whose presence in this map is to be tested. true if this map contains a mapping for the specifiedkey.
throws:
  ClassCastException - if the key is of an inappropriatetype for this map.
throws:
  NullPointerException - if the key is null



containsValue
public boolean containsValue(Object value)(Code)
Returns true if this map maps one or more keys to the specified value.
Parameters:
  value - value whose presence in this map is to be tested. true if this map maps one or more keys to the specifiedvalue.



entrySet
public Set entrySet()(Code)
Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined.

The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations. The setValue method is not supported on the Map Entry. a set view of the mappings contained in this map.




entrySetByValue
public Set entrySetByValue()(Code)
Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

The difference between this method and entrySet is that entrySet's iterator() method returns an iterator that iterates over the mappings in ascending order by key. This method's iterator method iterates over the mappings in ascending order by value. a set view of the mappings contained in this map.




get
public Object get(Object key) throws ClassCastException, NullPointerException(Code)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key.
Parameters:
  key - key whose associated value is to be returned. the value to which this map maps the specified key, ornull if the map contains no mapping for this key.
throws:
  ClassCastException - if the key is of an inappropriatetype for this map.
throws:
  NullPointerException - if the key is null



getKeyForValue
public Object getKeyForValue(Object value) throws ClassCastException, NullPointerException(Code)
Returns the key to which this map maps the specified value. Returns null if the map contains no mapping for this value.
Parameters:
  value - value whose associated key is to be returned. the key to which this map maps the specified value, ornull if the map contains no mapping for this value.
throws:
  ClassCastException - if the value is of aninappropriate type for this map.
throws:
  NullPointerException - if the value is null



keySet
public Set keySet()(Code)
Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations. a set view of the keys contained in this map.



keySetByValue
public Set keySetByValue()(Code)
Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The difference between this method and keySet is that keySet's iterator() method returns an iterator that iterates over the keys in ascending order by key. This method's iterator method iterates over the keys in ascending order by value. a set view of the keys contained in this map.




put
public Object put(Object key, Object value) throws ClassCastException, NullPointerException, IllegalArgumentException(Code)
Associates the specified value with the specified key in this map.
Parameters:
  key - key with which the specified value is to beassociated.
Parameters:
  value - value to be associated with the specified key. null
throws:
  ClassCastException - if the class of the specified keyor value prevents it from beingstored in this map.
throws:
  NullPointerException - if the specified key or valueis null
throws:
  IllegalArgumentException - if the key duplicates anexisting key, or if thevalue duplicates anexisting value



remove
public Object remove(Object key)(Code)
Removes the mapping for this key from this map if present
Parameters:
  key - key whose mapping is to be removed from the map. previous value associated with specified key, or nullif there was no mapping for key.



removeValue
public Object removeValue(Object value)(Code)
Removes the mapping for this value from this map if present
Parameters:
  value - value whose mapping is to be removed from the map. previous key associated with specified value, or nullif there was no mapping for value.



size
public int size()(Code)
Returns the number of key-value mappings in this map. If the map contains more than Integer.MAXVALUE elements, returns Integer.MAXVALUE. the number of key-value mappings in this map.



values
public Collection values()(Code)
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations. a collection view of the values contained in this map.



valuesByValue
public Collection valuesByValue()(Code)
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

The difference between this method and values is that values's iterator() method returns an iterator that iterates over the values in ascending order by key. This method's iterator method iterates over the values in ascending order by key. a collection view of the values contained in this map.




Methods inherited from java.util.AbstractMap
public void clear()(Code)(Java Doc)
protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean containsKey(Object key)(Code)(Java Doc)
public boolean containsValue(Object value)(Code)(Java Doc)
abstract public Set<Entry<K, V>> entrySet()(Code)(Java Doc)
public boolean equals(Object o)(Code)(Java Doc)
public V get(Object key)(Code)(Java Doc)
public int hashCode()(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)
public Set<K> keySet()(Code)(Java Doc)
public V put(K key, V value)(Code)(Java Doc)
public void putAll(Map<? extends K, ? extends V> m)(Code)(Java Doc)
public V remove(Object key)(Code)(Java Doc)
public int size()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
public Collection<V> values()(Code)(Java Doc)

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.