Java Doc for MapUtils.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
   org.apache.commons.collections.MapUtils

MapUtils
public class MapUtils (Code)
Provides utility methods and decorators for Map and SortedMap instances.

It contains various type safe methods as well as other useful features like deep copying.

It also provides the following decorators:


since:
   Commons Collections 1.0
version:
   $Revision: 357494 $ $Date: 2005-12-18 19:05:31 +0000 (Sun, 18 Dec 2005) $
author:
   James Strachan
author:
   Nissim Karpenstein
author:
   Kasper Nielsen
author:
   Paul Jack
author:
   Stephen Colebourne
author:
   Matthew Hawthorne
author:
   Arun Mammen Thomas
author:
   Janek Bogucki
author:
   Max Rydahl Andersen
author:
   Ashwin S
author:
   James Carman
author:
   Neil O'Toole


Field Summary
final public static  MapEMPTY_MAP
     An empty unmodifiable map.
final public static  SortedMapEMPTY_SORTED_MAP
     An empty unmodifiable sorted map.

Constructor Summary
public  MapUtils()
     MapUtils should not normally be instantiated.

Method Summary
public static  voiddebugPrint(PrintStream out, Object label, Map map)
     Prints the given map with nice line breaks.

This method prints a nicely formatted String describing the Map. Each map entry will be printed with key, value and value classname. When the value is a Map, recursive behaviour occurs.

This method is NOT thread-safe in any special way.

public static  MapfixedSizeMap(Map map)
     Returns a fixed-sized map backed by the given map.
public static  SortedMapfixedSizeSortedMap(SortedMap map)
     Returns a fixed-sized sorted map backed by the given sorted map.
public static  BooleangetBoolean(Map map, Object key)
     Gets a Boolean from a Map in a null-safe manner.
public static  BooleangetBoolean(Map map, Object key, Boolean defaultValue)
     Looks up the given key in the given map, converting the result into a boolean, using the default value if the the conversion fails.
public static  booleangetBooleanValue(Map map, Object key)
     Gets a boolean from a Map in a null-safe manner.
public static  booleangetBooleanValue(Map map, Object key, boolean defaultValue)
     Gets a boolean from a Map in a null-safe manner, using the default value if the the conversion fails.
public static  BytegetByte(Map map, Object key)
     Gets a Byte from a Map in a null-safe manner.
public static  BytegetByte(Map map, Object key, Byte defaultValue)
     Looks up the given key in the given map, converting the result into a byte, using the default value if the the conversion fails.
public static  bytegetByteValue(Map map, Object key)
     Gets a byte from a Map in a null-safe manner.
public static  bytegetByteValue(Map map, Object key, byte defaultValue)
     Gets a byte from a Map in a null-safe manner, using the default value if the the conversion fails.
public static  DoublegetDouble(Map map, Object key)
     Gets a Double from a Map in a null-safe manner.
public static  DoublegetDouble(Map map, Object key, Double defaultValue)
     Looks up the given key in the given map, converting the result into a double, using the default value if the the conversion fails.
public static  doublegetDoubleValue(Map map, Object key)
     Gets a double from a Map in a null-safe manner.
public static  doublegetDoubleValue(Map map, Object key, double defaultValue)
     Gets a double from a Map in a null-safe manner, using the default value if the the conversion fails.
public static  FloatgetFloat(Map map, Object key)
     Gets a Float from a Map in a null-safe manner.
public static  FloatgetFloat(Map map, Object key, Float defaultValue)
     Looks up the given key in the given map, converting the result into a float, using the default value if the the conversion fails.
public static  floatgetFloatValue(Map map, Object key)
     Gets a float from a Map in a null-safe manner.
public static  floatgetFloatValue(Map map, Object key, float defaultValue)
     Gets a float from a Map in a null-safe manner, using the default value if the the conversion fails.
public static  intgetIntValue(Map map, Object key)
     Gets an int from a Map in a null-safe manner.
public static  intgetIntValue(Map map, Object key, int defaultValue)
     Gets an int from a Map in a null-safe manner, using the default value if the the conversion fails.
public static  IntegergetInteger(Map map, Object key)
     Gets a Integer from a Map in a null-safe manner.
public static  IntegergetInteger(Map map, Object key, Integer defaultValue)
     Looks up the given key in the given map, converting the result into an integer, using the default value if the the conversion fails.
public static  LonggetLong(Map map, Object key)
     Gets a Long from a Map in a null-safe manner.
public static  LonggetLong(Map map, Object key, Long defaultValue)
     Looks up the given key in the given map, converting the result into a long, using the default value if the the conversion fails.
public static  longgetLongValue(Map map, Object key)
     Gets a long from a Map in a null-safe manner.
public static  longgetLongValue(Map map, Object key, long defaultValue)
     Gets a long from a Map in a null-safe manner, using the default value if the the conversion fails.
public static  MapgetMap(Map map, Object key)
     Gets a Map from a Map in a null-safe manner.
public static  MapgetMap(Map map, Object key, Map defaultValue)
     Looks up the given key in the given map, converting the result into a map, using the default value if the the conversion fails.
public static  NumbergetNumber(Map map, Object key)
     Gets a Number from a Map in a null-safe manner.
public static  NumbergetNumber(Map map, Object key, Number defaultValue)
     Looks up the given key in the given map, converting the result into a number, using the default value if the the conversion fails.
public static  ObjectgetObject(Map map, Object key)
     Gets from a Map in a null-safe manner.
public static  ObjectgetObject(Map map, Object key, Object defaultValue)
     Looks up the given key in the given map, converting null into the given default value.
public static  ShortgetShort(Map map, Object key)
     Gets a Short from a Map in a null-safe manner.
public static  ShortgetShort(Map map, Object key, Short defaultValue)
     Looks up the given key in the given map, converting the result into a short, using the default value if the the conversion fails.
public static  shortgetShortValue(Map map, Object key)
     Gets a short from a Map in a null-safe manner.
public static  shortgetShortValue(Map map, Object key, short defaultValue)
     Gets a short from a Map in a null-safe manner, using the default value if the the conversion fails.
public static  StringgetString(Map map, Object key)
     Gets a String from a Map in a null-safe manner.
public static  StringgetString(Map map, Object key, String defaultValue)
     Looks up the given key in the given map, converting the result into a string, using the default value if the the conversion fails.
public static  MapinvertMap(Map map)
     Inverts the supplied map returning a new HashMap such that the keys of the input are swapped with the values.
public static  booleanisEmpty(Map map)
     Null-safe check if the specified map is empty.
public static  booleanisNotEmpty(Map map)
     Null-safe check if the specified map is not empty.
public static  MaplazyMap(Map map, Factory factory)
     Returns a "lazy" map whose values will be created on demand.

When the key passed to the returned map's Map.get(Object) method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key.

For instance:

 Factory factory = new Factory() {
 public Object create() {
 return new Date();
 }
 }
 Map lazyMap = MapUtils.lazyMap(new HashMap(), factory);
 Object obj = lazyMap.get("test");
 
After the above code is executed, obj will contain a new Date instance.
public static  MaplazyMap(Map map, Transformer transformerFactory)
     Returns a "lazy" map whose values will be created on demand.

When the key passed to the returned map's Map.get(Object) method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key.

public static  SortedMaplazySortedMap(SortedMap map, Factory factory)
     Returns a "lazy" sorted map whose values will be created on demand.

When the key passed to the returned map's Map.get(Object) method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key.

For instance:

 Factory factory = new Factory() {
 public Object create() {
 return new Date();
 }
 }
 SortedMap lazy = MapUtils.lazySortedMap(new TreeMap(), factory);
 Object obj = lazy.get("test");
 
After the above code is executed, obj will contain a new Date instance.
public static  SortedMaplazySortedMap(SortedMap map, Transformer transformerFactory)
     Returns a "lazy" sorted map whose values will be created on demand.

When the key passed to the returned map's Map.get(Object) method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key.

protected static  voidlogInfo(Exception ex)
     Logs the given exception to System.out.
public static  MapmultiValueMap(Map map)
     Creates a mult-value map backed by the given map which returns collections of type ArrayList.
public static  MapmultiValueMap(Map map, Class collectionClass)
     Creates a multi-value map backed by the given map which returns collections of the specified type.
Parameters:
  map - the map to decorate
Parameters:
  collectionClass - the type of collections to return from the map (must contain public no-arg constructorand extend Collection).
public static  MapmultiValueMap(Map map, Factory collectionFactory)
     Creates a multi-value map backed by the given map which returns collections created by the specified collection factory.
public static  MaporderedMap(Map map)
     Returns a map that maintains the order of keys that are added backed by the given map.
public static  MappredicatedMap(Map map, Predicate keyPred, Predicate valuePred)
     Returns a predicated (validating) map backed by the given map.
public static  SortedMappredicatedSortedMap(SortedMap map, Predicate keyPred, Predicate valuePred)
     Returns a predicated (validating) sorted map backed by the given map.
public static  MapputAll(Map map, Object[] array)
     Puts all the keys and values from the specified array into the map.

This method is an alternative to the java.util.Map.putAll(java.util.Map) method and constructors.

public static  voidsafeAddToMap(Map map, Object key, Object value)
     Protects against adding null values to a map.
public static  MapsynchronizedMap(Map map)
     Returns a synchronized map backed by the given map.
public static  MapsynchronizedSortedMap(SortedMap map)
     Returns a synchronized sorted map backed by the given sorted map.
public static  MaptoMap(ResourceBundle resourceBundle)
     Creates a new HashMap using data copied from a ResourceBundle.
public static  PropertiestoProperties(Map map)
     Gets a new Properties object initialised with the values from a Map.
public static  MaptransformedMap(Map map, Transformer keyTransformer, Transformer valueTransformer)
     Returns a transformed map backed by the given map.

This method returns a new map (decorating the specified map) that will transform any new entries added to it. Existing entries in the specified map will not be transformed. If you want that behaviour, see TransformedMap.decorateTransform .

Each object is passed through the transformers as it is added to the Map.

public static  SortedMaptransformedSortedMap(SortedMap map, Transformer keyTransformer, Transformer valueTransformer)
     Returns a transformed sorted map backed by the given map.

This method returns a new sorted map (decorating the specified map) that will transform any new entries added to it. Existing entries in the specified map will not be transformed. If you want that behaviour, see TransformedSortedMap.decorateTransform .

Each object is passed through the transformers as it is added to the Map.

public static  MaptypedMap(Map map, Class keyType, Class valueType)
     Returns a typed map backed by the given map.
public static  SortedMaptypedSortedMap(SortedMap map, Class keyType, Class valueType)
     Returns a typed sorted map backed by the given map.
public static  MapunmodifiableMap(Map map)
     Returns an unmodifiable map backed by the given map.
public static  MapunmodifiableSortedMap(SortedMap map)
     Returns an unmodifiable sorted map backed by the given sorted map.
public static  voidverbosePrint(PrintStream out, Object label, Map map)
     Prints the given map with nice line breaks.

This method prints a nicely formatted String describing the Map. Each map entry will be printed with key and value. When the value is a Map, recursive behaviour occurs.

This method is NOT thread-safe in any special way.


Field Detail
EMPTY_MAP
final public static Map EMPTY_MAP(Code)
An empty unmodifiable map. This was not provided in JDK1.2.



EMPTY_SORTED_MAP
final public static SortedMap EMPTY_SORTED_MAP(Code)
An empty unmodifiable sorted map. This is not provided in the JDK.




Constructor Detail
MapUtils
public MapUtils()(Code)
MapUtils should not normally be instantiated.




Method Detail
debugPrint
public static void debugPrint(PrintStream out, Object label, Map map)(Code)
Prints the given map with nice line breaks.

This method prints a nicely formatted String describing the Map. Each map entry will be printed with key, value and value classname. When the value is a Map, recursive behaviour occurs.

This method is NOT thread-safe in any special way. You must manually synchronize on either this class or the stream as required.
Parameters:
  out - the stream to print to, must not be null
Parameters:
  label - The label to be used, may be null.If null, the label is not output.It typically represents the name of the property in a bean or similar.
Parameters:
  map - The map to print, may be null.If null, the text 'null' is output.
throws:
  NullPointerException - if the stream is null




fixedSizeMap
public static Map fixedSizeMap(Map map)(Code)
Returns a fixed-sized map backed by the given map. Elements may not be added or removed from the returned map, but existing elements can be changed (for instance, via the Map.put(ObjectObject) method).
Parameters:
  map - the map whose size to fix, must not be null a fixed-size map backed by that map
throws:
  IllegalArgumentException - if the Map is null



fixedSizeSortedMap
public static SortedMap fixedSizeSortedMap(SortedMap map)(Code)
Returns a fixed-sized sorted map backed by the given sorted map. Elements may not be added or removed from the returned map, but existing elements can be changed (for instance, via the Map.put(ObjectObject) method).
Parameters:
  map - the map whose size to fix, must not be null a fixed-size map backed by that map
throws:
  IllegalArgumentException - if the SortedMap is null



getBoolean
public static Boolean getBoolean(Map map, Object key)(Code)
Gets a Boolean from a Map in a null-safe manner.

If the value is a Boolean it is returned directly. If the value is a String and it equals 'true' ignoring case then true is returned, otherwise false. If the value is a Number an integer zero value returns false and non-zero returns true. Otherwise, null is returned.
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Boolean, null if null map input




getBoolean
public static Boolean getBoolean(Map map, Object key, Boolean defaultValue)(Code)
Looks up the given key in the given map, converting the result into a boolean, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a boolean, or defaultValue if the original value is null, the map is null or the boolean conversionfails



getBooleanValue
public static boolean getBooleanValue(Map map, Object key)(Code)
Gets a boolean from a Map in a null-safe manner.

If the value is a Boolean its value is returned. If the value is a String and it equals 'true' ignoring case then true is returned, otherwise false. If the value is a Number an integer zero value returns false and non-zero returns true. Otherwise, false is returned.
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Boolean, false if null map input




getBooleanValue
public static boolean getBooleanValue(Map map, Object key, boolean defaultValue)(Code)
Gets a boolean from a Map in a null-safe manner, using the default value if the the conversion fails.

If the value is a Boolean its value is returned. If the value is a String and it equals 'true' ignoring case then true is returned, otherwise false. If the value is a Number an integer zero value returns false and non-zero returns true. Otherwise, defaultValue is returned.
Parameters:
  map - the map to use
Parameters:
  key - the key to look up
Parameters:
  defaultValue - return if the value is null or if theconversion fails the value in the Map as a Boolean, defaultValue if null map input




getByte
public static Byte getByte(Map map, Object key)(Code)
Gets a Byte from a Map in a null-safe manner.

The Byte is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Byte, null if null map input




getByte
public static Byte getByte(Map map, Object key, Byte defaultValue)(Code)
Looks up the given key in the given map, converting the result into a byte, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversionfails



getByteValue
public static byte getByteValue(Map map, Object key)(Code)
Gets a byte from a Map in a null-safe manner.

The byte is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a byte, 0 if null map input




getByteValue
public static byte getByteValue(Map map, Object key, byte defaultValue)(Code)
Gets a byte from a Map in a null-safe manner, using the default value if the the conversion fails.

The byte is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up
Parameters:
  defaultValue - return if the value is null or if theconversion fails the value in the Map as a byte, defaultValue if null map input




getDouble
public static Double getDouble(Map map, Object key)(Code)
Gets a Double from a Map in a null-safe manner.

The Double is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Double, null if null map input




getDouble
public static Double getDouble(Map map, Object key, Double defaultValue)(Code)
Looks up the given key in the given map, converting the result into a double, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversionfails



getDoubleValue
public static double getDoubleValue(Map map, Object key)(Code)
Gets a double from a Map in a null-safe manner.

The double is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a double, 0.0 if null map input




getDoubleValue
public static double getDoubleValue(Map map, Object key, double defaultValue)(Code)
Gets a double from a Map in a null-safe manner, using the default value if the the conversion fails.

The double is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up
Parameters:
  defaultValue - return if the value is null or if theconversion fails the value in the Map as a double, defaultValue if null map input




getFloat
public static Float getFloat(Map map, Object key)(Code)
Gets a Float from a Map in a null-safe manner.

The Float is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Float, null if null map input




getFloat
public static Float getFloat(Map map, Object key, Float defaultValue)(Code)
Looks up the given key in the given map, converting the result into a float, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversionfails



getFloatValue
public static float getFloatValue(Map map, Object key)(Code)
Gets a float from a Map in a null-safe manner.

The float is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a float, 0.0F if null map input




getFloatValue
public static float getFloatValue(Map map, Object key, float defaultValue)(Code)
Gets a float from a Map in a null-safe manner, using the default value if the the conversion fails.

The float is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up
Parameters:
  defaultValue - return if the value is null or if theconversion fails the value in the Map as a float, defaultValue if null map input




getIntValue
public static int getIntValue(Map map, Object key)(Code)
Gets an int from a Map in a null-safe manner.

The int is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as an int, 0 if null map input




getIntValue
public static int getIntValue(Map map, Object key, int defaultValue)(Code)
Gets an int from a Map in a null-safe manner, using the default value if the the conversion fails.

The int is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up
Parameters:
  defaultValue - return if the value is null or if theconversion fails the value in the Map as an int, defaultValue if null map input




getInteger
public static Integer getInteger(Map map, Object key)(Code)
Gets a Integer from a Map in a null-safe manner.

The Integer is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Integer, null if null map input




getInteger
public static Integer getInteger(Map map, Object key, Integer defaultValue)(Code)
Looks up the given key in the given map, converting the result into an integer, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversionfails



getLong
public static Long getLong(Map map, Object key)(Code)
Gets a Long from a Map in a null-safe manner.

The Long is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Long, null if null map input




getLong
public static Long getLong(Map map, Object key, Long defaultValue)(Code)
Looks up the given key in the given map, converting the result into a long, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversionfails



getLongValue
public static long getLongValue(Map map, Object key)(Code)
Gets a long from a Map in a null-safe manner.

The long is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a long, 0L if null map input




getLongValue
public static long getLongValue(Map map, Object key, long defaultValue)(Code)
Gets a long from a Map in a null-safe manner, using the default value if the the conversion fails.

The long is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up
Parameters:
  defaultValue - return if the value is null or if theconversion fails the value in the Map as a long, defaultValue if null map input




getMap
public static Map getMap(Map map, Object key)(Code)
Gets a Map from a Map in a null-safe manner.

If the value returned from the specified map is not a Map then null is returned.
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Map, null if null map input




getMap
public static Map getMap(Map map, Object key, Map defaultValue)(Code)
Looks up the given key in the given map, converting the result into a map, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a number, or defaultValue if the original value is null, the map is null or the map conversionfails



getNumber
public static Number getNumber(Map map, Object key)(Code)
Gets a Number from a Map in a null-safe manner.

If the value is a Number it is returned directly. If the value is a String it is converted using NumberFormat.parse(String) on the system default formatter returning null if the conversion fails. Otherwise, null is returned.
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Number, null if null map input




getNumber
public static Number getNumber(Map map, Object key, Number defaultValue)(Code)
Looks up the given key in the given map, converting the result into a number, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversionfails



getObject
public static Object getObject(Map map, Object key)(Code)
Gets from a Map in a null-safe manner.
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map, null if null map input



getObject
public static Object getObject(Map map, Object key, Object defaultValue)(Code)
Looks up the given key in the given map, converting null into the given default value.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null the value in the map, or defaultValue if the original valueis null or the map is null



getShort
public static Short getShort(Map map, Object key)(Code)
Gets a Short from a Map in a null-safe manner.

The Short is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a Short, null if null map input




getShort
public static Short getShort(Map map, Object key, Short defaultValue)(Code)
Looks up the given key in the given map, converting the result into a short, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversionfails



getShortValue
public static short getShortValue(Map map, Object key)(Code)
Gets a short from a Map in a null-safe manner.

The short is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a short, 0 if null map input




getShortValue
public static short getShortValue(Map map, Object key, short defaultValue)(Code)
Gets a short from a Map in a null-safe manner, using the default value if the the conversion fails.

The short is obtained from the results of MapUtils.getNumber(Map,Object) .
Parameters:
  map - the map to use
Parameters:
  key - the key to look up
Parameters:
  defaultValue - return if the value is null or if theconversion fails the value in the Map as a short, defaultValue if null map input




getString
public static String getString(Map map, Object key)(Code)
Gets a String from a Map in a null-safe manner.

The String is obtained via toString.
Parameters:
  map - the map to use
Parameters:
  key - the key to look up the value in the Map as a String, null if null map input




getString
public static String getString(Map map, Object key, String defaultValue)(Code)
Looks up the given key in the given map, converting the result into a string, using the default value if the the conversion fails.
Parameters:
  map - the map whose value to look up
Parameters:
  key - the key of the value to look up in that map
Parameters:
  defaultValue - what to return if the value is null or if theconversion fails the value in the map as a string, or defaultValue if the original value is null, the map is null or the string conversionfails



invertMap
public static Map invertMap(Map map)(Code)
Inverts the supplied map returning a new HashMap such that the keys of the input are swapped with the values.

This operation assumes that the inverse mapping is well defined. If the input map had multiple entries with the same value mapped to different keys, the returned map will map one of those keys to the value, but the exact key which will be mapped is undefined.
Parameters:
  map - the map to invert, may not be null a new HashMap containing the inverted data
throws:
  NullPointerException - if the map is null




isEmpty
public static boolean isEmpty(Map map)(Code)
Null-safe check if the specified map is empty.

Null returns true.
Parameters:
  map - the map to check, may be null true if empty or null
since:
   Commons Collections 3.2




isNotEmpty
public static boolean isNotEmpty(Map map)(Code)
Null-safe check if the specified map is not empty.

Null returns false.
Parameters:
  map - the map to check, may be null true if non-null and non-empty
since:
   Commons Collections 3.2




lazyMap
public static Map lazyMap(Map map, Factory factory)(Code)
Returns a "lazy" map whose values will be created on demand.

When the key passed to the returned map's Map.get(Object) method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key.

For instance:

 Factory factory = new Factory() {
 public Object create() {
 return new Date();
 }
 }
 Map lazyMap = MapUtils.lazyMap(new HashMap(), factory);
 Object obj = lazyMap.get("test");
 
After the above code is executed, obj will contain a new Date instance. Furthermore, that Date instance is the value for the "test" key in the map.
Parameters:
  map - the map to make lazy, must not be null
Parameters:
  factory - the factory for creating new objects, must not be null a lazy map backed by the given map
throws:
  IllegalArgumentException - if the Map or Factory is null



lazyMap
public static Map lazyMap(Map map, Transformer transformerFactory)(Code)
Returns a "lazy" map whose values will be created on demand.

When the key passed to the returned map's Map.get(Object) method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key. The factory is a Transformer that will be passed the key which it must transform into the value.

For instance:

 Transformer factory = new Transformer() {
 public Object transform(Object mapKey) {
 return new File(mapKey);
 }
 }
 Map lazyMap = MapUtils.lazyMap(new HashMap(), factory);
 Object obj = lazyMap.get("C:/dev");
 
After the above code is executed, obj will contain a new File instance for the C drive dev directory. Furthermore, that File instance is the value for the "C:/dev" key in the map.

If a lazy map is wrapped by a synchronized map, the result is a simple synchronized cache. When an object is not is the cache, the cache itself calls back to the factory Transformer to populate itself, all within the same synchronized block.
Parameters:
  map - the map to make lazy, must not be null
Parameters:
  transformerFactory - the factory for creating new objects, must not be null a lazy map backed by the given map
throws:
  IllegalArgumentException - if the Map or Transformer is null




lazySortedMap
public static SortedMap lazySortedMap(SortedMap map, Factory factory)(Code)
Returns a "lazy" sorted map whose values will be created on demand.

When the key passed to the returned map's Map.get(Object) method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key.

For instance:

 Factory factory = new Factory() {
 public Object create() {
 return new Date();
 }
 }
 SortedMap lazy = MapUtils.lazySortedMap(new TreeMap(), factory);
 Object obj = lazy.get("test");
 
After the above code is executed, obj will contain a new Date instance. Furthermore, that Date instance is the value for the "test" key.
Parameters:
  map - the map to make lazy, must not be null
Parameters:
  factory - the factory for creating new objects, must not be null a lazy map backed by the given map
throws:
  IllegalArgumentException - if the SortedMap or Factory is null



lazySortedMap
public static SortedMap lazySortedMap(SortedMap map, Transformer transformerFactory)(Code)
Returns a "lazy" sorted map whose values will be created on demand.

When the key passed to the returned map's Map.get(Object) method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key. The factory is a Transformer that will be passed the key which it must transform into the value.

For instance:

 Transformer factory = new Transformer() {
 public Object transform(Object mapKey) {
 return new File(mapKey);
 }
 }
 SortedMap lazy = MapUtils.lazySortedMap(new TreeMap(), factory);
 Object obj = lazy.get("C:/dev");
 
After the above code is executed, obj will contain a new File instance for the C drive dev directory. Furthermore, that File instance is the value for the "C:/dev" key in the map.

If a lazy map is wrapped by a synchronized map, the result is a simple synchronized cache. When an object is not is the cache, the cache itself calls back to the factory Transformer to populate itself, all within the same synchronized block.
Parameters:
  map - the map to make lazy, must not be null
Parameters:
  transformerFactory - the factory for creating new objects, must not be null a lazy map backed by the given map
throws:
  IllegalArgumentException - if the Map or Transformer is null




logInfo
protected static void logInfo(Exception ex)(Code)
Logs the given exception to System.out.

This method exists as Jakarta Collections does not depend on logging.
Parameters:
  ex - the exception to log




multiValueMap
public static Map multiValueMap(Map map)(Code)
Creates a mult-value map backed by the given map which returns collections of type ArrayList.
Parameters:
  map - the map to decorate a multi-value map backed by the given map which returns ArrayLists of values.
See Also:   MultiValueMap
since:
   Commons Collections 3.2



multiValueMap
public static Map multiValueMap(Map map, Class collectionClass)(Code)
Creates a multi-value map backed by the given map which returns collections of the specified type.
Parameters:
  map - the map to decorate
Parameters:
  collectionClass - the type of collections to return from the map (must contain public no-arg constructorand extend Collection). a multi-value map backed by the given map which returns collections of the specified type
See Also:   MultiValueMap
since:
   Commons Collections 3.2



multiValueMap
public static Map multiValueMap(Map map, Factory collectionFactory)(Code)
Creates a multi-value map backed by the given map which returns collections created by the specified collection factory.
Parameters:
  map - the map to decorate
Parameters:
  collectionFactory - a factor which creates collection objects a multi-value map backed by the given map which returns collectionscreated by the specified collection factory
See Also:   MultiValueMap
since:
   Commons Collections 3.2



orderedMap
public static Map orderedMap(Map map)(Code)
Returns a map that maintains the order of keys that are added backed by the given map.

If a key is added twice, the order is determined by the first add. The order is observed through the keySet, values and entrySet.
Parameters:
  map - the map to order, must not be null an ordered map backed by the given map
throws:
  IllegalArgumentException - if the Map is null




predicatedMap
public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred)(Code)
Returns a predicated (validating) map backed by the given map.

Only objects that pass the tests in the given predicates can be added to the map. Trying to add an invalid object results in an IllegalArgumentException. Keys must pass the key predicate, values must pass the value predicate. It is important not to use the original map after invoking this method, as it is a backdoor for adding invalid objects.
Parameters:
  map - the map to predicate, must not be null
Parameters:
  keyPred - the predicate for keys, null means no check
Parameters:
  valuePred - the predicate for values, null means no check a predicated map backed by the given map
throws:
  IllegalArgumentException - if the Map is null




predicatedSortedMap
public static SortedMap predicatedSortedMap(SortedMap map, Predicate keyPred, Predicate valuePred)(Code)
Returns a predicated (validating) sorted map backed by the given map.

Only objects that pass the tests in the given predicates can be added to the map. Trying to add an invalid object results in an IllegalArgumentException. Keys must pass the key predicate, values must pass the value predicate. It is important not to use the original map after invoking this method, as it is a backdoor for adding invalid objects.
Parameters:
  map - the map to predicate, must not be null
Parameters:
  keyPred - the predicate for keys, null means no check
Parameters:
  valuePred - the predicate for values, null means no check a predicated map backed by the given map
throws:
  IllegalArgumentException - if the SortedMap is null




putAll
public static Map putAll(Map map, Object[] array)(Code)
Puts all the keys and values from the specified array into the map.

This method is an alternative to the java.util.Map.putAll(java.util.Map) method and constructors. It allows you to build a map from an object array of various possible styles.

If the first entry in the object array implements java.util.Map.Entry or KeyValue then the key and value are added from that object. If the first entry in the object array is an object array itself, then it is assumed that index 0 in the sub-array is the key and index 1 is the value. Otherwise, the array is treated as keys and values in alternate indices.

For example, to create a color map:

 Map colorMap = MapUtils.putAll(new HashMap(), new String[][] {
 {"RED", "#FF0000"},
 {"GREEN", "#00FF00"},
 {"BLUE", "#0000FF"}
 });
 
or:
 Map colorMap = MapUtils.putAll(new HashMap(), new String[] {
 "RED", "#FF0000",
 "GREEN", "#00FF00",
 "BLUE", "#0000FF"
 });
 
or:
 Map colorMap = MapUtils.putAll(new HashMap(), new Map.Entry[] {
 new DefaultMapEntry("RED", "#FF0000"),
 new DefaultMapEntry("GREEN", "#00FF00"),
 new DefaultMapEntry("BLUE", "#0000FF")
 });
 

Parameters:
  map - the map to populate, must not be null
Parameters:
  array - an array to populate from, null ignored the input map
throws:
  NullPointerException - if map is null
throws:
  IllegalArgumentException - if sub-array or entry matching used and anentry is invalid
throws:
  ClassCastException - if the array contents is mixed
since:
   Commons Collections 3.2



safeAddToMap
public static void safeAddToMap(Map map, Object key, Object value) throws NullPointerException(Code)
Protects against adding null values to a map.

This method checks the value being added to the map, and if it is null it is replaced by an empty string.

This could be useful if the map does not accept null values, or for receiving data from a source that may provide null or empty string which should be held in the same way in the map.

Keys are not validated.
Parameters:
  map - the map to add to, may not be null
Parameters:
  key - the key
Parameters:
  value - the value, null converted to ""
throws:
  NullPointerException - if the map is null




synchronizedMap
public static Map synchronizedMap(Map map)(Code)
Returns a synchronized map backed by the given map.

You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior:

 Map m = MapUtils.synchronizedMap(myMap);
 Set s = m.keySet();  // outside synchronized block
 synchronized (m) {  // synchronized on MAP!
 Iterator i = s.iterator();
 while (i.hasNext()) {
 process (i.next());
 }
 }
 
This method uses the implementation in java.util.Collections Collections .
Parameters:
  map - the map to synchronize, must not be null a synchronized map backed by the given map
throws:
  IllegalArgumentException - if the map is null



synchronizedSortedMap
public static Map synchronizedSortedMap(SortedMap map)(Code)
Returns a synchronized sorted map backed by the given sorted map.

You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior:

 Map m = MapUtils.synchronizedSortedMap(myMap);
 Set s = m.keySet();  // outside synchronized block
 synchronized (m) {  // synchronized on MAP!
 Iterator i = s.iterator();
 while (i.hasNext()) {
 process (i.next());
 }
 }
 
This method uses the implementation in java.util.Collections Collections .
Parameters:
  map - the map to synchronize, must not be null a synchronized map backed by the given map
throws:
  IllegalArgumentException - if the map is null



toMap
public static Map toMap(ResourceBundle resourceBundle)(Code)
Creates a new HashMap using data copied from a ResourceBundle.
Parameters:
  resourceBundle - the resource bundle to convert, may not be null the hashmap containing the data
throws:
  NullPointerException - if the bundle is null



toProperties
public static Properties toProperties(Map map)(Code)
Gets a new Properties object initialised with the values from a Map. A null input will return an empty properties object.
Parameters:
  map - the map to convert to a Properties object, may not be null the properties object



transformedMap
public static Map transformedMap(Map map, Transformer keyTransformer, Transformer valueTransformer)(Code)
Returns a transformed map backed by the given map.

This method returns a new map (decorating the specified map) that will transform any new entries added to it. Existing entries in the specified map will not be transformed. If you want that behaviour, see TransformedMap.decorateTransform .

Each object is passed through the transformers as it is added to the Map. It is important not to use the original map after invoking this method, as it is a backdoor for adding untransformed objects.

If there are any elements already in the map being decorated, they are NOT transformed.
Parameters:
  map - the map to transform, must not be null, typically empty
Parameters:
  keyTransformer - the transformer for the map keys, null means no transformation
Parameters:
  valueTransformer - the transformer for the map values, null means no transformation a transformed map backed by the given map
throws:
  IllegalArgumentException - if the Map is null




transformedSortedMap
public static SortedMap transformedSortedMap(SortedMap map, Transformer keyTransformer, Transformer valueTransformer)(Code)
Returns a transformed sorted map backed by the given map.

This method returns a new sorted map (decorating the specified map) that will transform any new entries added to it. Existing entries in the specified map will not be transformed. If you want that behaviour, see TransformedSortedMap.decorateTransform .

Each object is passed through the transformers as it is added to the Map. It is important not to use the original map after invoking this method, as it is a backdoor for adding untransformed objects.

If there are any elements already in the map being decorated, they are NOT transformed.
Parameters:
  map - the map to transform, must not be null, typically empty
Parameters:
  keyTransformer - the transformer for the map keys, null means no transformation
Parameters:
  valueTransformer - the transformer for the map values, null means no transformation a transformed map backed by the given map
throws:
  IllegalArgumentException - if the SortedMap is null




typedMap
public static Map typedMap(Map map, Class keyType, Class valueType)(Code)
Returns a typed map backed by the given map.

Only keys and values of the specified types can be added to the map.
Parameters:
  map - the map to limit to a specific type, must not be null
Parameters:
  keyType - the type of keys which may be added to the map, must not be null
Parameters:
  valueType - the type of values which may be added to the map, must not be null a typed map backed by the specified map
throws:
  IllegalArgumentException - if the Map or Class is null




typedSortedMap
public static SortedMap typedSortedMap(SortedMap map, Class keyType, Class valueType)(Code)
Returns a typed sorted map backed by the given map.

Only keys and values of the specified types can be added to the map.
Parameters:
  map - the map to limit to a specific type, must not be null
Parameters:
  keyType - the type of keys which may be added to the map, must not be null
Parameters:
  valueType - the type of values which may be added to the map, must not be null a typed map backed by the specified map




unmodifiableMap
public static Map unmodifiableMap(Map map)(Code)
Returns an unmodifiable map backed by the given map.

This method uses the implementation in the decorators subpackage.
Parameters:
  map - the map to make unmodifiable, must not be null an unmodifiable map backed by the given map
throws:
  IllegalArgumentException - if the map is null




unmodifiableSortedMap
public static Map unmodifiableSortedMap(SortedMap map)(Code)
Returns an unmodifiable sorted map backed by the given sorted map.

This method uses the implementation in the decorators subpackage.
Parameters:
  map - the sorted map to make unmodifiable, must not be null an unmodifiable map backed by the given map
throws:
  IllegalArgumentException - if the map is null




verbosePrint
public static void verbosePrint(PrintStream out, Object label, Map map)(Code)
Prints the given map with nice line breaks.

This method prints a nicely formatted String describing the Map. Each map entry will be printed with key and value. When the value is a Map, recursive behaviour occurs.

This method is NOT thread-safe in any special way. You must manually synchronize on either this class or the stream as required.
Parameters:
  out - the stream to print to, must not be null
Parameters:
  label - The label to be used, may be null.If null, the label is not output.It typically represents the name of the property in a bean or similar.
Parameters:
  map - The map to print, may be null.If null, the text 'null' is output.
throws:
  NullPointerException - if the stream is null




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.