ral.util
Class HashRel<FROM,TO,T extends Pair<FROM,TO>>

java.lang.Object
  extended by ral.util.HashRel<FROM,TO,T>
All Implemented Interfaces:
MultiRelationship<FROM,TO,T>, Relationship<FROM,TO,T>, UniMultiRelationship<FROM,TO,T>, UniRelationship<FROM,TO,T>
Direct Known Subclasses:
One2ManyHashRel, ReflexiveHashRel

public class HashRel<FROM,TO,T extends Pair<FROM,TO>>
extends java.lang.Object
implements Relationship<FROM,TO,T>

A HashRel represents a bidirectional relationship where pairs are stored internally using HashSets. Thus, only one edge between any two objects is possible.


Constructor Summary
HashRel()
           
HashRel(java.util.Collection<? extends T> r)
           
 
Method Summary
 boolean add(T a)
          Adds a pair to the relationship.
 void clearFrom(FROM f)
          Clears all pairs with t in the TO position
 void clearTo(TO t)
          Clears all pairs with t in the TO position
 void copyFrom(FROM f, FROM t)
          Copies all pairs with f in the FROM position, where the new pairs have t in the FROM position instead.
 void copyTo(TO f, TO t)
          Copies all pairs with f in the TO position, where the new pairs have t in the TO position instead.
 java.util.Set<TO> from(FROM f)
          Returns all objects t, such that there exists a pair
 java.util.Set<T> fromPairs(FROM f)
          Returns all pairs with f in the FROM position
 T get(FROM f, TO t)
          Gets a Pair instance.
 boolean remove(FROM f, TO t)
          Removes a pair instance
 boolean remove(Pair<FROM,TO> p)
          Removes a pair instance
 java.util.Set<FROM> to(TO t)
          Returns all objects f, such that there exists a pair
 java.util.Set<T> toPairs(TO t)
          Returns all pairs with t in the TO position
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashRel

public HashRel()

HashRel

public HashRel(java.util.Collection<? extends T> r)
Method Detail

add

public boolean add(T a)
Description copied from interface: UniMultiRelationship
Adds a pair to the relationship.

Specified by:
add in interface UniMultiRelationship<FROM,TO,T extends Pair<FROM,TO>>

get

public T get(FROM f,
             TO t)
Description copied from interface: UniMultiRelationship
Gets a Pair instance.

Specified by:
get in interface UniMultiRelationship<FROM,TO,T extends Pair<FROM,TO>>

clearFrom

public void clearFrom(FROM f)
Description copied from interface: UniMultiRelationship
Clears all pairs with t in the TO position

Specified by:
clearFrom in interface UniMultiRelationship<FROM,TO,T extends Pair<FROM,TO>>

clearTo

public void clearTo(TO t)
Description copied from interface: MultiRelationship
Clears all pairs with t in the TO position

Specified by:
clearTo in interface MultiRelationship<FROM,TO,T extends Pair<FROM,TO>>

copyFrom

public void copyFrom(FROM f,
                     FROM t)
Description copied from interface: UniMultiRelationship
Copies all pairs with f in the FROM position, where the new pairs have t in the FROM position instead. Note, this operation clones the underlying Pair instances.

Specified by:
copyFrom in interface UniMultiRelationship<FROM,TO,T extends Pair<FROM,TO>>

copyTo

public void copyTo(TO f,
                   TO t)
Description copied from interface: MultiRelationship
Copies all pairs with f in the TO position, where the new pairs have t in the TO position instead. Note, this operation clones the underlying Pair instances.

Specified by:
copyTo in interface MultiRelationship<FROM,TO,T extends Pair<FROM,TO>>

remove

public boolean remove(Pair<FROM,TO> p)
Description copied from interface: UniMultiRelationship
Removes a pair instance

Specified by:
remove in interface UniMultiRelationship<FROM,TO,T extends Pair<FROM,TO>>

remove

public boolean remove(FROM f,
                      TO t)
Description copied from interface: UniMultiRelationship
Removes a pair instance

Specified by:
remove in interface UniMultiRelationship<FROM,TO,T extends Pair<FROM,TO>>

toPairs

public java.util.Set<T> toPairs(TO t)
Description copied from interface: MultiRelationship
Returns all pairs with t in the TO position

Specified by:
toPairs in interface MultiRelationship<FROM,TO,T extends Pair<FROM,TO>>
Specified by:
toPairs in interface Relationship<FROM,TO,T extends Pair<FROM,TO>>

fromPairs

public java.util.Set<T> fromPairs(FROM f)
Description copied from interface: UniMultiRelationship
Returns all pairs with f in the FROM position

Specified by:
fromPairs in interface Relationship<FROM,TO,T extends Pair<FROM,TO>>
Specified by:
fromPairs in interface UniMultiRelationship<FROM,TO,T extends Pair<FROM,TO>>
Specified by:
fromPairs in interface UniRelationship<FROM,TO,T extends Pair<FROM,TO>>

to

public java.util.Set<FROM> to(TO t)
Description copied from interface: MultiRelationship
Returns all objects f, such that there exists a pair

Specified by:
to in interface MultiRelationship<FROM,TO,T extends Pair<FROM,TO>>
Specified by:
to in interface Relationship<FROM,TO,T extends Pair<FROM,TO>>

from

public java.util.Set<TO> from(FROM f)
Description copied from interface: UniMultiRelationship
Returns all objects t, such that there exists a pair

Specified by:
from in interface Relationship<FROM,TO,T extends Pair<FROM,TO>>
Specified by:
from in interface UniMultiRelationship<FROM,TO,T extends Pair<FROM,TO>>
Specified by:
from in interface UniRelationship<FROM,TO,T extends Pair<FROM,TO>>