Class OneToManyMap<From,To>
- java.lang.Object
-
- org.apache.jena.util.OneToManyMap<From,To>
-
- All Implemented Interfaces:
java.util.Map<From,To>
public class OneToManyMap<From,To> extends java.lang.Object implements java.util.Map<From,To>
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OneToManyMap.Entry<From,To>
Helper class to implement the Map.Entry interface to enumerate entries in the map
-
Constructor Summary
Constructors Constructor Description OneToManyMap()
Construct a new empty one-to-many mapOneToManyMap(OneToManyMap<From,To> map)
Construct a new one-to-many map whose contents are initialised from the existing map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear all entries from the map.boolean
contains(java.lang.Object key, java.lang.Object value)
Answer true if this mapping contains the pair(key, value)
.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<java.util.Map.Entry<From,To>>
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.To
get(java.lang.Object key)
Get a value for this key.java.util.Iterator<To>
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<From>
keySet()
Answer a set of the keys in this mapTo
put(From key, To value)
Associates the given value with the given key.void
putAll(java.util.Map<? extends From,? extends To> m)
Put all entries from one map into this map.To
remove(java.lang.Object key)
Remove all of the associations for the given key.boolean
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 mapjava.lang.String
toString()
Answer a string representation of this map.java.util.Collection<To>
values()
Returns a collection view of the values contained in this map.
-
-
-
Constructor Detail
-
OneToManyMap
public OneToManyMap()
Construct a new empty one-to-many map
-
OneToManyMap
public OneToManyMap(OneToManyMap<From,To> map)
Construct a new one-to-many map whose contents are initialised from the existing map.
- Parameters:
map
- An existing one-to-many map
-
-
Method Detail
-
clear
public void clear()
Clear all entries from the map.
-
containsKey
public boolean containsKey(java.lang.Object key)
Answer true if the map contains the given value as a key.
-
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.
-
contains
public boolean contains(java.lang.Object key, java.lang.Object value)
Answer true if this mapping contains the pair
(key, value)
.- Parameters:
key
- A key objectvalue
- A value object- Returns:
- True if
key
hasvalue
as one of its values in this mapping
-
entrySet
public java.util.Set<java.util.Map.Entry<From,To>> entrySet()
Answer a set of the mappings in this map. Each member of the set will be a Map.Entry value.
-
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.
-
get
public To 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 interfacejava.util.Map<From,To>
- 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<To> 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.
-
keySet
public java.util.Set<From> keySet()
Answer a set of the keys in this map
-
put
public To put(From key, To 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).
-
putAll
public void putAll(java.util.Map<? extends From,? extends To> m)
Put all entries from one map into this map. Tests for m being a OneToManyMap, and, if so, copies all of the entries for each key.
-
remove
public To remove(java.lang.Object key)
Remove all of the associations for the given key. If only a specific association is to be removed, useremove( 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.
-
remove
public boolean 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. If all values for a particular key have been removed post removing this particular association, the key will no longer appear as a key in the map.
-
size
public int size()
Answer the number of key-value mappings in the map
-
values
public java.util.Collection<To> values()
Returns a collection view of the values contained in this map. Specifically, this will be a set, so duplicate values that appear for multiple keys are suppressed.
-
toString
public java.lang.String toString()
Answer a string representation of this map. This can be quite a long string for large maps.
- Overrides:
toString
in classjava.lang.Object
-
-