|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectFlexOr.container.DLList
public class DLList
Implementation of a sequence of objects as a doubly linked list.
Sequence| Constructor Summary | |
|---|---|
DLList()
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. |
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 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 DLList()
Class invariant
To simplify assertions we assume sequence[-1] exists for all sequences. It is
implemented by a dummy header node. Also we assume sequence[size] exists for all
sequences. It is implemented by a dummy trailer node.
header.previous = trailer.next = null length = 0 <=> current = header.next = trailer && trailer.previous = header sequence[-1] = header sequence[size] = trailer
| 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 Containerjava.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 SequenceSequenceIndexException - 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 Sequencepublic 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 Sequencepublic boolean isEmpty()
Requires: True Ensures: isEmpty = (length = 0)
isEmpty in interface Containerpublic boolean isFull()
Requires: True Ensures: isFull = false
isFull in interface Containerpublic java.lang.Object lastElement()
Requires: True
Ensures: isEmpty => result = null
~isEmpty => result = sequence[last]
lastElement in interface Sequencepublic int size()
Requires: True Ensures: result = length
size in interface Containerpublic 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 SequenceSequenceIndexException - when index is out of bounds.public void removeAll()
Requires: True Ensures: sequence = null // the empty sequence.
removeAll in interface Containerpublic java.lang.Object remove()
Requires: isEmpty = false Ensures: old sequence = obj ^ sequence
remove in interface Containerpublic 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 Sequencepublic void removeAt(int index)
Requires: 0 <= index < size
Ensures:
sequence = old sequence[first..index-1] ^ old sequence[index+1..last]
removeAt in interface SequenceSequenceIndexException - 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 SequenceSequenceIndexException - when index is out of bounds.public java.lang.Object clone()
Requires: True Ensures: result = copy of sequence
clone in interface Containerclone in class java.lang.Objectpublic java.lang.String toString()
Requires: True Ensures: result = string representation of list
toString in interface ContainertoString in class java.lang.Objectpublic boolean equals(java.lang.Object list)
Requires: True
Ensures: result = true => sequences are equal
result = false => sequences are not equal
equals in interface Containerequals in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||