Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Util.Collections
Class AbstrRelation  view AbstrRelation download AbstrRelation.java

java.lang.Object
  extended byUtil.Collections.AbstrRelation
All Implemented Interfaces:
java.lang.Cloneable, Relation, java.io.Serializable
Direct Known Subclasses:
AbstrRelationMapBased

public abstract class AbstrRelation
extends java.lang.Object
implements Relation, java.lang.Cloneable, java.io.Serializable

AbstrRelation

Version:
$Id: AbstrRelation.java,v 1.2 2003/05/12 10:05:21 joewhaley Exp $

Nested Class Summary
 
Nested classes inherited from class Util.Collections.Relation
Relation.EntryVisitor
 
Field Summary
protected  int hashCode
           
static boolean OPTIMIZE_HASH_CODE
          Optimizes the .hashCode() method by caching the hash code.
 
Constructor Summary
AbstrRelation()
           
 
Method Summary
 boolean add(java.lang.Object key, java.lang.Object value)
          Adds the pair <key, value> to the relation.
 boolean addAll(java.lang.Object key, java.util.Collection values)
          Adds a relation from key to each element of the set values.
 java.lang.Object clone()
          Clones this relation.
 boolean contains(java.lang.Object key, java.lang.Object value)
          Checks the existence of the relation <key,value>.
 boolean containsKey(java.lang.Object key)
          Checks the existence of the key key in this relation.
private  boolean equal_sets(java.util.Collection c1, java.util.Collection c2)
           
 boolean equals(java.lang.Object o)
          Checks the equality of two relations
 void forAllEntries(Relation.EntryVisitor visitor)
          Visits all the entries <key,value> of this relation and calls visitor.visit on each of them.
protected  Relation getEmptyRelation()
           
 java.util.Set getValues(java.lang.Object key)
          Returns the image of key through this relation.
protected  java.util.Set getValues2(java.lang.Object key)
           
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 boolean isEmpty()
          Tests if this relation is empty or not.
 java.util.Set keys()
          Returns all the keys appearing in this relation.
 void remove(java.lang.Object key, java.lang.Object value)
          Removes the relation between key and value.
 void removeAll(java.lang.Object key, java.util.Collection values)
          Removes the relation between key and any element from values.
 void removeKey(java.lang.Object key)
          Removes all the relations attached to key.
 void removeKeys(PredicateWrapper predicate)
          Removes all the keys that satisfy predicate.check().
 void removeObjects(PredicateWrapper predicate)
          Removes all the relations involving at least one object that satisfy predicate.check().
 void removeValues(PredicateWrapper predicate)
          Removes all the values that satisfy predicate.check().
 Relation select(java.util.Collection selected_keys)
          Returns the subrelation of this relation that contains only the keys that appear in selected_keys.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 void union(Relation rel)
          Combines this relation with a new one.
 java.util.Set values()
          Returns all the values appearing in this relation.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

OPTIMIZE_HASH_CODE

public static final boolean OPTIMIZE_HASH_CODE
Optimizes the .hashCode() method by caching the hash code. The cached value is invalidated after each update.

See Also:
Constant Field Values

hashCode

protected int hashCode
Constructor Detail

AbstrRelation

public AbstrRelation()
Method Detail

getEmptyRelation

protected Relation getEmptyRelation()

add

public boolean add(java.lang.Object key,
                   java.lang.Object value)
Description copied from interface: Relation
Adds the pair <key, value> to the relation. Returns true if the new relation is bigger.

Specified by:
add in interface Relation

addAll

public boolean addAll(java.lang.Object key,
                      java.util.Collection values)
Description copied from interface: Relation
Adds a relation from key to each element of the set values. values should not contain duplicated elements. Returns true if the new relation is bigger.

Specified by:
addAll in interface Relation

remove

public void remove(java.lang.Object key,
                   java.lang.Object value)
Description copied from interface: Relation
Removes the relation between key and value.

Specified by:
remove in interface Relation

getValues2

protected java.util.Set getValues2(java.lang.Object key)

removeAll

public void removeAll(java.lang.Object key,
                      java.util.Collection values)
Description copied from interface: Relation
Removes the relation between key and any element from values.

Specified by:
removeAll in interface Relation

removeKey

public void removeKey(java.lang.Object key)
Description copied from interface: Relation
Removes all the relations attached to key.

Specified by:
removeKey in interface Relation

removeKeys

public void removeKeys(PredicateWrapper predicate)
Description copied from interface: Relation
Removes all the keys that satisfy predicate.check().

Specified by:
removeKeys in interface Relation

removeValues

public void removeValues(PredicateWrapper predicate)
Description copied from interface: Relation
Removes all the values that satisfy predicate.check().

Specified by:
removeValues in interface Relation

removeObjects

public void removeObjects(PredicateWrapper predicate)
Description copied from interface: Relation
Removes all the relations involving at least one object that satisfy predicate.check().

Specified by:
removeObjects in interface Relation

contains

public boolean contains(java.lang.Object key,
                        java.lang.Object value)
Description copied from interface: Relation
Checks the existence of the relation <key,value>.

Specified by:
contains in interface Relation

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from interface: Relation
Checks the existence of the key key in this relation.

Specified by:
containsKey in interface Relation

isEmpty

public boolean isEmpty()
Description copied from interface: Relation
Tests if this relation is empty or not.

Specified by:
isEmpty in interface Relation

getValues

public java.util.Set getValues(java.lang.Object key)
Description copied from interface: Relation
Returns the image of key through this relation. The returned collection is guarranted not to contain duplicates. Can return null if no value is attached to key. If the result is non-null, additions and removals on the returned collection take effect on the relation.

Specified by:
getValues in interface Relation

keys

public java.util.Set keys()
Description copied from interface: Relation
Returns all the keys appearing in this relation. The result is guaranted not to contain duplicates.

Specified by:
keys in interface Relation

values

public java.util.Set values()
Description copied from interface: Relation
Returns all the values appearing in this relation.

Specified by:
values in interface Relation

union

public void union(Relation rel)
Description copied from interface: Relation
Combines this relation with a new one. A null parameter is considered to be an empty relation.

Specified by:
union in interface Relation

equals

public boolean equals(java.lang.Object o)
Description copied from interface: Relation
Checks the equality of two relations

Specified by:
equals in interface Relation

hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


equal_sets

private boolean equal_sets(java.util.Collection c1,
                           java.util.Collection c2)

select

public Relation select(java.util.Collection selected_keys)
Description copied from interface: Relation
Returns the subrelation of this relation that contains only the keys that appear in selected_keys.

Specified by:
select in interface Relation

forAllEntries

public void forAllEntries(Relation.EntryVisitor visitor)
Description copied from interface: Relation
Visits all the entries <key,value> of this relation and calls visitor.visit on each of them.

Specified by:
forAllEntries in interface Relation

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


clone

public java.lang.Object clone()
Description copied from interface: Relation
Clones this relation.

Specified by:
clone in interface Relation