|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractSet
java.util.HashSet
org.zedlib.HashSet
org.zedlib.HashRel
A relation is a set of relationships between two objects. Each (x,y) is termed a binary relation (or maplet) relating some x of set X to some y of set Y, contained within the relation X ↔ Y.
Note that this is not equivalent to a java.util.Map which
enforces a unique set of keys (properly called a function). In other words,
a relation allows x of X to appear multiple times so long as each x relates
to a different y of Y.
If X and Y are sets, then X ↔ Y is the set of binary relations between X and Y. Each such relation is a subset of X x Y. A 'maplet' from x to y is another way of expressing the ordered pair (x, y).
For example, the following are valid binary relations (maplets, ordered pairs)
within a Relation R:
(tom, mary)
(fred, jane)
(tom, jane)
| Constructor Summary | |
HashRel()
|
|
HashRel(Collection c)
Constructs a relation containing all elements in the supplied collection of maplets. |
|
HashRel(Collection x,
Collection y)
Constructs a relation between two collections. |
|
HashRel(Map m)
Constructs a relation from a given java.util.Map. |
|
HashRel(Relation r)
Constructs a relation from the given relation R. |
|
| Method Summary | |
boolean |
add(Maplet m)
Adds a maplet to this relation. |
boolean |
add(Object o)
Overrides add in Set to ensure only
maplets are added. |
boolean |
add(Object x,
Object y)
Adds a pair of objects to this relation as a maplet. |
boolean |
addAll(Collection c)
Adds all entries in a java.util.Collection to this relation. |
boolean |
addAll(Map m)
Adds all entries in a java.util.Map to this relation. |
protected void |
buildRelation(Collection x,
Collection y)
|
Relation |
composition(Relation r)
Returns the relational composition of this relation and another given relation, thus if (x,y) exists in this relation Q and (y,z) exists in R then (x,z) appears in the composed relation. |
Set |
domain()
Returns a set containing the unique objects in X of the relation X ↔ Y. |
Relation |
domainAntiRestriction(Set s)
Returns a relation being those maplets in this relation whose x in (x,y) do not appear in the given set. |
Relation |
domainRestriction(Set s)
Returns a relation being only those maplets in this relation whose x in (x,y) appear in the given set. |
protected Set |
getInstance()
|
protected Set |
getInstance(Set s)
|
Set |
image(Set s)
Returns a set containing the range of a domain restriction on this relation, that is, returns a set of all y of Y for which x of X is related in X ↔ Y. |
Relation |
inverse()
Returns the relational inverse of this relation, thus each maplet (x,y) is inverted to (y,x). |
boolean |
isFunction()
|
boolean |
isInjection()
|
boolean |
isReflexive()
|
Relation |
override(Relation r)
Returns a relation being this relation overridden with a given relation. |
Set |
range()
Returns a set containing the unique objects in Y of the relation X ↔ Y. |
Relation |
rangeAntiRestriction(Set t)
Returns a relation containing those maplets in this relation whose y in (x,y) do not appear in the given set. |
Relation |
rangeRestriction(Set t)
Returns a relation containing only those maplets of this relation whose y in (x,y) appear in the given set. |
String |
toString()
|
Relation |
transitiveClosure()
Returns the transitive closure of this relation. |
| Methods inherited from class org.zedlib.HashSet |
cartesianProduct, difference, difference, identity, intersection, intersection, isProperSubsetOf, isSubsetOf, isSupersetOf, union, union |
| Methods inherited from class java.util.HashSet |
clear, clone, contains, isEmpty, iterator, remove, size |
| Methods inherited from class java.util.AbstractSet |
equals, hashCode, removeAll |
| Methods inherited from class java.util.AbstractCollection |
containsAll, retainAll, toArray, toArray |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.zedlib.Set |
cartesianProduct, difference, identity, intersection, isSubsetOf, isSupersetOf, union |
| Methods inherited from interface java.util.Set |
clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Constructor Detail |
public HashRel()
public HashRel(Collection x,
Collection y)
x - any collectiony - any collection
IllegalArgumentException - if the collections are not the same sizepublic HashRel(Map m)
java.util.Map.
public HashRel(Collection c)
ClassCastException - if the collection does not contain mapletspublic HashRel(Relation r)
| Method Detail |
protected void buildRelation(Collection x,
Collection y)
protected Set getInstance()
getInstance in class HashSetprotected Set getInstance(Set s)
getInstance in class HashSetpublic Set domain()
If R is a binary relation between X and Y, then the domain of R is the set of all members of X which are related to at least one member of Y by R.
domain in interface Relationpublic Set range()
If R is a binary relation between X and Y, then the range of R is the set of all members of Y to which at least one member of X is related by R.
range in interface Relationpublic boolean add(Object o)
add in Set to ensure only
maplets are added.
add in interface Settrue if the object was added to this relation
ClassCastException - if the object is not a Mapletpublic boolean add(Maplet m)
add in interface Relationm - any maplet
true if the given maplet was added to this relationSet.add(Object o)
public boolean add(Object x,
Object y)
add in interface Relationx - any objecty - any object
true if the objects were added to this relationpublic boolean addAll(Collection c)
java.util.Collection to this relation. Overrides addAll
in Set to ensure only Maplets are added.
addAll in interface Setc - any collection
true if any objects of the collection were added to this relation
ClassCastException - if any element is not a mapletpublic boolean addAll(Map m)
java.util.Map to this relation.
addAll in interface Relationm - any java.util.Map
true if any objects of the map were added to this relationSet.addAll(Collection c)public Relation domainRestriction(Set s)
The domain restriction R.domainRestriction(S) of this relation R to a set S, relates x to y if and only if R relates x to y and x is a member of S.
domainRestriction in interface Relations - the set of objects with which to restrict the domain of this relation
spublic Relation domainAntiRestriction(Set s)
This operation is the complemented counterpart of the domain restriction operation. An object x is related to an object y by the relation R.domainAntiRestrict(S) if and only if x is related to y by R and x is not a member of S.
domainAntiRestriction in interface Relations - the set of objects with which to anti-restrict this relation.
By definition, these objects will not appear in the domain of the restricted relation.
spublic Relation rangeRestriction(Set t)
The range restriction R.rangeRestrict(T) of R to a set T relates x to y if and only if R relates x to y and y is a member of T.
rangeRestriction in interface Relationt - the set of objects with which to restrict the range of this relation
tpublic Relation rangeAntiRestriction(Set t)
This operation is the complemented counterpart of the domain restriction operation. An object x is related to an object y by the relation R.rangeAntiRestrict(T) if and only if x is related to y by R and y is not a member of T.
rangeAntiRestriction in interface Relationt - the set of objects with which to anti-restrict this relation.
By definition, these objects will not appear in the range of the restricted relation.
tpublic Relation inverse()
An object y is related to an object x by the relational inverse R∼ of R if and only if x is related to y by R.
inverse in interface Relationpublic Relation composition(Relation r)
The composition Q.compose(R) of two relations Q: X ↔ Y and R: Y ↔ Z relates a member x of X to a member z of Z if and only if there is at least one element y of Y to which x is related by Q and which is itself related to z by R.
composition in interface Relationr - the relation R with which to perform the composition
rpublic Relation override(Relation r)
override in interface Relationr - the relation to override this relation
rpublic Relation transitiveClosure()
If R is a relation from a set X to itself, R.transitiveClosure(), or R+, is the strongest or smallest relation containing R which is transitive.
Example:
if R = { (a,b), (b,c), (a,e), (c,d) }
then R+ = { (a,b), (b,c), (a,e), (c,d), (a,c), (a,d), (b,d) }
If a relation Relation.transitiveClosure(r).intersect(Relation.identity(r)) is
not empty, then the transitive closure contains one or more cycles.
transitiveClosure in interface Relationpublic Set image(Set s)
The operation does not modify this relation.
image in interface Relationpublic boolean isFunction()
isFunction in interface Relationtrue if elements in the domain of this relation
are uniquepublic boolean isInjection()
isInjection in interface Relationtrue if elements in the domain of this relation
are unique and none of them map to the same object.public boolean isReflexive()
isReflexive in interface Relationtrue if all elements in the domain of this relation
are at least related to themselves in the range of this relation.public String toString()
String representation of this relation
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||