|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jpaul.DataStructs.Relation<K,V> jpaul.DataStructs.MapSetRelation<K,V>
public class MapSetRelation<K,V>
MapSetRelation
is an implementation of the
Relation
interface based on a Map
from
keys to Set
s of values.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class jpaul.DataStructs.Relation |
---|
Relation.EntryVisitor<Key,Value> |
Constructor Summary | |
---|---|
MapSetRelation()
Constructs a Relation represented using a
LinkedHashMap from keys to
LinkedHashSet s of values. |
|
MapSetRelation(MapFactory<K,java.util.Set<V>> mapFact,
SetFactory<V> setFact)
Constructs a Relation represented by a
Map from keys to Set s of values. |
Method Summary | |
---|---|
protected java.util.Set<V> |
_getValues(K key)
Method used by the internal implementation of the Relation or its subclasses. |
boolean |
add(K key,
V value)
Adds the pair <key, value> to the relation. |
boolean |
addAll(K key,
java.util.Collection<V> values)
Adds a relation from key to each element of the set
values . |
java.lang.Object |
clone()
Creates a new, independent relation (independent = the operations on the new relation won't affect the old one). |
boolean |
containsKey(K key)
Checks the existence of the key key in this relation. |
boolean |
equals(java.lang.Object o)
Checks the equality of two relations |
int |
hashCode()
Complexity: linear in the number of (key,value) pairs from the relation. |
boolean |
isEmpty()
Tests if this relation is empty or not. |
java.util.Set<K> |
keys()
Returns an IMMUTABLE view of all the keys appearing in this relation. |
boolean |
remove(K key,
V value)
Removes the relation between key and
value . |
boolean |
removeAll(K key,
java.util.Collection<V> values)
Removes the relation between key and
any element from values . |
boolean |
removeKey(K key)
Removes all the relations attached to key . |
boolean |
removeKeys(Predicate<K> predicate)
Removes all the keys that satisfy predicate.check() . |
boolean |
removeValues(Predicate<V> predicate)
Removes all the values that satisfy predicate.check() . |
boolean |
union(Relation<K,V> rel)
Combines this relation with relation
rel . |
java.lang.Iterable<V> |
values()
Returns an IMMUTABLE view of all the values appearing in this relation. |
Methods inherited from class jpaul.DataStructs.Relation |
---|
contains, containsAll, forAllEntries, getValues, revert, size, toString, unmodifiableRelation |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MapSetRelation()
Relation
represented using a
LinkedHashMap
from keys to
LinkedHashSet
s of values. Consumes a lot of
memory but fast for large relation.
public MapSetRelation(MapFactory<K,java.util.Set<V>> mapFact, SetFactory<V> setFact)
Relation
represented by a
Map
from keys to Set
s of values.
The map is created by mapFact
and the sets by
setFact
.
MapFacts
,
SetFacts
Method Detail |
---|
public boolean add(K key, V value)
Relation
<key, value>
to the relation.
Returns true
if the new relation is bigger.
add
in class Relation<K,V>
public boolean addAll(K key, java.util.Collection<V> values)
Relation
key
to each element of the set
values
. values
should not contain
duplicated elements.
Returns true
if the new relation is bigger.
addAll
in class Relation<K,V>
public boolean remove(K key, V value)
Relation
key
and
value
.
remove
in class Relation<K,V>
true
iff the relation changedpublic boolean removeAll(K key, java.util.Collection<V> values)
Relation
key
and
any element from values
.
removeAll
in class Relation<K,V>
true
iff the relation changedpublic boolean removeKey(K key)
Relation
key
.
removeKey
in class Relation<K,V>
true
iff the relation changedpublic boolean removeKeys(Predicate<K> predicate)
Relation
predicate.check()
.
removeKeys
in class Relation<K,V>
true
iff the relation changedpublic boolean removeValues(Predicate<V> predicate)
Relation
predicate.check()
.
removeValues
in class Relation<K,V>
true
iff the relation changedpublic boolean containsKey(K key)
Relation
key
key in this relation.
containsKey
in class Relation<K,V>
public boolean isEmpty()
Relation
isEmpty
in class Relation<K,V>
protected final java.util.Set<V> _getValues(K key)
Relation
Relation
or its subclasses. Similar to the
user-level Relation.getValues(K)
but the returned set IS MUTABLE.
Mutating this set affects the set of values that are
associated with a given key; therefore, this method cannot be
used by Relation
clients directly.
_getValues
in class Relation<K,V>
public java.util.Set<K> keys()
Relation
this
relation. If you want to delete a key, then
use Relation.removeKey(K)
.
keys
in class Relation<K,V>
public java.lang.Iterable<V> values()
Relation
this
relation. The view may contain the same
value twice, if it is associated with two distinct keys.
values
in class Relation<K,V>
public boolean union(Relation<K,V> rel)
Relation
this
relation with relation
rel
. A null
parameter is considered
to be an empty relation.
union
in class Relation<K,V>
true
iff this
relation has
changed.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
Relation
equals
in class Relation<K,V>
public java.lang.Object clone()
clone
in class Relation<K,V>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |