|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.neoworks.util.AbstractMultiMap
This class provides a skeletal implementation of the MultiMap interface, to minimize the effort required to
implement this interface.
To implement an unmodifiable multimap, the programmer needs only to extend this class and provide an implementation for the
entrySet method, which returns a set-view of the multimap's mappings. Typically, the returned set will, in turn,
be implemented atop AbstractSet. This set should not support the add or remove methods,
and its iterator should not support the remove method.
To implement a modifiable multimap, the programmer must additionally override this class's put method (which
otherwise throws an UnsupportedOperationException), and the iterator returned by
entrySet().iterator() must additionally implement its remove method.
The programmer should generally provide a void (no argument) and multimap constructor, as per the recommendation in the
MultiMap interface specification.
The documentation for each non-abstract methods in this class describes its implementation in detail. Each of these methods may be overridden if the multimap being implemented admits a more efficient implementation.
| Nested Class Summary |
| Nested classes inherited from class com.neoworks.util.MultiMap |
MultiMap.Entry |
| Constructor Summary | |
protected |
AbstractMultiMap()
Sole constructor. |
| Method Summary | |
void |
clear()
Removes all mappings from this multimap (optional operation). |
boolean |
containsKey(java.lang.Object key)
Returns true if this multimap contains a mapping for the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this multimap maps one or more keys to this value. |
abstract java.util.Set |
entrySet()
Returns a set view of the mappings contained in this multimap. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this multimap for equality. |
java.util.Set |
get(java.lang.Object key)
Returns the set of values to which this multimap maps the specified key. |
int |
hashCode()
Returns the hash code value for this multimap. |
boolean |
isEmpty()
Returns true if this multimap contains no key-value mappings. |
java.util.Collection |
keys()
Returns a collection view of the keys contained in this multimap. |
java.util.Set |
put(java.lang.Object key,
java.lang.Object value)
Associates the specified value with the specified key in this map (optional operation). |
void |
putAll(MultiMap map)
Copies all of the mappings from the specified multimap to this multimap (optional operation). |
java.util.Set |
remove(java.lang.Object key)
Removes all the mappings for this key from this multimap if present (optional operation). |
java.lang.Object |
remove(java.lang.Object key,
java.lang.Object value)
Removes the specified mapping from this multimap if present (optional operation). |
int |
size()
Returns the number of key-value mappings in this multimap. |
java.lang.String |
toString()
Returns a string representation of this multimap. |
java.util.Collection |
uniqueKeys()
Return a Collection of unique keys from the Multimap |
java.util.Collection |
values()
Returns a collection view of the values contained in this multimap. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
protected AbstractMultiMap()
| Method Detail |
public int size()
Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
This implementation returns entrySet().size().
size in interface MultiMappublic boolean isEmpty()
true if this multimap contains no key-value mappings.
This implementation returns size() == 0.
isEmpty in interface MultiMaptrue if this multimap contains no key-value mappings.public boolean containsValue(java.lang.Object value)
true if this multimap maps one or more keys to this value. More formally, returns
true if and only if this multimap contains at least one mapping to a value v such that:
(value == null ? v == null : value.equals(v)).
This operation will probably require time linear in the multimap size for most implementations of multimap.
This implementation iterates over entrySet() searching for an entry with the specified value. If such
an entry is found, true is returned. If the iteration terminates without finding such an entry,
false is returned. Note that this implementation requires linear time in the size of the multimap.
containsValue in interface MultiMapvalue - value whose presence in this multimap is to be tested.
true if this multimap maps one or more keys to this value.public boolean containsKey(java.lang.Object key)
true if this multimap contains a mapping for the specified key.
This implementation iterates over entrySet() searching for an entry with the specified key. If such an
entry is found, true is returned. If the iteration terminates without finding such an entry,
false is returned. Note that this implementation requires linear time in the size of the multimap;
many implementations will override this method.
containsKey in interface MultiMapkey - Key whose presence in this multimap is to be tested.
true if this multimap contains a mapping for the specified key.public java.util.Set get(java.lang.Object key)
null if the multimap
contains no mapping for this key. A return value of null does indicate that the multimap contains no
mapping for the key; it's possible that the map explicitly maps the key to null, in this case the
returned set will contain null possibly along with other objects. The containsKey operation may also be
used to distinguish these two cases.
This implementation iterates over entrySet() searching for an entry with the specified key. If such an
entry is found, the entry's values are placed in a Set and returned. If the iteration terminates without
finding such an entry, null is returned. This implementation allows null keys. Note that this
implementation requires linear time in the size of the multimap; many implementations will override this method.
get in interface MultiMapkey - Key whose associated value is to be returned.
Set of values to which this multimap maps the specified key.containsKey(Object)
public java.util.Set put(java.lang.Object key,
java.lang.Object value)
This implementation always throws an UnsupportedOperationException.
put in interface MultiMapkey - Key with which the specified value is to be associated.value - Value to be associated with the specified key.
Set of values associated with the specified key.public java.util.Set remove(java.lang.Object key)
This implementation iterates over entrySet() searching for entries with the specified key. If such an
entry is found, its value is obtained with its getValue operation, the entry is removed from the
collection (and the backing map) with the iterator's remove operation, and the saved value is added to a
Set object which is returned at the end of this method. If the iteration terminates without finding such an
entry, null is returned. Note that this implementation requires linear time in the size of the map; many
implementations will override this method.
remove in interface MultiMapkey - Key whose mappings is to be removed from the multimap.
Set of values associated with the specified key, or null if there were no mappings
for key.
public java.lang.Object remove(java.lang.Object key,
java.lang.Object value)
This implementation iterates over entrySet() searching for entries with the specified key and value. If
such an entry is found, its value is obtained with its getValue operation, the entry is removed from the
collection (and the backing map) with the iterator's remove operation, it is returned at the end of this
method. If the iteration terminates without finding such an entry, null is returned. Note that this
implementation requires linear time in the size of the map; many implementations will override this method.
remove in interface MultiMapkey - Key whose mapping is to be removed from the multimap.value - Value that is being mapped to by the given key.
null if there were no mappings for key.public void putAll(MultiMap map)
This implementation iterates over the specified multi's entrySet() collection, and calls this
multimap's put operation once for each entry returned by the iteration.
putAll in interface MultiMapmap - Mappings to be stored in this multimap.public void clear()
This implementation calls entrySet().clear().
clear in interface MultiMappublic java.util.Collection keys()
Iterator.remove, Collection.remove,
removeAll, retainAll, and clear operations. It does not support the
add or addAll operations.
This implementation returns a Collection that subclasses AbstractCollection. The subclass's
iterator method returns a "wrapper object" over this multimap's entrySet() iterator. The size method
delegates to this multimap's size method and the contains method delegates to this multimap's containsKey
method.
The collection is created the first time this method is called, and returned in response to all subsequent calls. No synchronization is performed, so there is a slight chance that multiple calls to this method will not all return the same collection.
keys in interface MultiMappublic java.util.Collection uniqueKeys()
uniqueKeys in interface MultiMappublic java.util.Collection values()
Iterator.remove,
Collection.remove, removeAll, retainAll and clear operations.
It does not support the add or addAll operations.
This implementation returns a Collection that subclasses AbstractCollection. The subclass's
iterator method returns a "wrapper object" over this multimap's entrySet() iterator. The size method
delegates to this multimap's size method and the contains method delegates to this multimap's containsValue method.
The collection is created the first time this method is called, and returned in response to all subsequent calls. No synchronization is performed, so there is a slight chance that multiple calls to this method will not all return the same collection.
values in interface MultiMappublic abstract java.util.Set entrySet()
Iterator.remove,
Set.remove, removeAll, retainAll and clear operations. It does not
support the add or addAll operations.
entrySet in interface MultiMappublic boolean equals(java.lang.Object o)
true if the given object is also
a multimap and the two multimaps represent the same mappings. More formally, two maps t1 and
t2 represent the same mappings iff:
t1.keySet().equals(t2.keySet())
and for every key k in t1.keySet(),
(t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k))). This ensures that the
equals method works properly across different implementations of the multimap interface.
This implementation first checks if the specified object is this map; if so it returns true. Then, it
checks if the specified object is a multimap whose size is identical to the size of this set; if not, it it returns
false. If so, it iterates over this multimap's entrySet collection, and checks that the
specified map contains each mapping that this multimap contains. If the specified map fails to contain such a mapping,
false is returned. If the iteration completes, true is returned.
equals in interface MultiMapequals in class java.lang.Objecto - Object to be compared for equality with this multimap.
true if the specified object is equal to this multimap.public int hashCode()
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.
This implementation iterates over entrySet(), calling hashCode on each element (entry) in
the Collection, and adding up the results.
hashCode in interface MultiMaphashCode in class java.lang.ObjectMultiMap.Entry.hashCode()public java.lang.String toString()
entrySet view's iterator, enclosed in braces ("{}").
Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is
rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are
converted to strings as by String.valueOf(Object).
This implementation creates an empty string buffer, appends a left brace, and iterates over the multimap's
entrySet view, appending the string representation of each MultiMap.Entry in turn. After
appending each entry except the last, the string ", " is appended. Finally a right brace is appended. A
String is obtained from the StringBuffer, and returned.
toString in class java.lang.ObjectString representation of this multimap.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||