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


java.lang.Object
   org.apache.commons.collections.bidimap.TreeBidiMap

TreeBidiMap
public class TreeBidiMap implements OrderedBidiMap(Code)
Red-Black tree-based implementation of BidiMap where all objects added implement the Comparable interface.

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. If the data contained in the TreeMaps is large, the cost of redundant storage becomes significant. The DualTreeBidiMap and DualHashBidiMap implementations use this approach.

This solution keeps minimizes the data storage by holding data only once. The red-black algorithm is based on java util TreeMap, 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.

The Map.Entry instances returned by the appropriate methods will not allow setValue() and will throw an UnsupportedOperationException on attempts to call that method.
since:
   Commons Collections 3.0 (previously DoubleOrderedMap v2.0)
version:
   $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
author:
   Marc Johnson
author:
   Stephen Colebourne


Inner Class :static class View extends AbstractSet
Inner Class :static class ViewIterator implements OrderedIterator
Inner Class :static class ViewMapIterator extends ViewIterator implements OrderedMapIterator
Inner Class :static class EntryView extends View
Inner Class :static class Node implements Map.Entry,KeyValue
Inner Class :static class Inverse implements OrderedBidiMap


Constructor Summary
public  TreeBidiMap()
     Constructs a new empty TreeBidiMap.
public  TreeBidiMap(Map map)
     Constructs a new TreeBidiMap by copying an existing Map.

Method Summary
public  voidclear()
     Removes all mappings from this map.
public  booleancontainsKey(Object key)
     Checks whether this map contains the a mapping for the specified key.
public  booleancontainsValue(Object value)
     Checks whether this map contains the a mapping for the specified value.
public  SetentrySet()
     Returns a set view of the entries contained in this map in key order. For simple iteration through the map, the MapIterator is quicker.

The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.

public  booleanequals(Object obj)
     Compares for equals as per the API.
public  ObjectfirstKey()
     Gets the first (lowest) key currently in this map.
public  Objectget(Object key)
     Gets the value to which this map maps the specified key.
public  ObjectgetKey(Object value)
     Returns the key to which this map maps the specified value. Returns null if the map contains no mapping for this value.

The value must implement Comparable.
Parameters:
  value - value whose associated key is to be returned.

public  inthashCode()
     Gets the hash code value for this map as per the API.
public  BidiMapinverseBidiMap()
     Gets the inverse map for comparison.
public  OrderedBidiMapinverseOrderedBidiMap()
     Gets the inverse map for comparison.
public  booleanisEmpty()
     Checks whether the map is empty or not.
public  SetkeySet()
     Returns a set view of the keys contained in this map in key order.

The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.

public  ObjectlastKey()
     Gets the last (highest) key currently in this map.
public  MapIteratormapIterator()
     Gets an iterator over the map entries.
public  ObjectnextKey(Object key)
     Gets the next key after the one specified.
public  OrderedMapIteratororderedMapIterator()
     Gets an ordered iterator over the map entries.
public  ObjectpreviousKey(Object key)
     Gets the previous key before the one specified.
public  Objectput(Object key, Object value)
     Puts the key-value pair into the map, replacing any previous pair.

When adding a key-value pair, the value may already exist in the map against a different key.

public  voidputAll(Map map)
     Puts all the mappings from the specified map into this map.
public  Objectremove(Object key)
     Removes the mapping for this key from this map if present.

The key must implement Comparable.
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.
public  intsize()
     Returns the number of key-value mappings in this map.
public  StringtoString()
     Returns a string version of this Map in standard format.
public  Collectionvalues()
     Returns a set view of the values contained in this map in key order. The returned object can be cast to a Set.

The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.



Constructor Detail
TreeBidiMap
public TreeBidiMap()(Code)
Constructs a new empty TreeBidiMap.



TreeBidiMap
public TreeBidiMap(Map map)(Code)
Constructs a new TreeBidiMap by copying an existing Map.
Parameters:
  map - the map to copy
throws:
  ClassCastException - if the keys/values in the map arenot Comparable or are not mutually comparable
throws:
  NullPointerException - if any key or value in the map is null




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



containsKey
public boolean containsKey(Object key)(Code)
Checks whether this map contains the a mapping for the specified key.

The key must implement Comparable.
Parameters:
  key - key whose presence in this map is to be tested true if this map contains a mapping for the specified key
throws:
  ClassCastException - if the key is of an inappropriate type
throws:
  NullPointerException - if the key is null




containsValue
public boolean containsValue(Object value)(Code)
Checks whether this map contains the a mapping for the specified value.

The value must implement Comparable.
Parameters:
  value - value whose presence in this map is to be tested true if this map contains a mapping for the specified value
throws:
  ClassCastException - if the value is of an inappropriate type
throws:
  NullPointerException - if the value is null




entrySet
public Set entrySet()(Code)
Returns a set view of the entries contained in this map in key order. For simple iteration through the map, the MapIterator is quicker.

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. It does not support the add or addAll operations. The returned MapEntry objects do not support setValue. a set view of the values contained in this map.




equals
public boolean equals(Object obj)(Code)
Compares for equals as per the API.
Parameters:
  obj - the object to compare to true if equal



firstKey
public Object firstKey()(Code)
Gets the first (lowest) key currently in this map. the first (lowest) key currently in this sorted map
throws:
  NoSuchElementException - if this map is empty



get
public Object get(Object key)(Code)
Gets the value to which this map maps the specified key. Returns null if the map contains no mapping for this key.

The key must implement Comparable.
Parameters:
  key - key whose associated value is to be returned the value to which this map maps the specified key,or null if the map contains no mapping for this key
throws:
  ClassCastException - if the key is of an inappropriate type
throws:
  NullPointerException - if the key is null




getKey
public Object getKey(Object value)(Code)
Returns the key to which this map maps the specified value. Returns null if the map contains no mapping for this value.

The value must implement Comparable.
Parameters:
  value - value whose associated key is to be returned. the key to which this map maps the specified value,or null if the map contains no mapping for this value.
throws:
  ClassCastException - if the value is of an inappropriate type
throws:
  NullPointerException - if the value is null




hashCode
public int hashCode()(Code)
Gets the hash code value for this map as per the API. the hash code value for this map



inverseBidiMap
public BidiMap inverseBidiMap()(Code)
Gets the inverse map for comparison. the inverse map



inverseOrderedBidiMap
public OrderedBidiMap inverseOrderedBidiMap()(Code)
Gets the inverse map for comparison. the inverse map



isEmpty
public boolean isEmpty()(Code)
Checks whether the map is empty or not. true if the map is empty



keySet
public Set keySet()(Code)
Returns a set view of the keys contained in this map in key order.

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. It does not support the add or addAll operations. a set view of the keys contained in this map.




lastKey
public Object lastKey()(Code)
Gets the last (highest) key currently in this map. the last (highest) key currently in this sorted map
throws:
  NoSuchElementException - if this map is empty



mapIterator
public MapIterator mapIterator()(Code)
Gets an iterator over the map entries.

For this map, this iterator is the fastest way to iterate over the entries. an iterator




nextKey
public Object nextKey(Object key)(Code)
Gets the next key after the one specified.

The key must implement Comparable.
Parameters:
  key - the key to search for next from the next key, null if no match or at end




orderedMapIterator
public OrderedMapIterator orderedMapIterator()(Code)
Gets an ordered iterator over the map entries.

This iterator allows both forward and reverse iteration over the entries. an iterator




previousKey
public Object previousKey(Object key)(Code)
Gets the previous key before the one specified.

The key must implement Comparable.
Parameters:
  key - the key to search for previous from the previous key, null if no match or at start




put
public Object put(Object key, Object value)(Code)
Puts the key-value pair into the map, replacing any previous pair.

When adding a key-value pair, the value may already exist in the map against a different key. That mapping is removed, to ensure that the value only occurs once in the inverse map.

 BidiMap map1 = new TreeBidiMap();
 map.put("A","B");  // contains A mapped to B, as per Map
 map.put("A","C");  // contains A mapped to C, as per Map
 BidiMap map2 = new TreeBidiMap();
 map.put("A","B");  // contains A mapped to B, as per Map
 map.put("C","B");  // contains C mapped to B, key A is removed
 

Both key and value must implement Comparable.
Parameters:
  key - key with which the specified value is to be associated
Parameters:
  value - value to be associated with the specified key the previous value for the key
throws:
  ClassCastException - if the key is of an inappropriate type
throws:
  NullPointerException - if the key is null




putAll
public void putAll(Map map)(Code)
Puts all the mappings from the specified map into this map.

All keys and values must implement Comparable.
Parameters:
  map - the map to copy from




remove
public Object remove(Object key)(Code)
Removes the mapping for this key from this map if present.

The key must implement Comparable.
Parameters:
  key - key whose mapping is to be removed from the map. previous value associated with specified key,or null if there was no mapping for key.
throws:
  ClassCastException - if the key is of an inappropriate type
throws:
  NullPointerException - if the key is null




removeValue
public Object removeValue(Object value)(Code)
Removes the mapping for this value from this map if present.

The value must implement Comparable.
Parameters:
  value - value whose mapping is to be removed from the map previous key associated with specified value,or null if there was no mapping for value.
throws:
  ClassCastException - if the value is of an inappropriate type
throws:
  NullPointerException - if the value is null




size
public int size()(Code)
Returns the number of key-value mappings in this map. the number of key-value mappings in this map



toString
public String toString()(Code)
Returns a string version of this Map in standard format. a standard format string version of the map



values
public Collection values()(Code)
Returns a set view of the values contained in this map in key order. The returned object can be cast to a Set.

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. It does not support the add or addAll operations. a set view of the values contained in this map.




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.