Neo4j Community

org.neo4j.helpers.collection
Class MapUtil

java.lang.Object
  extended by org.neo4j.helpers.collection.MapUtil

public abstract class MapUtil
extends Object

Utility to create Maps.


Constructor Summary
MapUtil()
           
 
Method Summary
static
<K,V> Map<K,V>
genericMap(Map<K,V> targetMap, Object... objects)
          A short-hand method for adding key/value pairs into a Map.
static
<K,V> Map<K,V>
genericMap(Object... objects)
          A short-hand method for creating a Map of key/value pairs.
static Map<String,String> load(File file)
          Loads a Map from a File assuming strings as keys and values.
static Map<String,String> load(InputStream stream)
          Loads a Map from an InputStream assuming strings as keys and values.
static Map<String,String> load(Reader reader)
          Loads a Map from a Reader assuming strings as keys and values.
static Map<String,String> loadStrictly(File file)
          Loads a Map from a File assuming strings as keys and values.
static Map<String,String> loadStrictly(InputStream stream)
          Loads a Map from an InputStream assuming strings as keys and values.
static Map<String,String> loadStrictly(Reader reader)
          Loads a Map from a Reader assuming strings as keys and values.
static Map<String,Object> map(Map<String,Object> targetMap, Object... objects)
          A short-hand method for creating a Map of key/value pairs where keys are Strings and values are Objects.
static Map<String,Object> map(Object... objects)
          A short-hand method for creating a Map of key/value pairs where keys are Strings and values are Objects.
static
<K,V> Map<V,K>
reverse(Map<K,V> map)
          Reversed a map, making the key value and the value key.
static void store(Map<String,String> config, File file)
          Stores the data in config into file in a standard java Properties format.
static void store(Map<String,String> config, OutputStream stream)
          Stores the data in config into stream in a standard java Properties format.
static void store(Map<String,String> config, Writer writer)
          Stores the data in config into writer in a standard java Properties format.
static void storeStrictly(Map<String,String> config, File file)
          Stores the data in config into file in a standard java Properties format.
static void storeStrictly(Map<String,String> config, OutputStream stream)
          Stores the data in config into stream in a standard java Properties format.
static void storeStrictly(Map<String,String> config, Writer writer)
          Stores the data in config into writer in a standard java Properties format.
static Map<String,String> stringMap(Map<String,String> targetMap, String... strings)
          A short-hand method for creating a Map of key/value pairs where both keys and values are Strings.
static Map<String,String> stringMap(String... strings)
          A short-hand method for creating a Map of key/value pairs where both keys and values are Strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapUtil

public MapUtil()
Method Detail

genericMap

public static <K,V> Map<K,V> genericMap(Object... objects)
A short-hand method for creating a Map of key/value pairs.

Type Parameters:
K - type of keys
V - type of values
Parameters:
objects - alternating key and value.
Returns:
a Map with the entries supplied by objects.

genericMap

public static <K,V> Map<K,V> genericMap(Map<K,V> targetMap,
                                        Object... objects)
A short-hand method for adding key/value pairs into a Map.

Type Parameters:
K - type of keys
V - type of values
Parameters:
targetMap - the Map to put the objects into.
objects - alternating key and value.
Returns:
a Map with the entries supplied by objects.

stringMap

public static Map<String,String> stringMap(String... strings)
A short-hand method for creating a Map of key/value pairs where both keys and values are Strings.

Parameters:
strings - alternating key and value.
Returns:
a Map with the entries supplied by strings.

stringMap

public static Map<String,String> stringMap(Map<String,String> targetMap,
                                           String... strings)
A short-hand method for creating a Map of key/value pairs where both keys and values are Strings.

Parameters:
targetMap - the Map to put the objects into.
strings - alternating key and value.
Returns:
a Map with the entries supplied by strings.

map

public static Map<String,Object> map(Object... objects)
A short-hand method for creating a Map of key/value pairs where keys are Strings and values are Objects.

Parameters:
objects - alternating key and value.
Returns:
a Map with the entries supplied by objects.

map

public static Map<String,Object> map(Map<String,Object> targetMap,
                                     Object... objects)
A short-hand method for creating a Map of key/value pairs where keys are Strings and values are Objects.

Parameters:
targetMap - the Map to put the objects into.
objects - alternating key and value.
Returns:
a Map with the entries supplied by objects.

load

public static Map<String,String> load(Reader reader)
                               throws IOException
Loads a Map from a Reader assuming strings as keys and values.

Parameters:
reader - the Reader containing a Properties-like layout of keys and values.
Returns:
the read data as a Map.
Throws:
IOException - if the reader throws IOException.

loadStrictly

public static Map<String,String> loadStrictly(Reader reader)
Loads a Map from a Reader assuming strings as keys and values. Any IOException is wrapped and thrown as a RuntimeException instead.

Parameters:
reader - the Reader containing a Properties-like layout of keys and values.
Returns:
the read data as a Map.

load

public static Map<String,String> load(InputStream stream)
                               throws IOException
Loads a Map from an InputStream assuming strings as keys and values.

Parameters:
stream - the InputStream containing a Properties-like layout of keys and values.
Returns:
the read data as a Map.
Throws:
IOException - if the stream throws IOException.

loadStrictly

public static Map<String,String> loadStrictly(InputStream stream)
Loads a Map from an InputStream assuming strings as keys and values. Any IOException is wrapped and thrown as a RuntimeException instead.

Parameters:
stream - the InputStream containing a Properties-like layout of keys and values.
Returns:
the read data as a Map.

load

public static Map<String,String> load(File file)
                               throws IOException
Loads a Map from a File assuming strings as keys and values.

Parameters:
file - the File containing a Properties-like layout of keys and values.
Returns:
the read data as a Map.
Throws:
IOException - if the file reader throws IOException.

loadStrictly

public static Map<String,String> loadStrictly(File file)
Loads a Map from a File assuming strings as keys and values. Any IOException is wrapped and thrown as a RuntimeException instead.

Parameters:
file - the File containing a Properties-like layout of keys and values.
Returns:
the read data as a Map.

store

public static void store(Map<String,String> config,
                         File file)
                  throws IOException
Stores the data in config into file in a standard java Properties format.

Parameters:
config - the data to store in the properties file.
file - the file to store the properties in.
Throws:
IOException - IO error.

storeStrictly

public static void storeStrictly(Map<String,String> config,
                                 File file)
Stores the data in config into file in a standard java Properties format. Any IOException is wrapped and thrown as a RuntimeException instead.

Parameters:
config - the data to store in the properties file.
file - the file to store the properties in.

store

public static void store(Map<String,String> config,
                         OutputStream stream)
                  throws IOException
Stores the data in config into stream in a standard java Properties format.

Parameters:
config - the data to store in the properties file.
stream - the OutputStream to store the properties in.
Throws:
IOException - IO error.

storeStrictly

public static void storeStrictly(Map<String,String> config,
                                 OutputStream stream)
Stores the data in config into stream in a standard java Properties format. Any IOException is wrapped and thrown as a RuntimeException instead.

Parameters:
config - the data to store in the properties file.
stream - the OutputStream to store the properties in.
Throws:
IOException - IO error.

store

public static void store(Map<String,String> config,
                         Writer writer)
                  throws IOException
Stores the data in config into writer in a standard java Properties format.

Parameters:
config - the data to store in the properties file.
stream - the Writer to store the properties in.
Throws:
IOException - IO error.

storeStrictly

public static void storeStrictly(Map<String,String> config,
                                 Writer writer)
Stores the data in config into writer in a standard java Properties format. Any IOException is wrapped and thrown as a RuntimeException instead.

Parameters:
config - the data to store in the properties file.
stream - the Writer to store the properties in.
Throws:
IOException - IO error.

reverse

public static <K,V> Map<V,K> reverse(Map<K,V> map)
Reversed a map, making the key value and the value key.

Type Parameters:
K - the type of key in the map to reverse. These will be the values in the returned map.
V - the type of values in the map to revert. These will be the keys in the returned map.
Parameters:
map - the Map to reverse.
Returns:
the reverse of map. A new Map will be returned where the keys from map will be the values and the values will be the keys.

Neo4j Community

Copyright © 2011 The Neo4j Graph Database Project. All Rights Reserved.