public final class IntList extends MutabilityControl
ints.| Modifier and Type | Field and Description |
|---|---|
static IntList |
EMPTY
non-null; immutable, no-element instance |
| Constructor and Description |
|---|
IntList()
Constructs an empty instance with a default initial capacity.
|
IntList(int initialCapacity)
Constructs an empty instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int value)
Adds an element to the end of the list.
|
int |
binarysearch(int value)
Performs a binary search on a sorted list, returning the index of
the given value if it is present or
(-(insertion point) - 1) if the value is not present. |
boolean |
contains(int value)
Returns whether or not the given value appears in the list.
|
boolean |
equals(Object other) |
int |
get(int n)
Gets the indicated value.
|
int |
hashCode() |
int |
indexOf(int value)
Returns the index of the given value, or -1 if the value does not
appear in the list.
|
void |
insert(int n,
int value)
Inserts element into specified index, moving elements at and above
that index up one.
|
static IntList |
makeImmutable(int value)
Constructs a new immutable instance with the given element.
|
static IntList |
makeImmutable(int value0,
int value1)
Constructs a new immutable instance with the given elements.
|
IntList |
mutableCopy()
Makes and returns a mutable copy of the list.
|
int |
pop()
Pops an element off the end of the list and decreasing the size by one.
|
void |
pop(int n)
Pops N elements off the end of the list and decreasing the size by N.
|
void |
removeIndex(int n)
Removes an element at a given index, shifting elements at greater
indicies down one.
|
void |
set(int n,
int value)
Sets the value at the given index.
|
void |
shrink(int newSize)
Shrinks the size of the list.
|
int |
size()
Gets the number of elements in this list.
|
void |
sort()
Sorts the elements in the list in-place.
|
int |
top()
Returns the last element in the array without modifying the array
|
String |
toString() |
isImmutable, isMutable, setImmutable, throwIfImmutable, throwIfMutablepublic static final IntList EMPTY
non-null; immutable, no-element instancepublic IntList()
public IntList(int initialCapacity)
initialCapacity - >= 0; initial capacity of the listpublic static IntList makeImmutable(int value)
value - the sole value in the listpublic static IntList makeImmutable(int value0, int value1)
value0 - the first value in the listvalue1 - the second value in the listpublic int size()
public int get(int n)
n - >= 0, < size(); which elementpublic void set(int n,
int value)
n - >= 0, < size(); which elementvalue - value to storepublic void add(int value)
value - the value to addpublic void insert(int n,
int value)
n - >= 0, <=size(); index of where to insertvalue - value to insertpublic void removeIndex(int n)
n - >=0, < size(); index of element to removepublic int top()
IndexOutOfBoundsException - if stack is emptypublic int pop()
IndexOutOfBoundsException - if stack is emptypublic void pop(int n)
n - >= 0; number of elements to remove from endIndexOutOfBoundsException - if stack is smaller than Npublic void shrink(int newSize)
newSize - >= 0; the new sizepublic IntList mutableCopy()
non-null; an appropriately-constructed instancepublic void sort()
public int indexOf(int value)
value - value to findpublic int binarysearch(int value)
(-(insertion point) - 1) if the value is not present.
If the list is not sorted, then reverts to linear search and returns
-size() if the element is not found.value - value to find(-(insertion point) - 1) if the
value is not presentpublic boolean contains(int value)
value - value to look forsort()Copyright © 2016. All Rights Reserved.