|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjpaul.DataStructs.Relation<K,V>
public abstract class Relation<K,V>
Relation
is a binary relation, accepting one to many
and many to one mappings.
It is similar to net.cscott.jutil.MultiMap
. One
difference: Relation
does not implement the
Map
interface. I have always found this very
confusing; e.g., MultiMap.get(v)
returns an arbitrary
value from the collection to which the multimap maps the value
v
.
Nested Class Summary | |
---|---|
static interface |
Relation.EntryVisitor<Key,Value>
Relation.EntryVisitor is a wrapper for a function that is
called on a relation entry of the form
<key,value> . |
Constructor Summary | |
---|---|
Relation()
|
Method Summary | ||
---|---|---|
protected abstract java.util.Set<V> |
_getValues(K key)
|
|
abstract boolean |
add(K key,
V value)
Adds the pair <key, value> to the relation. |
|
abstract 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()
|
|
abstract boolean |
contains(K key,
V value)
Checks the existence of the relation <key,value> . |
|
boolean |
containsAll(K key,
java.util.Collection<V> values)
Checks the existence of the relation between key
and every element from values . |
|
abstract boolean |
containsKey(K key)
Checks the existence of the key key in this relation. |
|
abstract boolean |
equals(java.lang.Object o)
Checks the equality of two relations |
|
void |
forAllEntries(Relation.EntryVisitor<K,V> visitor)
Visits all the entries <key,value> of
this relation and calls visitor.visit
on each of them. |
|
java.util.Set<V> |
getValues(K key)
Returns the image of key through this relation. |
|
abstract boolean |
isEmpty()
Tests if this relation is empty or not. |
|
abstract java.util.Set<K> |
keys()
Returns all the keys appearing in this relation. |
|
abstract boolean |
remove(K key,
V value)
Removes the relation between key and
value . |
|
abstract boolean |
removeAll(K key,
java.util.Collection<V> values)
Removes the relation between key and
any element from values . |
|
abstract boolean |
removeKey(K key)
Removes all the relations attached to key . |
|
abstract boolean |
removeKeys(Predicate<K> predicate)
Removes all the keys that satisfy predicate.check() . |
|
abstract boolean |
removeValues(Predicate<V> predicate)
Removes all the values that satisfy predicate.check() . |
|
Relation<V,K> |
revert(Relation<V,K> result)
Revert this relation and store the result into
the relation result . |
|
java.lang.String |
toString()
Pretty-print function for debug. |
|
abstract boolean |
union(Relation<K,V> rel)
Combines this relation with relation
rel . |
|
static
|
unmodifiableRelation(Relation<K,V> rel)
|
|
abstract java.lang.Iterable<V> |
values()
Returns an immutable view of all the values appearing in this relation. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Relation()
Method Detail |
---|
public abstract boolean add(K key, V value)
<key, value>
to the relation.
Returns true
if the new relation is bigger.
public abstract boolean addAll(K key, java.util.Collection<V> values)
key
to each element of the set
values
. values
should not contain
duplicated elements.
Returns true
if the new relation is bigger.
public abstract boolean remove(K key, V value)
key
and
value
.
true
iff the relation changedpublic abstract boolean removeAll(K key, java.util.Collection<V> values)
key
and
any element from values
.
true
iff the relation changedpublic abstract boolean removeKey(K key)
key
.
true
iff the relation changedpublic abstract boolean removeKeys(Predicate<K> predicate)
predicate.check()
.
true
iff the relation changedpublic abstract boolean removeValues(Predicate<V> predicate)
predicate.check()
.
true
iff the relation changedpublic abstract boolean contains(K key, V value)
<key,value>
.
public boolean containsAll(K key, java.util.Collection<V> values)
key
and every element from values
.
public abstract boolean containsKey(K key)
key
key in this relation.
public abstract boolean isEmpty()
public java.util.Set<V> getValues(K key)
key
through this relation.
The returned collection is immutable.
Can return null
if no value is attached to key.
protected abstract java.util.Set<V> _getValues(K key)
public abstract java.util.Set<K> keys()
this
relation.
public abstract java.lang.Iterable<V> values()
this
relation. The view may contain the
same value twice.
public abstract boolean union(Relation<K,V> rel)
this
relation with relation
rel
. A null
parameter is considered
to be an empty relation.
true
iff this
relation has
changed.public abstract boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public void forAllEntries(Relation.EntryVisitor<K,V> visitor)
<key,value>
of
this
relation and calls visitor.visit
on each of them.
public Relation<V,K> revert(Relation<V,K> result)
this
relation and store the result into
the relation result
. <a,b> appears in the
reverse relation iff <b,a> appears in this
relation. Returns the new relation (ie,
result
).
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String toString()
rel1.equals(rel2) <==> rel1.toString().equals(rel2.toString())
toString
in class java.lang.Object
public static <K,V> Relation<K,V> unmodifiableRelation(Relation<K,V> rel)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |