Package cs2110
Class JavaIndexedSeq<T>
java.lang.Object
cs2110.JavaIndexedSeq<T>
- All Implemented Interfaces:
IndexedSeq<T>
,Iterable<T>
An indexed sequence of elements of type `T` backed by a Java List. Changes made to the sequence
are reflected in the original list, and vice versa. Null values must never be added to the
backing list. It is recommended that an `ArrayList` is used for the backing list.
-
Nested Class Summary
Nested classes/interfaces inherited from interface cs2110.IndexedSeq
IndexedSeq.Itr<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Append `value` to the end of this sequence.get
(int index) Return the element at index `index`.getList()
Return the Java List backing this sequence.void
Assign `value` to the element at index `index`.int
size()
Return the number of elements in this sequence.<U extends Comparable<? super U>>
voidSort the distinct elements in this sequence in ascending order, discarding duplicate copies.toString()
void
truncate
(int end) Truncate this sequence, retaining only the elements with indices `[0..end)`.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface cs2110.IndexedSeq
getLast, isEmpty, iterator, removeLast, swap
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Method Details
-
getList
Return the Java List backing this sequence. -
get
Description copied from interface:IndexedSeq
Return the element at index `index`. Throws `IndexOutOfBoundsException` if `index` is negative or is not less than this sequence's size.- Specified by:
get
in interfaceIndexedSeq<T>
-
set
Description copied from interface:IndexedSeq
Assign `value` to the element at index `index`. Throws `IndexOutOfBoundsException` if `index` is negative or is not less than this sequence's size. Requires `value` is not null.- Specified by:
set
in interfaceIndexedSeq<T>
-
size
public int size()Description copied from interface:IndexedSeq
Return the number of elements in this sequence.- Specified by:
size
in interfaceIndexedSeq<T>
-
add
Description copied from interface:IndexedSeq
Append `value` to the end of this sequence. Requires `value` is not null.- Specified by:
add
in interfaceIndexedSeq<T>
-
truncate
public void truncate(int end) Description copied from interface:IndexedSeq
Truncate this sequence, retaining only the elements with indices `[0..end)`.- Specified by:
truncate
in interfaceIndexedSeq<T>
-
sortDistinct
Description copied from interface:IndexedSeq
Sort the distinct elements in this sequence in ascending order, discarding duplicate copies. Requires `T` is `Comparable` to itself (that is, `T` satisfies the bounds on `U`).- Specified by:
sortDistinct
in interfaceIndexedSeq<T>
-
toString
-