|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.quadrique.jbuildingblocks.core.dataStructure.JbbHashMapWithMultipleValuesPerKey<K,V>
K - the datatype for the KeysV - the datatype for the Valuespublic class JbbHashMapWithMultipleValuesPerKey<K,V>
This data structure is similar to a HashMap except that the data associated to any given key is a list of values (an ArrrayList instance).
The actual differences are:
This class can be seen as a generalisation of the Histogram class in the sense that a set of related values can be grouped together based on a given key.
For instance:
HashMapWithMultipleValuesPerKey<Integer,String> map = new HashMapWithMultipleValuesPerKey<Integer,String>();
map.add(1,"1_red");
map.add(2,"2_yellow");
map.add(3,"3_red");
map.add(2,"2_green");
map.add(3,"3_yellow");
map.add(2,"2_purple");
map.add(2,"2_blue");
System.out.println("\nThe number of keys is: " + map.getNbOfKeys());
System.out.println("\nThe keys are: ");
for(int key : map.keySet())
{
System.out.println("- \"" + key + "\"");
}
for(int key : map.keySet())
{
System.out.println("\nThe value(s) for the key \"" + key + "\" are:");
for(String value : map.get(key))
{
System.out.println("- \"" + value + "\"");
}
}
The corresponding execution results are:
The number of keys is: 3
The keys are:
- "2"
- "1"
- "3"
The value(s) for the key "2" are:
- "2_yellow"
- "2_green"
- "2_purple"
- "2_blue"
The value(s) for the key "1" are:
- "1_red"
The value(s) for the key "3" are:
- "3_red"
- "3_yellow"
| Constructor Summary | |
|---|---|
JbbHashMapWithMultipleValuesPerKey()
|
|
| Method Summary | |
|---|---|
void |
add(K key,
V value)
|
ArrayList<V> |
get(K key)
|
int |
getNbOfKeys()
|
Set<K> |
keySet()
|
ArrayList<V> |
remove(K key)
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JbbHashMapWithMultipleValuesPerKey()
| Method Detail |
|---|
public void add(K key,
V value)
key - value - public int getNbOfKeys()
public Set<K> keySet()
public ArrayList<V> get(K key)
key -
public ArrayList<V> remove(K key)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||