uk.ac.ed.inf.utils
Class OneToManyMap

java.lang.Object
  extended by uk.ac.ed.inf.utils.OneToManyMap

public class OneToManyMap
extends java.lang.Object

A map containing for each key a set of values. No key can be null. At most one key can be an empty-string. No value can be null (the Java TreeSet class used uses "null" as a return message when there is *no* mapping for a given key!). A value can be an empty string.

Version:
3 Jun 2008
Author:
Luna De Ferrari luna.deferrari-at-ed.ac.uk

Constructor Summary
OneToManyMap()
          Initialise an empty map
OneToManyMap(java.util.Vector<java.lang.String> keys, java.util.Vector<java.lang.String> values)
          Initialise with a list of key-value pairs
 
Method Summary
 void addAll(OneToManyMap mapToAdd)
          Add all elements of a one2many map to another map
 boolean addKeyAndValue(java.lang.String key, java.lang.String value)
          Add a key-value pair to the map
 boolean containsKey(java.lang.String key)
          Checks if the map contains a key
 boolean containsKeyValue(java.lang.String key, java.lang.String value)
          Checks if the map contains a specific key-value pair
 boolean containsValue(java.lang.String value)
          Checks if the map contains a value
 boolean deleteKeyValue(java.lang.String key, java.lang.String value)
           
 java.util.Set<java.lang.String> getKeys()
           
 java.util.Vector<java.util.Vector<java.lang.String>> getKeysVectorValuesVector()
          Get 1.
 java.util.Set<java.lang.String> getKeyValues(java.lang.String key)
          Get the set of unique values for this key.
 int getKeyValuesPairsSize()
          Get the number of unique key-value pairs in the map.
 java.util.TreeMap<java.lang.String,java.util.Set<java.lang.String>> getMap()
           
 java.util.Set<java.lang.String> getNonEmptyKeys()
          Get the set of unique, non-empty-string keys for this map.
 int getNonEmptyKeyValuesPairsSize()
          Get the number of unique, non-empty key-value pairs in the map.
 java.util.Set<java.lang.String> getNonEmptyValues()
          Get the set of unique, non-empty-string values for this map.
 java.util.Set<java.lang.String> getValues()
          Get the set of unique values for this map.
 boolean mapIsNullOrEmpty()
           
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OneToManyMap

public OneToManyMap()
Initialise an empty map


OneToManyMap

public OneToManyMap(java.util.Vector<java.lang.String> keys,
                    java.util.Vector<java.lang.String> values)
Initialise with a list of key-value pairs

Parameters:
keys - the list of keys
values - the list of values (the value for each key in the keys list)
Method Detail

addAll

public void addAll(OneToManyMap mapToAdd)
Add all elements of a one2many map to another map

Parameters:
map - the map whose elements have to be added

addKeyAndValue

public boolean addKeyAndValue(java.lang.String key,
                              java.lang.String value)
Add a key-value pair to the map

Parameters:
key - a key
value - a value
Returns:
true if the value was added, false if the key-value pair already existed

containsKey

public boolean containsKey(java.lang.String key)
Checks if the map contains a key

Parameters:
key -
Returns:
true if the key exists in the map, false otherwise

containsKeyValue

public boolean containsKeyValue(java.lang.String key,
                                java.lang.String value)
Checks if the map contains a specific key-value pair

Parameters:
key -
value -
Returns:
true if the key-value exists, false otherwise (false if the key or value are null)

containsValue

public boolean containsValue(java.lang.String value)
Checks if the map contains a value

Parameters:
value - a value
Returns:
true if the value exists in the map, false otherwise

deleteKeyValue

public boolean deleteKeyValue(java.lang.String key,
                              java.lang.String value)

getKeys

public java.util.Set<java.lang.String> getKeys()

getKeysVectorValuesVector

public java.util.Vector<java.util.Vector<java.lang.String>> getKeysVectorValuesVector()
Get 1. a first vector containing each key as many times as values exist for the key. 2. a second vector containing one corresponding value for each key entry in the first vector. The two vectors together create a 2 vectors representation of the map (key in vector 1, value in vector 2). Example, for a map: [1:{a, b}, 2:{b, c}] the keys vector will contain: [1, 1, 2, 2]. While the values vector will contain: [a, b, b, c]. Read together, element by element, they give the map couples.

Returns:
a vector of vectors, with the first vector being the keys vector and the second being the values vector.

getKeyValues

public java.util.Set<java.lang.String> getKeyValues(java.lang.String key)
Get the set of unique values for this key. No values can be null. At most one of the values can be an empty string.

Returns:
the set of unique values for this key

getKeyValuesPairsSize

public int getKeyValuesPairsSize()
Get the number of unique key-value pairs in the map. No key can be null. At most one of the keys can be an empty string. The values can be empty strings.

Returns:
the number of unique key-value pairs in the map

getNonEmptyKeyValuesPairsSize

public int getNonEmptyKeyValuesPairsSize()
Get the number of unique, non-empty key-value pairs in the map. No key can be null. Empty string keys will not be included, nor will empty string values.

Returns:
the number of unique key-value pairs in the map

getMap

public java.util.TreeMap<java.lang.String,java.util.Set<java.lang.String>> getMap()

getValues

public java.util.Set<java.lang.String> getValues()
Get the set of unique values for this map. At most one value can be null. At most one value can be an empty string.

Returns:
the set of unique values for this map

getNonEmptyValues

public java.util.Set<java.lang.String> getNonEmptyValues()
Get the set of unique, non-empty-string values for this map.

Returns:
the set of unique, non-empty-string values for this map

getNonEmptyKeys

public java.util.Set<java.lang.String> getNonEmptyKeys()
Get the set of unique, non-empty-string keys for this map.

Returns:
the set of unique, non-empty-string keys for this map

mapIsNullOrEmpty

public boolean mapIsNullOrEmpty()

size

public int size()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object