public abstract class AbstractMultimap<K,V,C extends com.gs.collections.api.RichIterable<V>>
extends java.lang.Object
implements com.gs.collections.api.multimap.Multimap<K,V>
| Constructor and Description |
|---|
AbstractMultimap() |
| Modifier and Type | Method and Description |
|---|---|
<K2,V2,R extends com.gs.collections.api.multimap.MutableMultimap<K2,V2>> |
collectKeysValues(com.gs.collections.api.block.function.Function2<? super K,? super V,com.gs.collections.api.tuple.Pair<K2,V2>> function,
R target)
Same as the collect method but uses the specified target multimap for the results.
|
<V2,R extends com.gs.collections.api.multimap.MutableMultimap<K,V2>> |
collectValues(com.gs.collections.api.block.function.Function<? super V,? extends V2> function,
R target)
Same as the collect method but uses the specified target multimap for the results.
|
boolean |
containsKey(java.lang.Object key)
Returns
true if any values are mapped to the specified key. |
boolean |
containsKeyAndValue(java.lang.Object key,
java.lang.Object value)
Returns
true if the specified key-value pair is mapped. |
boolean |
containsValue(java.lang.Object value)
Returns
true if any key is mapped to the specified value. |
protected abstract C |
createCollection()
Creates the collection of values for a single key.
|
protected com.gs.collections.api.block.function.Function<AbstractMultimap<K,V,C>,C> |
createCollectionBlock() |
boolean |
equals(java.lang.Object object)
Compares the specified object with this Multimap for equality.
|
void |
forEachKey(com.gs.collections.api.block.procedure.Procedure<? super K> procedure)
Calls the
procedure with each key. |
void |
forEachKeyMultiValues(com.gs.collections.api.block.procedure.Procedure2<K,? super java.lang.Iterable<V>> procedure)
Calls the
procedure with each key-Iterable[value]. |
void |
forEachKeyValue(com.gs.collections.api.block.procedure.Procedure2<K,V> procedure)
Calls the
procedure with each key-value pair. |
void |
forEachValue(com.gs.collections.api.block.procedure.Procedure<? super V> procedure)
Calls the procedure with each value.
|
protected abstract com.gs.collections.api.map.MapIterable<K,C> |
getMap() |
int |
hashCode()
Returns the hash code for this multimap.
|
com.gs.collections.api.bag.Bag<K> |
keyBag()
Returns a
Bag of keys with the count corresponding to the number of mapped values. |
com.gs.collections.api.RichIterable<com.gs.collections.api.tuple.Pair<K,com.gs.collections.api.RichIterable<V>>> |
keyMultiValuePairsView()
Returns a lazy view of the pair of a key and and a lazy view of the values mapped to that key.
|
com.gs.collections.api.RichIterable<K> |
keysView()
Returns a lazy view of the unique keys.
|
com.gs.collections.api.RichIterable<com.gs.collections.api.tuple.Pair<K,V>> |
keyValuePairsView()
Returns a lazy view of all of the key/value pairs.
|
com.gs.collections.api.RichIterable<com.gs.collections.api.RichIterable<V>> |
multiValuesView()
Returns an unmodifiable view of all of the values mapped to each key.
|
boolean |
notEmpty()
Returns
true if there is at least one entry. |
<R extends com.gs.collections.api.multimap.MutableMultimap<K,V>> |
rejectKeysMultiValues(com.gs.collections.api.block.predicate.Predicate2<? super K,? super java.lang.Iterable<V>> predicate,
R target)
Same as the reject method but uses the specified target multimap for the results.
|
<R extends com.gs.collections.api.multimap.MutableMultimap<K,V>> |
rejectKeysValues(com.gs.collections.api.block.predicate.Predicate2<? super K,? super V> predicate,
R target)
Same as the reject method but uses the specified target multimap for the results.
|
<R extends com.gs.collections.api.multimap.MutableMultimap<K,V>> |
selectKeysMultiValues(com.gs.collections.api.block.predicate.Predicate2<? super K,? super java.lang.Iterable<V>> predicate,
R target)
Same as the select method but uses the specified target multimap for the results.
|
<R extends com.gs.collections.api.multimap.MutableMultimap<K,V>> |
selectKeysValues(com.gs.collections.api.block.predicate.Predicate2<? super K,? super V> predicate,
R target)
Same as the select method but uses the specified target multimap for the results.
|
java.lang.String |
toString()
Returns a string representation of the multimap, generated by calling
toString on the map returned by Multimap.toMap(). |
com.gs.collections.api.RichIterable<V> |
valuesView()
Returns a lazy flattened view of all the values.
|
protected abstract C createCollection()
Collections with weak, soft, or phantom references are not supported.
Each call to createCollection should create a new instance.
The returned collection class determines whether duplicate key-value pairs are allowed.
protected com.gs.collections.api.block.function.Function<AbstractMultimap<K,V,C>,C> createCollectionBlock()
public boolean containsKey(java.lang.Object key)
com.gs.collections.api.multimap.Multimaptrue if any values are mapped to the specified key.public boolean containsValue(java.lang.Object value)
com.gs.collections.api.multimap.Multimaptrue if any key is mapped to the specified value.public boolean containsKeyAndValue(java.lang.Object key,
java.lang.Object value)
com.gs.collections.api.multimap.Multimaptrue if the specified key-value pair is mapped.public com.gs.collections.api.RichIterable<K> keysView()
com.gs.collections.api.multimap.Multimappublic com.gs.collections.api.RichIterable<com.gs.collections.api.RichIterable<V>> multiValuesView()
com.gs.collections.api.multimap.Multimappublic com.gs.collections.api.bag.Bag<K> keyBag()
com.gs.collections.api.multimap.MultimapBag of keys with the count corresponding to the number of mapped values.public com.gs.collections.api.RichIterable<V> valuesView()
com.gs.collections.api.multimap.Multimappublic com.gs.collections.api.RichIterable<com.gs.collections.api.tuple.Pair<K,com.gs.collections.api.RichIterable<V>>> keyMultiValuePairsView()
com.gs.collections.api.multimap.Multimappublic com.gs.collections.api.RichIterable<com.gs.collections.api.tuple.Pair<K,V>> keyValuePairsView()
com.gs.collections.api.multimap.Multimappublic boolean equals(java.lang.Object object)
com.gs.collections.api.multimap.Multimap
Two Multimaps are equal when their map views (as returned by Multimap.toMap()) are also equal.
In general, two Multimaps with identical key-value mappings may or may not be equal, depending on the type of the collections holding the values. If the backing collections are Sets, then two instances with the same key-value mappings are equal, but if the backing collections are Lists, equality depends on the ordering of the values for each key.
Any two empty Multimaps are equal, because they both have empty Multimap.toMap() views.
public int hashCode()
The hash code of a multimap is defined as the hash code of the map view,
as returned by Multimap.toMap().
public java.lang.String toString()
toString on the map returned by Multimap.toMap().toString in class java.lang.Objectpublic boolean notEmpty()
com.gs.collections.api.multimap.Multimaptrue if there is at least one entry.public void forEachValue(com.gs.collections.api.block.procedure.Procedure<? super V> procedure)
com.gs.collections.api.multimap.MultimapGiven a Multimap with the contents:
{ "key1" : ["val1", "val2", "val2"], "key2" : ["val3"] }
The given procedure would be invoked with the parameters:
[ "val1", "val2", "val2", "val3" ]
public void forEachKey(com.gs.collections.api.block.procedure.Procedure<? super K> procedure)
com.gs.collections.api.multimap.Multimapprocedure with each key.
Given a Multimap with the contents:
{ "key1" : ["val1", "val2", "val2"], "key2" : ["val3"] }
The given procedure would be invoked with the parameters:
[ "key1", "key2" ]
public void forEachKeyValue(com.gs.collections.api.block.procedure.Procedure2<K,V> procedure)
com.gs.collections.api.multimap.Multimapprocedure with each key-value pair.
Given a Multimap with the contents:
{ "key1" : ["val1", "val2", "val2"], "key2" : ["val3"] }
The given procedure would be invoked with the parameters:
[ ["key1", "val1"], ["key1", "val2"], ["key1", "val2"], ["key2", "val3"] ]
public void forEachKeyMultiValues(com.gs.collections.api.block.procedure.Procedure2<K,? super java.lang.Iterable<V>> procedure)
com.gs.collections.api.multimap.Multimapprocedure with each key-Iterable[value].
Given a Multimap with the contents:
{ "key1" : ["val1", "val2", "val2"], "key2" : ["val3"] }
The given procedure would be invoked with the parameters:
[ ["key1", {@link RichIterable["val1", "val2", "val2"]}], ["key2", {@link RichIterable["val3"]}] ]
public <R extends com.gs.collections.api.multimap.MutableMultimap<K,V>> R selectKeysValues(com.gs.collections.api.block.predicate.Predicate2<? super K,? super V> predicate, R target)
com.gs.collections.api.multimap.Multimap
e.g.
return multimap.selectKeysValues(new Predicate2<Integer, Person>()
{
public boolean accept(Integer age, Person person)
{
return (age >= 18)
&& (person.getAddress().getCity().equals("Metuchen"));
}
}, FastListMultimap.newMultimap());
selectKeysValues in interface com.gs.collections.api.multimap.Multimap<K,V>predicate - a Predicate2 to use as the select criteriatarget - the Multimap to append to for all elements in this Multimap that satisfy the predicatetarget, which contains appended elements as a result of the select criteriapublic <R extends com.gs.collections.api.multimap.MutableMultimap<K,V>> R rejectKeysValues(com.gs.collections.api.block.predicate.Predicate2<? super K,? super V> predicate, R target)
com.gs.collections.api.multimap.Multimap
e.g.
return multimap.rejectKeysValues(new Predicate2<Integer, Person>()
{
public boolean accept(Integer age, Person person)
{
return (age >= 18)
&& (person.getAddress().getCity().equals("Metuchen"));
}
}, FastListMultimap.newMultimap());
rejectKeysValues in interface com.gs.collections.api.multimap.Multimap<K,V>predicate - a Predicate2 to use as the reject criteriatarget - the Multimap to append to for all elements in this Multimap that don't satisfy the predicatetarget, which contains appended elements that don't satisfy the predicatepublic <R extends com.gs.collections.api.multimap.MutableMultimap<K,V>> R selectKeysMultiValues(com.gs.collections.api.block.predicate.Predicate2<? super K,? super java.lang.Iterable<V>> predicate, R target)
com.gs.collections.api.multimap.Multimap
e.g.
return multimap.selectKeysMultiValues(new Predicate2<Integer, Iterable<Person>>()
{
public boolean accept(Integer age, Iterable<Person> values)
{
return (age >= 18)
&& ((RichIterable<Person>)values.size() >= 2);
}
}, FastListMultimap.newMultimap());
selectKeysMultiValues in interface com.gs.collections.api.multimap.Multimap<K,V>predicate - a Predicate2 to use as the select criteriatarget - the Multimap to append to for all elements in this Multimap that satisfy the predicatetarget, which contains appended elements as a result of the select criteriapublic <R extends com.gs.collections.api.multimap.MutableMultimap<K,V>> R rejectKeysMultiValues(com.gs.collections.api.block.predicate.Predicate2<? super K,? super java.lang.Iterable<V>> predicate, R target)
com.gs.collections.api.multimap.Multimap
e.g.
return multimap.rejectKeysMultiValues(new Predicate2<Integer, Iterable<Person>>()
{
public boolean accept(Integer age, Iterable<Person> values)
{
return (age >= 18)
&& ((RichIterable<Person>)values.size() >= 2);
}
}, FastListMultimap.newMultimap());
rejectKeysMultiValues in interface com.gs.collections.api.multimap.Multimap<K,V>predicate - a Predicate2 to use as the reject criteriatarget - the Multimap to append to for all elements in this Multimap that don't satisfy the predicatetarget, which contains appended elements that don't satisfy the predicatepublic <K2,V2,R extends com.gs.collections.api.multimap.MutableMultimap<K2,V2>> R collectKeysValues(com.gs.collections.api.block.function.Function2<? super K,? super V,com.gs.collections.api.tuple.Pair<K2,V2>> function, R target)
com.gs.collections.api.multimap.Multimap
e.g.
return multimap.collectKeysValues(new Function2<Integer, Person, Pair<String, String>>()
{
public Pair<String, String> valueOf(Integer age, Person person)
{
return Tuples.pair(age.toString(), person.getLastName());
}
}, HashBagMultimap.newMultimap());
collectKeysValues in interface com.gs.collections.api.multimap.Multimap<K,V>function - a Function2 to use for transformationtarget - the Multimap to append for all elements in this Multimap that are evaluated in functiontarget, which contains appended elements as a result of the transformationpublic <V2,R extends com.gs.collections.api.multimap.MutableMultimap<K,V2>> R collectValues(com.gs.collections.api.block.function.Function<? super V,? extends V2> function, R target)
com.gs.collections.api.multimap.Multimap
e.g.
return multimap.collectValues(new Function<Person, String>()
{
public String valueOf(Person person)
{
return person.getLastName();
}
}, FastListMultimap.newMultimap());
collectValues in interface com.gs.collections.api.multimap.Multimap<K,V>function - a Function to use for transformationtarget - the Multimap to append for all elements in this Multimap that are evaluated in functiontarget, which contains appended elements as a result of the transformation