SimpleList Class Diagram

 

 

Ancestor class specifications:

java.lang.Object
java.util.Iterator
java.util.Collection
java.util.AbstractCollection


SimpleList Class Specification

            Invariant

                        A SimpleList object...

-       is a container of zero or more objects arranged in a linear order.

-       maintains an iterator that is positioned either in front of the first item, beyond the last item, or between two consecutive list items.  (The iterator can be thought of as an integer that counts the number of items preceding its position.)

-       maintains an isRemovable Boolean value to tell when a call to remove is allowed

 

            Constructor Method

public SimpleList<ItemType> ( )

      post:  this is empty (i.e. size() == 0)

   and  iterator position == 0  (i.e. the iterator has zero items before it)

   and  isRemovable == false

 

            Update Methods

public boolean add ( ItemType z)

      post:  this == this@pre with z inserted at the iterator@pre position

   and   size() = size()@pre + 1

   and  iterator == iterator@pre + 1

   and  isRemovable == false

note:  The add method returns a boolean value to be consistent with inheritance constrains.  However, in practice we shall treat this as a void method.

 

public void remove ()

      pre:   isRemovable

      post:  this == this@pre with the item preceding iterator@pre removed

               and  size() == size()@pre - 1

               and  iterator == iterator@pre - 1

               and  isRemovable == false

 

public void reset ()

      post:  iterator == 0  (i.e. the iterator has zero items before it)

   and  isRemovable == false

 

Query Methods

public boolean hasNext( )

      post:  result == ( iterator == size() )   (i.e. result is false exactly when iterator is

                                                            positioned at the rear of this list)

public ItemType next ()

      pre:   hasNext()

      post:  iterator == iterator@pre + 1

               and  result == the item immediately preceding iterator

               and  isRemovable == true

 

public int size ()

      post:  result == the number of items in this list