|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectFlexOr.container.SLList
public class SLList
Implementation of a sequence of objects as a singly linked list.
Sequence
Constructor Summary | |
---|---|
SLList()
Establish the class invariant on an empty list. |
Method Summary | |
---|---|
void |
add(java.lang.Object obj)
Adds obj after the last element of the list. |
java.lang.Object |
clone()
Return a copy of the list with new nodes that point to the same objects as in the original list. |
boolean |
contains(java.lang.Object obj)
Determines whether an element is in the sequence[first..last]. |
boolean |
contains(java.lang.Object obj,
int startIndex)
Determines whether an element is in sequence[startIndex..last]. |
java.lang.Object |
elementAt(int index)
Return the element at the specified index. |
java.util.Enumeration<java.lang.Object> |
elements()
Returns an enumerator from the current position. |
boolean |
equals(java.lang.Object list)
Check for equality of contents of two lists. |
java.lang.Object |
firstElement()
Return the first element in the list. |
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. |
void |
insertAt(SLList list,
int index)
Insert the argument list at the specified index. |
boolean |
isEmpty()
Returns true if the list is empty. |
boolean |
isFull()
Returns false as a list can never become full. |
java.lang.Object |
lastElement()
Return the last element in the list. |
java.lang.Object |
remove()
Remove and return the first element in the sequence. |
boolean |
remove(java.lang.Object obj)
If obj is found remove it from the container. |
void |
removeAll()
Empty 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. |
int |
size()
Return the number of elements in the list. |
java.lang.String |
toString()
Return a string representation of the contents of the list. |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SLList()
Class invariant
To simplify assertions we assume sequence[-1] exists for all sequences. It is
implemented by the dummy headerNode. First always points to the headerNode.
length = 0 <=> header = last = current length ~= 0 => current ~= header sequence[-1] = header
Method Detail |
---|
public boolean contains(java.lang.Object obj)
Requires: True Ensures: contains(obj) => result = true not contains(obj) => result = false
contains
in interface Container
public boolean contains(java.lang.Object obj, int startIndex)
Requires: True Ensures: sequence[startIndex..length-1].contains(obj) => result = true not sequence[startIndex..length-1].contains(obj) => result = false
public java.util.Enumeration<java.lang.Object> elements()
Requires: True Ensures: enumeration over the elements first to last.
elements
in interface Container
java.util.NoSuchElementException
- when nextElement is called with an empty
enumeration sequence.public java.lang.Object elementAt(int index)
Requires: 0 <= index < size Ensures: result = sequence[index]
elementAt
in interface Sequence
SequenceIndexException
- when index is out of bounds.public java.lang.Object firstElement()
Requires: True Ensures: length > 0 => result = sequence[first] length = 0 => result = null
firstElement
in interface Sequence
public int indexOf(java.lang.Object obj)
Requires: True Ensures: contains(obj) => obj = sequence[result] not contains(obj) => result = -1
indexOf
in interface Sequence
public int indexOf(java.lang.Object obj, int startIndex)
Requires: True Ensures: sequence[startIndex..size-1].contains(obj) => obj = sequence[result] not sequence[startIndex..size-1].contains(obj) => result = -1
indexOf
in interface Sequence
public boolean isEmpty()
Requires: True Ensures: isEmpty = (length = 0)
isEmpty
in interface Container
public boolean isFull()
Requires: True Ensures: isFull = false
isFull
in interface Container
public java.lang.Object lastElement()
Requires: True Ensures: isEmpty => result = null ~isEmpty => result = sequence[last]
lastElement
in interface Sequence
public int size()
Requires: True Ensures: result = length
size
in interface Container
public void add(java.lang.Object obj)
obj
after the last element of the list.
Requires: True Ensures: sequence = old sequence ^ obj
add
in interface Container
public 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]
insertAt
in interface Sequence
SequenceIndexException
- when index is out of bounds.public void removeAll()
Requires: True Ensures: sequence = null // the empty sequence.
removeAll
in interface Container
public java.lang.Object remove()
Requires: isEmpty = true or false Ensures: old sequence = obj ^ sequence
remove
in interface Container
public 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
remove
in interface Sequence
public void removeAt(int index)
Requires: 0 <= index < size Ensures: sequence = old sequence[first..index-1] ^ old sequence[index+1..last]
removeAt
in interface Sequence
SequenceIndexException
- when index is out of bounds.public void setAt(java.lang.Object obj, int index)
Requires: 0 <= index < size Ensures: sequence[index].datum = obj
setAt
in interface Sequence
SequenceIndexException
- when index is out of bounds.public java.lang.Object clone()
Requires: True Ensures: result = copy of list
clone
in interface Container
clone
in class java.lang.Object
public java.lang.String toString()
Requires: True Ensures: result = string representation of list
toString
in interface Container
toString
in class java.lang.Object
public boolean equals(java.lang.Object list)
Requires: True Ensures: result = true => sequences are equal result = false => sequences are not equal
equals
in interface Container
equals
in class java.lang.Object
public void insertAt(SLList list, int index)
Requires: 0 <= index < old size + 1 Ensures: sequence = old sequence[first..index-1] ^ clone(newSequence[first..last]) ^ old sequence[index..last]
SequenceIndexException
- when index is out of bounds.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |