com.hp.hpl.jena.util
Class OneToManyMap

java.lang.Object
  |
  +--com.hp.hpl.jena.util.OneToManyMap
All Implemented Interfaces:
java.util.Map

public class OneToManyMap
extends java.lang.Object
implements java.util.Map

An extension to a standard map that supports one-to-many mappings: that is, there may be zero, one or many values corresponding to a given key.

Version:
CVS info: $Id: OneToManyMap.java,v 1.1 2001/09/24 17:02:36 ijd Exp $
Author:
Ian Dickinson, HP Labs (email)

Inner Class Summary
 class OneToManyMap.Entry
          Helper class to implement the Map.Entry interface to enumerate entries in the map
 
Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
OneToManyMap()
           
 
Method Summary
 void clear()
          Clear all entries from the map.
 boolean containsKey(java.lang.Object key)
          Answer true if the map contains the given value as a key.
 boolean containsValue(java.lang.Object value)
          Answer true if the map contains the given object as a value stored against any key.
 java.util.Set entrySet()
          Answer a set of the mappings in this map.
 boolean equals(java.lang.Object o)
          Compares the specified object with this map for equality.
 java.lang.Object get(java.lang.Object key)
          Get a value for this key.
 java.util.Iterator getAll(java.lang.Object key)
          Answer an iterator over all of the values for the given key.
 int hashcode()
          Returns the hash code value for this map.
 boolean isEmpty()
          Answer true if the map is empty of key-value mappings.
 java.util.Set keySet()
          Answer a set of the keys in this map
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the given value with the given key.
 void putAll(java.util.Map m)
          Put all entries from one map into this.
 java.lang.Object remove(java.lang.Object key)
          Remove all of the associations for the given key.
 void remove(java.lang.Object key, java.lang.Object value)
          Remove the specific association between the given key and value.
 int size()
          Answer the number of key-value mappings in the map
 java.util.Collection values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode
 

Constructor Detail

OneToManyMap

public OneToManyMap()
Method Detail

clear

public void clear()
Clear all entries from the map.
Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Answer true if the map contains the given value as a key.
Specified by:
containsKey in interface java.util.Map
Parameters:
key - The key object to test for
Returns:
True or false

containsValue

public boolean containsValue(java.lang.Object value)
Answer true if the map contains the given object as a value stored against any key. Note that this is quite an expensive operation in the current implementation.
Specified by:
containsValue in interface java.util.Map
Parameters:
value - The value to test for
Returns:
True if the value is in the map

entrySet

public java.util.Set entrySet()
Answer a set of the mappings in this map. Each member of the set will be a Map.Entry value.
Specified by:
entrySet in interface java.util.Map
Returns:
A Set of the mappings as Map.Entry values.

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a map and the two Maps represent the same mappings. More formally, two maps t1 and t2 represent the same mappings if t1.entrySet().equals(t2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.
Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.lang.Object
Parameters:
o - The object to be compared for equality with this map.
Returns:
True if the specified object is equal to this map.

get

public java.lang.Object get(java.lang.Object key)
Get a value for this key. Since this map is explicitly designed to allow there to be more than one mapping per key, this method will return an undetermined instance of the mapping. If no mapping exists, or the selected value is null, null is returned.
Specified by:
get in interface java.util.Map
Parameters:
key - The key to access the map.
Returns:
One of the values this key corresponds to, or null.
See Also:
getAll(java.lang.Object)

getAll

public java.util.Iterator getAll(java.lang.Object key)
Answer an iterator over all of the values for the given key. An iterator is always supplied, even if the key is not present.
Parameters:
key - The key object
Returns:
An iterator over all of the values for this key in the map

hashcode

public int hashcode()
Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hashCodes of each entry in the map's entrySet view. This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode() for any two maps t1 and t2, as required by the general contract of Object.hashCode

isEmpty

public boolean isEmpty()
Answer true if the map is empty of key-value mappings.
Specified by:
isEmpty in interface java.util.Map
Returns:
True if there are no entries.

keySet

public java.util.Set keySet()
Answer a set of the keys in this map
Specified by:
keySet in interface java.util.Map
Returns:
The keys of the map as a Set

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the given value with the given key. Since this map formulation allows many values for one key, previous associations with the key are not lost. Consequently, the method always returns null (since the replaced value is not defined).
Specified by:
put in interface java.util.Map
Parameters:
key - The key object
value - The value object
Returns:
Null.

putAll

public void putAll(java.util.Map m)
            throws java.lang.UnsupportedOperationException
Put all entries from one map into this. Not implemented.
Specified by:
putAll in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Remove all of the associations for the given key. If only a specific association is to be removed, use remove( java.lang.Object, java.lang.Object ) instead. Has no effect if the key is not present in the map. Since no single specific association with the key is defined, this method always returns null.
Specified by:
remove in interface java.util.Map
Parameters:
key - All associations with this key will be removed.

remove

public void remove(java.lang.Object key,
                   java.lang.Object value)
Remove the specific association between the given key and value. Has no effect if the association is not present in the map.
Parameters:
key - The key object
value - The value object

size

public int size()
Answer the number of key-value mappings in the map
Specified by:
size in interface java.util.Map
Returns:
The number of key-value pairs.

values

public java.util.Collection values()
Returns a collection view of the values contained in this map.
Specified by:
values in interface java.util.Map
Returns:
A collection view of the values contained in this map.


Copyright © 2001 Hewlett-Packard. All Rights Reserved.