soot.util
Class HashChain<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by soot.util.HashChain<E>
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, Chain<E>
Direct Known Subclasses:
IterableSet, PegChain

public class HashChain<E>
extends AbstractCollection<E>
implements Chain<E>

Reference implementation of the Chain interface, using a HashMap as the underlying structure.

See Also:
Serialized Form

Constructor Summary
HashChain()
          Constructs an empty HashChain.
HashChain(Chain<E> src)
          Constructs a HashChain filled with the contents of the src Chain.
 
Method Summary
 boolean add(E item)
          Adds the given object to this HashChain.
 void addFirst(E item)
          Adds the given object at the beginning of the Chain.
 void addLast(E item)
          Adds the given object at the end of the Chain.
 void clear()
          Erases the contents of the current HashChain.
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 boolean follows(E someObject, E someReferenceObject)
          Returns true if object someObject follows object someReferenceObject in the Chain.
 E getFirst()
          Returns the first object in this Chain.
 E getLast()
          Returns the last object in this Chain.
 E getPredOf(E point)
          Returns the object immediately preceding point.
 E getSuccOf(E point)
          Returns the object immediately following point.
 void insertAfter(Chain<E> toInsert, E point)
          Inserts toInsert in the Chain after point.
 void insertAfter(E toInsert, E point)
          Inserts toInsert in the Chain after point.
 void insertAfter(List<E> toInsert, E point)
          Inserts toInsert in the Chain after point.
 void insertBefore(Chain<E> toInsert, E point)
          Inserts toInsert in the Chain before point.
 void insertBefore(E toInsert, E point)
          Inserts toInsert in the Chain before point.
 void insertBefore(List<E> toInsert, E point)
          Inserts toInsert in the Chain before point.
 Iterator<E> iterator()
          Returns an iterator over this Chain.
 Iterator<E> iterator(E item)
          Returns an iterator over this Chain, starting at the given object.
 Iterator<E> iterator(E head, E tail)
          Returns an iterator ranging from head to tail, inclusive.
static HashChain listToHashChain(List list)
           
 boolean remove(Object item)
          Removes the given object from this Chain.
 void removeFirst()
          Removes the first object contained in this Chain.
 void removeLast()
          Removes the last object contained in this Chain.
 int size()
          Returns the size of this Chain.
 Iterator<E> snapshotIterator()
          Returns an iterator over a copy of this chain.
 Iterator<E> snapshotIterator(Object item)
           
 void swapWith(E out, E in)
          Replaces out in the Chain by in.
static List toList(Chain c)
          Returns an unbacked list containing the contents of the given Chain.
 String toString()
          Returns a textual representation of the contents of this Chain.
 
Methods inherited from class java.util.AbstractCollection
addAll, isEmpty, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

HashChain

public HashChain()
Constructs an empty HashChain.


HashChain

public HashChain(Chain<E> src)
Constructs a HashChain filled with the contents of the src Chain.

Method Detail

clear

public void clear()
Erases the contents of the current HashChain.

Specified by:
clear in interface Collection<E>
Overrides:
clear in class AbstractCollection<E>

swapWith

public void swapWith(E out,
                     E in)
Description copied from interface: Chain
Replaces out in the Chain by in.

Specified by:
swapWith in interface Chain<E>

add

public boolean add(E item)
Adds the given object to this HashChain.

Specified by:
add in interface Collection<E>
Overrides:
add in class AbstractCollection<E>

toList

public static List toList(Chain c)
Returns an unbacked list containing the contents of the given Chain.


follows

public boolean follows(E someObject,
                       E someReferenceObject)
Description copied from interface: Chain
Returns true if object someObject follows object someReferenceObject in the Chain.

Specified by:
follows in interface Chain<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Overrides:
contains in class AbstractCollection<E>

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection<E>
Overrides:
containsAll in class AbstractCollection<E>

insertAfter

public void insertAfter(E toInsert,
                        E point)
Description copied from interface: Chain
Inserts toInsert in the Chain after point.

Specified by:
insertAfter in interface Chain<E>

insertAfter

public void insertAfter(List<E> toInsert,
                        E point)
Description copied from interface: Chain
Inserts toInsert in the Chain after point.

Specified by:
insertAfter in interface Chain<E>

insertAfter

public void insertAfter(Chain<E> toInsert,
                        E point)
Description copied from interface: Chain
Inserts toInsert in the Chain after point. (It would probably be better to make Chain implement List)

Specified by:
insertAfter in interface Chain<E>

insertBefore

public void insertBefore(E toInsert,
                         E point)
Description copied from interface: Chain
Inserts toInsert in the Chain before point.

Specified by:
insertBefore in interface Chain<E>

insertBefore

public void insertBefore(List<E> toInsert,
                         E point)
Description copied from interface: Chain
Inserts toInsert in the Chain before point.

Specified by:
insertBefore in interface Chain<E>

insertBefore

public void insertBefore(Chain<E> toInsert,
                         E point)
Description copied from interface: Chain
Inserts toInsert in the Chain before point. (It would probably be better to make Chain implement List)

Specified by:
insertBefore in interface Chain<E>

listToHashChain

public static HashChain listToHashChain(List list)

remove

public boolean remove(Object item)
Description copied from interface: Chain
Removes the given object from this Chain. Parameter has to be of type Object to be compatible with the Collection interface.

Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Chain<E>
Overrides:
remove in class AbstractCollection<E>

addFirst

public void addFirst(E item)
Description copied from interface: Chain
Adds the given object at the beginning of the Chain.

Specified by:
addFirst in interface Chain<E>

addLast

public void addLast(E item)
Description copied from interface: Chain
Adds the given object at the end of the Chain.

Specified by:
addLast in interface Chain<E>

removeFirst

public void removeFirst()
Description copied from interface: Chain
Removes the first object contained in this Chain.

Specified by:
removeFirst in interface Chain<E>

removeLast

public void removeLast()
Description copied from interface: Chain
Removes the last object contained in this Chain.

Specified by:
removeLast in interface Chain<E>

getFirst

public E getFirst()
Description copied from interface: Chain
Returns the first object in this Chain.

Specified by:
getFirst in interface Chain<E>

getLast

public E getLast()
Description copied from interface: Chain
Returns the last object in this Chain.

Specified by:
getLast in interface Chain<E>

getSuccOf

public E getSuccOf(E point)
            throws NoSuchElementException
Description copied from interface: Chain
Returns the object immediately following point.

Specified by:
getSuccOf in interface Chain<E>
Throws:
NoSuchElementException

getPredOf

public E getPredOf(E point)
            throws NoSuchElementException
Description copied from interface: Chain
Returns the object immediately preceding point.

Specified by:
getPredOf in interface Chain<E>
Throws:
NoSuchElementException

snapshotIterator

public Iterator<E> snapshotIterator()
Description copied from interface: Chain
Returns an iterator over a copy of this chain. This avoids ConcurrentModificationExceptions from being thrown if the underlying Chain is modified during iteration. Do not use this to remove elements which have not yet been iterated over!

Specified by:
snapshotIterator in interface Chain<E>

snapshotIterator

public Iterator<E> snapshotIterator(Object item)

iterator

public Iterator<E> iterator()
Description copied from interface: Chain
Returns an iterator over this Chain.

Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Chain<E>
Specified by:
iterator in class AbstractCollection<E>

iterator

public Iterator<E> iterator(E item)
Description copied from interface: Chain
Returns an iterator over this Chain, starting at the given object.

Specified by:
iterator in interface Chain<E>

iterator

public Iterator<E> iterator(E head,
                            E tail)

Returns an iterator ranging from head to tail, inclusive.

If tail is the element immediately preceding head in this HashChain, the returned iterator will iterate 0 times (a special case to allow the specification of an empty range of elements). Otherwise if tail is not one of the elements following head, the returned iterator will iterate past the end of the HashChain, provoking a NoSuchElementException.

Specified by:
iterator in interface Chain<E>
Throws:
NoSuchElementException - if head is not an element of the chain.

size

public int size()
Description copied from interface: Chain
Returns the size of this Chain.

Specified by:
size in interface Collection<E>
Specified by:
size in interface Chain<E>
Specified by:
size in class AbstractCollection<E>

toString

public String toString()
Returns a textual representation of the contents of this Chain.

Overrides:
toString in class AbstractCollection<E>