public class IntLinkedSeq
extends java.lang.Object
implements java.lang.Cloneable
IntLinkedSeq
is a collection of int
numbers.
The sequence can have a special "current element," which is specified and
accessed through four methods (start, getCurrent, advance, and isCurrent).
size
method
does not work.
Constructor and Description |
---|
IntLinkedSeq()
Initialize an empty sequence.
|
Modifier and Type | Method and Description |
---|---|
void |
addAfter(int element)
Add a new element to this sequence, after the current element.
|
void |
addAll(IntLinkedSeq addend)
Place the contents of another sequence at the end of this sequence.
|
void |
addBefore(int element)
Add a new element to this sequence, before the current element.
|
void |
addFirst(int element)
Add a new element to the beginning of this sequence.
|
void |
addLast(int element)
Add a new element to the end of this sequence.
|
void |
advance()
Move forward, so that the current element is now the next element
in this sequence.
|
IntLinkedSeq |
catenation(IntLinkedSeq s2)
Create a new sequence that contains all the elements from
this sequence followed by another sequence.
|
java.lang.Object |
clone()
Generate a copy of this sequence.
|
boolean |
contains(int target)
Method to determine if a particular element
is in this sequence.
|
int |
getCurrentValue()
Accessor method to get the value in the current element of this sequence.
|
int |
indexOf(int target)
Returns the index of the first occurrence of the specified element in
this sequence, or -1 if this sequence does not contain the element.
|
void |
invalidateCurrent()
Set the state of this sequence so that it does not have a current element.
|
boolean |
isCurrent()
Accessor method to determine whether this sequence has a specified
current element that can be retrieved with the getCurrent() method.
|
void |
removeCurrent()
Remove the current element from this sequence.
|
void |
removeFirst()
Remove the element at the beginning of this sequence.
|
void |
removeLast()
Remove the element at the end of this sequence.
|
IntLinkedSeq |
reverse()
Create a new sequence that contains all the elements from
this sequence in the reverse order.
|
void |
setCurrent(int i)
Set the current element to be the i'th element of this sequence
(starting with the 0'th element at the head).
|
void |
setCurrentValue(int element)
Mutator method to set the value in the current element of this sequence.
|
int |
size()
Determine the number of elements in this sequence.
|
void |
start()
Set the current element at the front of this sequence.
|
IntLinkedSeq |
subSeq(int fromIndex,
int toIndex)
Create a new sequence that contains all the elements from
this sequence that are between the indices fromIndex, inclusive,
and toIndex, exclusive.
|
int[] |
toArray()
Returns an array containing all of the elements in this sequence.
|
java.lang.String |
toString()
Returns a String containing a representation of all the elements
in this sequence.
|
public IntLinkedSeq()
none
- public void addAfter(int element)
element
- the new element that is being addedjava.lang.OutOfMemoryError
- Indicates insufficient memory for a new node.public void addBefore(int element)
element
- the new element that is being addedjava.lang.OutOfMemoryError
- Indicates insufficient memory for a new node.public void addAll(IntLinkedSeq addend)
addend
- a sequence whose contents will be placed at the end of this sequencejava.lang.NullPointerException
- Indicates that addend is null.java.lang.OutOfMemoryError
- Indicates insufficient memory to increase the size of this sequence.public void addFirst(int element)
element
- the new element that is being addedjava.lang.OutOfMemoryError
- Indicates insufficient memory for a new node.public void addLast(int element)
element
- the new element that is being addedjava.lang.OutOfMemoryError
- Indicates insufficient memory for a new node.public void start()
none
- public boolean isCurrent()
none
- public int getCurrentValue()
none
- java.lang.IllegalStateException
- Indicates that there is no current element,
so getCurrentValue() may not be called.public void setCurrentValue(int element)
element
- the new value that is to be placed in the current elementjava.lang.IllegalStateException
- Indicates that there is no current element,
so setCurrentValue() may not be called.public void removeCurrent()
none
- java.lang.IllegalStateException
- Indicates that there is no current element,
so removeCurrent() may not be called.public void removeFirst()
none
- java.lang.IllegalStateException
- Indicates that the sequence is empty,
so removeFirst() may not be called.public void removeLast()
none
- java.lang.IllegalStateException
- Indicates that the sequence is empty,
so removeLast() may not be called.public void advance()
none
- java.lang.IllegalStateException
- Indicates that there is no current element,
so advance() may not be called.public void setCurrent(int i)
i
- the index of the element to make the current elementjava.lang.IndexOutOfBoundsException
- Indicates that i is less than 0 or greater than
size-1 (i < 0 || i >= size).public void invalidateCurrent()
none
- public boolean contains(int target)
target
- the element that needs to be found in this sequencepublic int indexOf(int target)
target
- the element that needs to be found in this sequencepublic int size()
none
- public java.lang.Object clone()
clone
in class java.lang.Object
none
- java.lang.OutOfMemoryError
- Indicates insufficient memory for creating the clone.public IntLinkedSeq catenation(IntLinkedSeq s2)
s2
- the second sequenceNullPointerException.
- Indicates that the argument is null.java.lang.OutOfMemoryError
- Indicates insufficient memory for the new sequence.public IntLinkedSeq subSeq(int fromIndex, int toIndex)
fromIndex
- low endpoint (inclusive) of the sub sequencetoIndex
- high endpoint (exclusive) of the sub sequencejava.lang.IllegalArgumentException
- if the endpoint indices are out of order (fromIndex > toIndex)java.lang.IndexOutOfBoundsException
- endpoint index value out of range (fromIndex < 0 || toIndex > size)public IntLinkedSeq reverse()
none
- java.lang.OutOfMemoryError
- Indicates insufficient memory for the new sequence.public int[] toArray()
none
- java.lang.OutOfMemoryError
- Indicates insufficient memory for the new array.public java.lang.String toString()
toString
in class java.lang.Object
none
- java.lang.OutOfMemoryError
- Indicates insufficient memory for the new String.