|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Sequence
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.
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 |
|---|
java.lang.Object elementAt(int index)
Requires: 0 <= index < size Ensures: result = sequence[index]
SequenceIndexException - if index is out of bounds.java.lang.Object firstElement()
Requires: True
Ensures: length > 0 => result = sequence[first]
length = 0 => result = null
int indexOf(java.lang.Object obj)
Requires: True
Ensures: contains(obj) => sequence[result] = obj
not contains(obj) => result = -1
int indexOf(java.lang.Object obj,
int startIndex)
Requires: True
Ensures:
sequence[startIndex..length-1].contains(obj) => sequence[result] = obj
not sequence[startIndex..length-1].contains(obj) => result = -1
java.lang.Object lastElement()
Requires: True
Ensures: isEmpty => result = null
not isEmpty => result = sequence[last]
void insertAt(java.lang.Object obj,
int index)
Requires: 0 <= index < old size + 1
Ensures:
sequence = old sequence[first..index-1] ^ obj ^ old sequence[index..last]
SequenceIndexException - if index is out of bounds.
ContainerFullException - if container already contains MaxLength
elements for finite size sequences.boolean remove(java.lang.Object obj)
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
void removeAt(int index)
Requires: 0 <= index < size
Ensures:
sequence = old sequence[first..index-1] ^ old sequence[index+1..last]
SequenceIndexException - if index is out of bounds.
void setAt(java.lang.Object obj,
int index)
Requires: 0 <= index < size Ensures: sequence[index] = obj
SequenceIndexException - if index is out of bounds.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||