|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectFlexOr.container.CircularArray
public class CircularArray
Implementation of a sequence of objects as a circular array.
Sequence| Constructor Summary | |
|---|---|
CircularArray(int capacity)
Establish the class invariant on an empty sequence. |
|
| Method Summary | |
|---|---|
void |
add(java.lang.Object obj)
Adds obj after the last element of the sequence. |
void |
addWait(java.lang.Object obj)
Adds obj after the last element of the sequence; if full,
the thread waits until space is available. |
int |
capacity()
Returns the maximum number of elements that can be stored. |
java.lang.Object |
clone()
Return a copy of the sequence that points to the same objects as in the original sequence. |
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 seq)
Check for equality of contents of two sequences. |
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. |
boolean |
isEmpty()
Returns true if the sequence is empty. |
boolean |
isFull()
Returns true if the sequence is 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 sequence. |
void |
removeAt(int index)
Remove the element at the specified index. |
java.lang.Object |
removeWait()
Remove the first element in the sequence; if the queue is empty, the thread waits for a notify. |
void |
setAt(java.lang.Object obj,
int index)
Replace the object at the specified index. |
int |
size()
Return the number of elements in the sequence. |
java.lang.String |
toString()
Return a string representation of the contents of the sequence. |
| Methods inherited from class java.lang.Object |
|---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public CircularArray(int capacity)
Class invariant
isEmpty => length = 0 && (last-1) mod Capacity = first not isFull => length = (Capacity + head - last + 1) mod Capacity
capacity - Create a CircularArray of the specified capacity.
TooSmallException - if caller requests a capacity < 2| 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) => sequence[result] = obj
not contains(obj) => result = -1
indexOf in interface Sequence
public 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
indexOf in interface Sequencepublic boolean isEmpty()
Requires: True Ensures: isEmpty = (length = 0)
isEmpty in interface Containerpublic boolean isFull()
Requires: True Ensures: isFull = (length = Capacity)
isFull in interface Containerpublic java.lang.Object lastElement()
Requires: True
Ensures: isEmpty => result = null
not isEmpty => result = sequence[last]
lastElement in interface Sequencepublic int size()
Requires: True Ensures: result = length
size in interface Containerpublic int capacity()
public void add(java.lang.Object obj)
obj after the last element of the sequence.
Requires: True Ensures: sequence = old sequence ^ obj
add in interface ContainerContainerFullException - when container already holds Capacity
elements.public void addWait(java.lang.Object obj)
obj after the last element of the sequence; if full,
the thread waits until space is available.
Requires: True Ensures: sequence = old sequence ^ obj
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.
ContainerFullException - when container already contains Capacity
elements.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 ContainerContainerEmptyException - when removing from an empty sequence.public java.lang.Object removeWait()
Requires: isEmpty = false Ensures: old sequence = obj ^ sequence
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 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] = 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 contents
toString in interface ContainertoString in class java.lang.Objectpublic boolean equals(java.lang.Object seq)
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 | |||||||||