FlexOr.container
Interface Sequence

All Superinterfaces:
java.lang.Cloneable, Container
All Known Implementing Classes:
CircularArray, DLList, SLList

public interface Sequence
extends Container

This interface together with the container interface parallels the that of the java Vector class since a vector is an implementation of a sequence -- although it is not of type Sequence. In principle Vector would be defined as implementing a Sequence.

We make use of the implied mapping between items in a sequence and the nonnegative integers (0,1,2, ...) to specify a collection of methods which index the sequence.

Version:
1.0 1999 Jan 15
Author:
Gunnar Gotshalks
See Also:
Vector

Method Summary
 java.lang.Object elementAt(int index)
          Return the element at the specified index.
 java.lang.Object firstElement()
          Return the first element in the sequence.
 int indexOf(java.lang.Object obj)
          Return the index of the specified element.
 int indexOf(java.lang.Object obj, int startIndex)
          Return the index of the specified element between the start index and the end of the sequence.
 void insertAt(java.lang.Object obj, int index)
          Insert the element at the specified index.
 java.lang.Object lastElement()
          Return the last element in the sequence.
 boolean remove(java.lang.Object obj)
          If obj is found remove it from the container.
 void removeAt(int index)
          Remove the element at the specified index.
 void setAt(java.lang.Object obj, int index)
          Replace the object at the specified index.
 
Methods inherited from interface FlexOr.container.Container
add, clone, contains, elements, equals, isEmpty, isFull, remove, removeAll, size, toString
 

Method Detail

elementAt

java.lang.Object elementAt(int index)
Return the element at the specified index.

Requires: 0 <= index < size
Ensures: result = sequence[index]

Throws:
SequenceIndexException - if index is out of bounds.

firstElement

java.lang.Object firstElement()
Return the first element in the sequence.

Requires: True
Ensures: length > 0 => result = sequence[first]
                length = 0 => result = null


indexOf

int indexOf(java.lang.Object obj)
Return the index of the specified element.

Requires: True
Ensures: contains(obj) => sequence[result] = obj
            not contains(obj) => result = -1


indexOf

int indexOf(java.lang.Object obj,
            int startIndex)
Return the index of the specified element between the start index and the end of the sequence.

Requires: True
Ensures: 
       sequence[startIndex..length-1].contains(obj) => sequence[result] = obj
   not sequence[startIndex..length-1].contains(obj) => result = -1


lastElement

java.lang.Object lastElement()
Return the last element in the sequence.

Requires: True
Ensures: isEmpty => result = null
        not isEmpty => result = sequence[last]


insertAt

void insertAt(java.lang.Object obj,
              int index)
Insert the element at the specified index. We permit index to be size -- instead of size - 1 -- to specify adding at the end of the list.

Requires: 0 <= index < old size + 1
Ensures:
    sequence = old sequence[first..index-1] ^ obj ^ old sequence[index..last]

Throws:
SequenceIndexException - if index is out of bounds.
ContainerFullException - if container already contains MaxLength elements for finite size sequences.

remove

boolean remove(java.lang.Object obj)
If obj is found remove it from the container.

Requires: True
Ensures:
    old sequence.contains(obj) => sequence = old sequence / obj and result = true 
not old sequence.contains(obj) => sequence = old sequence and result = false


removeAt

void removeAt(int index)
Remove the element at the specified index.

Requires: 0 <= index < size
Ensures:
    sequence = old sequence[first..index-1] ^ old sequence[index+1..last]

Throws:
SequenceIndexException - if index is out of bounds.

setAt

void setAt(java.lang.Object obj,
           int index)
Replace the object at the specified index.
Requires: 0 <= index < size
Ensures: sequence[index] = obj

Throws:
SequenceIndexException - if index is out of bounds.