org.zedlib
Class HashSeq

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
                          extended byorg.zedlib.HashSeq
All Implemented Interfaces:
Cloneable, Collection, Function, List, Relation, Sequence, Serializable, Set, Set

public class HashSeq
extends HashFun
implements Sequence, List

A sequence is a type of function that maps an integer (usually representing an ordering) to an object.

Example: S = { (1,fred), (2,tom), (3,mary) } is a valid sequence.

Author:
Brad Long
See Also:
Serialized Form

Constructor Summary
HashSeq()
           
HashSeq(Collection c)
          Constructs a sequence by iterating over a given collection.
HashSeq(Sequence s)
          Construct a sequence from an existing sequence.
 
Method Summary
 void add(int index, Object y)
          Adds an (integer, object) pair representing a maplet to this function.
 boolean add(Maplet m)
          Adds a maplet to this sequence.
 boolean add(Object y)
          Adds an object to the end of this sequence.
 void add(Seqlet m)
          Adds a seqlet to this sequence.
 boolean addAll(int index, Collection c)
           
 boolean containsKey(int key)
          A convenience function for the alternative domain().contains(new Integer(key)).
 Sequence front()
          Returns a sequence being all but the last element in the sequence.
 Object get(int key)
          Returns the value that a given key maps to.
protected  Set getInstance()
           
protected  Set getInstance(Set s)
           
 Seqlet getSeqlet(int key)
          Returns the maplet that a given key participates in.
 Object head()
          Returns the first element in the sequence.
 int indexOf(Object o)
          Searches for the first occurence of the given argument, testing for equality using the equals method.
 Object last()
          Returns the last element in the sequence.
 int lastIndexOf(Object o)
          Returns the index of the last occurrence of the specified object in this list.
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
 Object put(Maplet m)
          Replaces a maplet in this sequence.
 Object remove(int key)
          Removes the maplet with the given key from this function.
 Object set(int index, Object y)
          Adds an (integer, object) pair representing a maplet to this function.
 List subList(int fromIndex, int toIndex)
           
 Sequence tail()
          Returns a sequence being all but the first element in the sequence.
 
Methods inherited from class org.zedlib.HashFun
containsKey, containsValue, getMaplet, getValue, put
 
Methods inherited from class org.zedlib.HashRel
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.Function
containsKey, containsValue, getMaplet
 
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
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.List
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

HashSeq

public HashSeq()

HashSeq

public HashSeq(Collection c)
Constructs a sequence by iterating over a given collection.


HashSeq

public HashSeq(Sequence s)
Construct a sequence from an existing sequence.

Method Detail

getInstance

protected Set getInstance()
Overrides:
getInstance in class HashFun

getInstance

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

head

public Object head()
Returns the first element in the sequence.

Specified by:
head in interface Sequence

tail

public Sequence tail()
Returns a sequence being all but the first element in the sequence.

Specified by:
tail in interface Sequence

last

public Object last()
Returns the last element in the sequence.

Specified by:
last in interface Sequence

front

public Sequence front()
Returns a sequence being all but the last element in the sequence.

Specified by:
front in interface Sequence

get

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

Specified by:
get in interface List
Parameters:
key - the key with which to obtain its corresponding value
Returns:
the object that the given key maps to

getSeqlet

public Seqlet getSeqlet(int key)
Returns the maplet that a given key participates in.

Specified by:
getSeqlet in interface Sequence
Parameters:
key - the key with which to obtain its corresponding value
Returns:
the maplet that the given key participates in or null

containsKey

public boolean containsKey(int key)
Description copied from interface: Sequence
A convenience function for the alternative domain().contains(new Integer(key)).

Specified by:
containsKey in interface Sequence
Parameters:
key - the key to check
Returns:
true if the key is contained in the domain of this function
See Also:
Relation.domain()

add

public void add(Seqlet m)
Adds a seqlet to this sequence. Existing maplets with the same x in (x,y) are pushed after the given maplet.

Specified by:
add in interface Sequence
Parameters:
m - the seqlet to add to this sequence
Returns:
true if the object was added to this sequence
Throws:
ClassCastException - if the key of the maplet is not an Integer
See Also:
Set.add(Object o)

add

public boolean add(Maplet m)
Adds a maplet to this sequence.

Specified by:
add in interface Relation
Overrides:
add in class HashFun
Parameters:
m - the maplet to add to the function
Returns:
true if the object was added to this sequence
Throws:
ClassCastException - if the key of the maplet is not an Integer

remove

public Object remove(int key)
Removes the maplet with the given key from this function.

Specified by:
remove in interface List
Parameters:
key - the key that identifies the maplet to remove
Returns:
the object that was removed or null
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

add

public void add(int index,
                Object y)
Adds an (integer, object) pair representing a maplet to this function. Existing maplets with the same x in (x,y) are pushed after the given maplet.

Specified by:
add in interface List
Parameters:
index - the position to add the object
y - the object to add; y in the seqlet (x,y)

add

public boolean add(Object y)
Adds an object to the end of this sequence.

Specified by:
add in interface Set
Overrides:
add in class HashRel
Parameters:
y - the object to add to the sequence
Returns:
true if the object was added

set

public Object set(int index,
                  Object y)
Adds an (integer, object) pair representing a maplet to this function. Existing maplets with the same x in (x,y) are overwritten with the given maplet.

Specified by:
set in interface List
Parameters:
index - the position to add the object; x in the maplet (x,y)
y - the object to add; 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 this function

put

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

Specified by:
put in interface Function
Overrides:
put in class HashFun
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.

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List

listIterator

public ListIterator listIterator(int index)
Specified by:
listIterator in interface List

subList

public List subList(int fromIndex,
                    int toIndex)
Specified by:
subList in interface List

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List

indexOf

public int indexOf(Object o)
Searches for the first occurence of the given argument, testing for equality using the equals method.

Specified by:
indexOf in interface List
See Also:
List.indexOf(java.lang.Object)

lastIndexOf

public int lastIndexOf(Object o)
Returns the index of the last occurrence of the specified object in this list.

Specified by:
lastIndexOf in interface List
See Also:
List.lastIndexOf(java.lang.Object)


Copyright © 2006 Brad Long. All Rights Reserved.