public class IntLinkedSeq extends IntSeq
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.
|
IntLinkedSeq(IntLinkedSeq otherSequence)
Copy Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addAfter(int element)
Add a new element to this sequence, after the current element.
|
void |
addAll(IntSeq 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.
|
IntSeq |
catenation(IntSeq s2)
Create a new sequence that contains all the elements from
this sequence followed by another 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.
|
IntSeq |
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.
|
IntSeq |
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.
|
String |
toString()
Returns a String containing a representation of all the elements
in this sequence.
|
public IntLinkedSeq()
none
- public IntLinkedSeq(IntLinkedSeq otherSequence)
otherSequence
- Sequence to make a deep copy of.public void addAfter(int element)
public void addAll(IntSeq addend)
public void addBefore(int element)
public void addFirst(int element)
public void addLast(int element)
public void advance()
public IntSeq catenation(IntSeq s2)
catenation
in class IntSeq
s2
- the second sequencepublic boolean contains(int target)
public int getCurrentValue()
getCurrentValue
in class IntSeq
public int indexOf(int target)
public void invalidateCurrent()
invalidateCurrent
in class IntSeq
public boolean isCurrent()
public void removeCurrent()
removeCurrent
in class IntSeq
public void removeFirst()
removeFirst
in class IntSeq
public void removeLast()
removeLast
in class IntSeq
public IntSeq reverse()
public void setCurrent(int i)
setCurrent
in class IntSeq
i
- the index of the element to make the current elementpublic void setCurrentValue(int element)
setCurrentValue
in class IntSeq
element
- the new value that is to be placed in the current elementpublic int size()
public void start()
public IntSeq subSeq(int fromIndex, int toIndex)
subSeq
in class IntSeq
fromIndex
- low endpoint (inclusive) of the sub sequencetoIndex
- high endpoint (exclusive) of the sub sequencepublic int[] toArray()