Package cs2110
Interface IndexedSeq<T>
- All Superinterfaces:
Iterable<T>
- All Known Implementing Classes:
DynamicArrayIndexedSeq
,JavaIndexedSeq
A sequence of elements of type `T`, which can be accessed via their 0-based index. This is a
simpler alternative to Java's `List` interface.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
An iterator over an indexed sequence of elements of type `T`. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Append `value` to the end of this sequence.static boolean
equals
(IndexedSeq<?> a, IndexedSeq<?> b) Return whether `a` and `b` have the same elements.get
(int index) Return the element at index `index`.default T
getLast()
Return the last element of this sequence.static int
hashCode
(IndexedSeq<?> seq) Return a hash code derived from the hash codes of all of the elements in `seq`, dependent on their ordering.default boolean
isEmpty()
Return whether this sequence currently contains no elements.iterator()
default T
Remove and return the last element of this sequence.void
Assign `value` to the element at index `index`.int
size()
Return the number of elements in this sequence.default <U extends Comparable<? super U>>
voidSort the distinct elements in this sequence in ascending order, discarding duplicate copies.default void
swap
(int i, int j) Swap the elements at indices `i` and `j`.static <T> String
toString
(IndexedSeq<T> seq) Return a String representation of `seq`.void
truncate
(int end) Truncate this sequence, retaining only the elements with indices `[0..end)`.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
get
Return the element at index `index`. Throws `IndexOutOfBoundsException` if `index` is negative or is not less than this sequence's size. -
set
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. -
size
int size()Return the number of elements in this sequence. -
add
Append `value` to the end of this sequence. Requires `value` is not null. -
truncate
void truncate(int end) Truncate this sequence, retaining only the elements with indices `[0..end)`. -
isEmpty
default boolean isEmpty()Return whether this sequence currently contains no elements. -
getLast
Return the last element of this sequence. Throws `NoSuchElementException` if this sequence is empty. -
removeLast
Remove and return the last element of this sequence. Throws `NoSuchElementException` if this sequence is empty. -
swap
default void swap(int i, int j) Swap the elements at indices `i` and `j`. Throws `IndexOutOfBoundsException` if `i` or `j` is negative or is not less than this list's size. -
sortDistinct
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`). -
iterator
-
equals
Return whether `a` and `b` have the same elements. That is, every element in `a` is equal to the corresponding element in `b`, and `b` has no additional elements beyond those in `a`. The result is agnostic to the dynamic types of `a` and `b`.Implementations may choose to call this when overriding their own `equals()`.
-
hashCode
Return a hash code derived from the hash codes of all of the elements in `seq`, dependent on their ordering. Implementations may choose to call this when overriding their own `hashCode()`. -
toString
Return a String representation of `seq`.
-