org.zedlib
Class HashFun

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byjava.util.HashSet
              extended byorg.zedlib.HashSet
                  extended byorg.zedlib.HashRel
                      extended byorg.zedlib.HashFun
All Implemented Interfaces:
Cloneable, Collection, Function, Relation, Serializable, Set, Set
Direct Known Subclasses:
HashBag, HashSeq

public class HashFun
extends HashRel
implements Function

This class provides similar functionality to java.util.Map, however, it is properly descended from a Set (org.zedlib.Set, hence implements the java.util.Set interface). It does not implement the java.util.Map interface because of conflicts between the java.util.Map and java.util.Set interfaces. If X and Y are sets, X → Y is the set of partial functions from X to Y. These are relations which relate each member x of X to at most one member of Y.

Author:
Brad Long
See Also:
Serialized Form

Constructor Summary
HashFun()
           
HashFun(Collection c)
          Constructs a function containing all elements in the supplied collection of maplets.
HashFun(Collection c1, Collection c2)
          Constructs a function between two collections.
HashFun(Function f)
          Constructs a function from a given function.
HashFun(Map m)
          Constructs a function from a given java.util.Map.
 
Method Summary
 boolean add(Maplet m)
          Adds a maplet to this function.
 boolean containsKey(Object key)
          An alternative for domain().contains(key).
 boolean containsValue(Object value)
          An alternative for range().contains(value).
protected  Set getInstance()
           
protected  Set getInstance(Set s)
           
 Maplet getMaplet(Object key)
          Returns the maplet that a given key participates in.
 Object getValue(Object key)
          Returns the value that a given key maps to.
 Object put(Maplet m)
          Adds a maplet to this function.
 Object put(Object x, Object y)
          Adds two objects representing a maplet to this function.
 
Methods inherited from class org.zedlib.HashRel
add, add, addAll, addAll, buildRelation, composition, domain, domainAntiRestriction, domainRestriction, image, inverse, isFunction, isInjection, isReflexive, override, range, rangeAntiRestriction, rangeRestriction, toString, transitiveClosure
 
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.Relation
add, addAll, composition, domain, domainAntiRestriction, domainRestriction, image, inverse, isFunction, isInjection, isReflexive, override, range, rangeAntiRestriction, rangeRestriction, transitiveClosure
 
Methods inherited from interface org.zedlib.Set
cartesianProduct, difference, identity, intersection, isSubsetOf, isSupersetOf, union
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

HashFun

public HashFun()

HashFun

public HashFun(Collection c1,
               Collection c2)
Constructs a function between two collections. Each maplet is created by traversing the iterators of each collection and associating each element of c1 with an element from c2. Duplicate elements in c1 are ignored, therefore requiring the number of unique elements in c1 to equal the number of elements in c2. This provides the same logical abstraction as java.util.Map but is properly contained in the collections hierarchy.

Parameters:
c1 - any collection
c2 - any collection
Throws:
IllegalArgumentException - if the collections do not contain the same number of unique elements

HashFun

public HashFun(Collection c)
Constructs a function containing all elements in the supplied collection of maplets.

Throws:
ClassCastException - if the collection does not contain maplets

HashFun

public HashFun(Map m)
Constructs a function from a given java.util.Map.


HashFun

public HashFun(Function f)
Constructs a function from a given function.

Method Detail

getInstance

protected Set getInstance()
Overrides:
getInstance in class HashRel

getInstance

protected Set getInstance(Set s)
Overrides:
getInstance in class HashRel

add

public boolean add(Maplet m)
Adds a maplet to this function. Existing maplets with the same x in (x,y) are overwritten with the given maplet.

Specified by:
add in interface Relation
Overrides:
add in class HashRel
Parameters:
m - the maplet to add to the function
Returns:
true if the maplet was added to this function

put

public Object put(Object x,
                  Object y)
Adds two objects representing a maplet to this function. Existing maplets with the same x in (x,y) are overwritten with the given maplet.

Parameters:
x - the key to add to the function; x in the maplet (x,y)
y - the value to add to the function; y in the maplet (x,y)
Returns:
the object, y in (x,y), that was replaced or null if there was no maplet having a key of x in the function.

put

public Object put(Maplet m)
Adds a maplet to this function. Existing maplets with the same x in (x,y) are overwritten with the given maplet.

Specified by:
put in interface Function
Parameters:
m - the maplet to add to the function
Returns:
the object, y in (x,y), that was replaced or null if there was no maplet having a key of x in the function.

getValue

public Object getValue(Object key)
Returns the value that a given key maps to.

Parameters:
key - the key (x) with which to obtain its corresponding (y) value
Returns:
the object that the given key maps to

getMaplet

public Maplet getMaplet(Object key)
Returns the maplet that a given key participates in.

Specified by:
getMaplet in interface Function
Parameters:
key - the key (x) with which to obtain its corresponding (y) value
Returns:
the maplet that the given key participates in

containsValue

public boolean containsValue(Object value)
An alternative for range().contains(value).

Specified by:
containsValue in interface Function
Parameters:
value - the object to check for existence in the range of this function
Returns:
true if a given value, y, is contained in the range of this function

containsKey

public boolean containsKey(Object key)
An alternative for domain().contains(key).

Specified by:
containsKey in interface Function
Parameters:
key - the object to check for existence in the domain of this function
Returns:
true if a given value, x, is contained in the domain of this function


Copyright © 2006 Brad Long. All Rights Reserved.