edu.toronto.cs.util
Class ArrayMarkedList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList
              extended by edu.toronto.cs.util.ArrayMarkedList
All Implemented Interfaces:
MarkedList, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

public class ArrayMarkedList
extends java.util.ArrayList
implements MarkedList

ArrayMarkedList is a extention of List that allows to mark a position in the list and later go back to it. This is done by creating a collection that stores the sizes of the undelying list after each mark. When restore is called, elements are removed from the list untill it's size is equal to that at the time of last mark.

Version:
1.0
Author:
Anton Selyshchev
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ArrayMarkedList()
          Creates a new ArrayMarkedList instance.
ArrayMarkedList(java.util.Collection c)
          Creates a new ArrayMarkedList instance given an initial list.
 
Method Summary
 void add(int index, java.lang.Object o)
          Inserts the specified element at the specified position in this list This operation is not supported
 boolean addAll(int index, java.util.Collection c)
          Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
 java.lang.Object get(int index)
          Returns the element at the specified position in this list.
 int getNumMarks()
          Returns the number of mark calls up to this point.
static void main(java.lang.String[] args)
           
 void mark()
          Records the current number of assertions.
 java.lang.Object remove(int index)
          Removes the element at the specified position in this list.
 boolean remove(java.lang.Object o)
          This operation is not supported
 boolean removeAll(java.util.Collection c)
          This operation is not supported
 void restore()
          removes all the marks done after the last mark.
 void restore(int level)
          if markNumber is the last mark, works like restore () otherwise removes all the asserts done after mark (markNumber +1) together with the mark number (markNumber + 1)
 boolean retainAll(java.util.Collection c)
          This operation is not supported
 java.lang.Object set(int index, java.lang.Object element)
          This operation is not supported
 java.lang.String toString()
          Prints the list plus the number of marks.
 
Methods inherited from class java.util.ArrayList
add, addAll, clear, clone, contains, ensureCapacity, indexOf, isEmpty, lastIndexOf, removeRange, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, size, subList, toArray, toArray
 

Constructor Detail

ArrayMarkedList

public ArrayMarkedList()
Creates a new ArrayMarkedList instance.


ArrayMarkedList

public ArrayMarkedList(java.util.Collection c)
Creates a new ArrayMarkedList instance given an initial list.

Method Detail

toString

public java.lang.String toString()
Prints the list plus the number of marks.

Overrides:
toString in class java.util.AbstractCollection

getNumMarks

public int getNumMarks()
Returns the number of mark calls up to this point.


mark

public void mark()
Records the current number of assertions. Restore can be used to go back to this number.

Specified by:
mark in interface MarkedList

restore

public void restore()
removes all the marks done after the last mark. Also removes the last mark.

Specified by:
restore in interface MarkedList

restore

public void restore(int level)
if markNumber is the last mark, works like restore () otherwise removes all the asserts done after mark (markNumber +1) together with the mark number (markNumber + 1)

Specified by:
restore in interface MarkedList
Parameters:
level - level on which to restore

add

public void add(int index,
                java.lang.Object o)
Inserts the specified element at the specified position in this list This operation is not supported

Specified by:
add in interface java.util.List
Overrides:
add in class java.util.ArrayList
Parameters:
index - position to insert a new member at
o - an Object to be inserted

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation). This operation is not supported

Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.ArrayList
Parameters:
index - an int a position where to add
c - a Collection to add
Returns:
if the addition was successful.

get

public java.lang.Object get(int index)
Returns the element at the specified position in this list.

Specified by:
get in interface java.util.List
Overrides:
get in class java.util.ArrayList

remove

public java.lang.Object remove(int index)
Removes the element at the specified position in this list. This operation is not supported. Mark and restore should be used instead.

Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.ArrayList
Parameters:
index - an int value
Returns:
an Object value

remove

public boolean remove(java.lang.Object o)
This operation is not supported

Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.ArrayList

removeAll

public boolean removeAll(java.util.Collection c)
This operation is not supported

Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List
Overrides:
removeAll in class java.util.AbstractCollection

retainAll

public boolean retainAll(java.util.Collection c)
This operation is not supported

Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List
Overrides:
retainAll in class java.util.AbstractCollection

set

public java.lang.Object set(int index,
                            java.lang.Object element)
This operation is not supported

Specified by:
set in interface java.util.List
Overrides:
set in class java.util.ArrayList

main

public static void main(java.lang.String[] args)