uk.ac.ed.inf.utils.maputils
Class MapUtils

java.lang.Object
  extended by uk.ac.ed.inf.utils.maputils.MapUtils

public class MapUtils
extends java.lang.Object

Utilities to manipulate maps and hashmaps

Version:
4 Jan 2008
Author:
Luna De Ferrari luna.deferrari-at-ed.ac.uk

Constructor Summary
MapUtils()
           
 
Method Summary
static java.util.Map.Entry extractMapEntry(java.util.Map map, int i)
          Extracts a random entry (key-value association) from a map
static java.util.TreeMap<java.lang.String,java.lang.String> fromTwoVectorsToMap(java.util.Vector<java.lang.String> keys, java.util.Vector<java.lang.String> values)
          Creates an hashmap from 2 vectors.
static double getDoubleFromHashmap(java.util.HashMap hashMap, java.lang.String hashMapKey)
          Gets a double from a hashMap
static java.util.ArrayList<java.lang.String> getFirstValueOccurrence(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String value)
          Get all the keys that have the given value in a Map\
static java.util.Map<java.lang.Integer,java.util.Map.Entry> getIndexedMap(java.lang.Object[] mapEntries)
          Get a map with entries composed of: an integer id as key and an entry as value
static java.lang.String mapToString(java.util.Map map)
          Creates a string representation of a map, as index,tab,key,tab,value
static void printMap(java.util.Map map)
          Prints an HashMap as a list of index + key + value
static boolean treeMapsHaveEqualValues(java.util.TreeMap<java.lang.Integer,java.lang.Character> map1, java.util.TreeMap<java.lang.Integer,java.lang.Character> map2)
          Check if two treeMaps have the same collection of values
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapUtils

public MapUtils()
Method Detail

extractMapEntry

public static java.util.Map.Entry extractMapEntry(java.util.Map map,
                                                  int i)
Extracts a random entry (key-value association) from a map

Parameters:
map - a map
Returns:
a random (truncated Pareto distributed) entry from the map

fromTwoVectorsToMap

public static java.util.TreeMap<java.lang.String,java.lang.String> fromTwoVectorsToMap(java.util.Vector<java.lang.String> keys,
                                                                                       java.util.Vector<java.lang.String> values)
Creates an hashmap from 2 vectors. The first vector must contain a the keys, the second vector the values. The keys and values vectors must have the same size.

Parameters:
keys -
values -
Returns:
an HashMap

getDoubleFromHashmap

public static double getDoubleFromHashmap(java.util.HashMap hashMap,
                                          java.lang.String hashMapKey)
Gets a double from a hashMap


getFirstValueOccurrence

public static java.util.ArrayList<java.lang.String> getFirstValueOccurrence(java.util.Map<java.lang.String,java.lang.String> map,
                                                                            java.lang.String value)
Get all the keys that have the given value in a Map\

Parameters:
map - a map
value - a hash map value
Returns:
the keys

getIndexedMap

public static java.util.Map<java.lang.Integer,java.util.Map.Entry> getIndexedMap(java.lang.Object[] mapEntries)
Get a map with entries composed of: an integer id as key and an entry as value

Parameters:
mapEntries - an array of Entry objects
Returns:
a map with entries composed of: an integer id as key and an entry as value

mapToString

public static java.lang.String mapToString(java.util.Map map)
Creates a string representation of a map, as index,tab,key,tab,value

Returns:
a string representation of the map

printMap

public static void printMap(java.util.Map map)
Prints an HashMap as a list of index + key + value

Parameters:
map -

treeMapsHaveEqualValues

public static boolean treeMapsHaveEqualValues(java.util.TreeMap<java.lang.Integer,java.lang.Character> map1,
                                              java.util.TreeMap<java.lang.Integer,java.lang.Character> map2)
Check if two treeMaps have the same collection of values

Parameters:
map1 -
map2 -
Returns:
true, if the two treeMaps have the same collection of values