T
- has to be comparablepublic class SortedArrayList<T extends java.lang.Comparable<T>> extends MyArrayList<T>
Constructor and Description |
---|
SortedArrayList() |
SortedArrayList(int capacity)
This constructor will set the internal array to a Comparable Object array of
size specified by the user.
|
SortedArrayList(SortedArrayList<T> s)
This is a copy constructor
|
Modifier and Type | Method and Description |
---|---|
void |
add(int i,
T item)
Add (insert) item to the ith position if the insertion maintains the array
sorted, if not, the item will not be added and an IllegalArgumentException
will be thrown.
|
void |
add(T item)
Add item to the end of this List.
|
int |
indexOf(java.lang.Object item)
Find the index of the input Object in this SortedArrayList.
|
T |
set(int i,
T item)
Set (insert) item to the ith position if the new item is not out of order; otherwise
an IllegalArgumentException will be thrown.
|
clone, get, iterator, remove, size, toArray, toArray, toString
public SortedArrayList()
public SortedArrayList(int capacity)
capacity
- is the initial size of the internal arraypublic SortedArrayList(SortedArrayList<T> s)
s
- is a SortedArrayListpublic void add(T item)
MyList
add
in interface MyList<T extends java.lang.Comparable<T>>
add
in class MyArrayList<T extends java.lang.Comparable<T>>
item
- will be inserted into the right place to maintain the orderMyList.add(java.lang.Object)
public void add(int i, T item)
add
in interface MyList<T extends java.lang.Comparable<T>>
add
in class MyArrayList<T extends java.lang.Comparable<T>>
i
- is an index.item
- is an object T to be inserted at i.java.lang.ArrayIndexOutOfBoundsException
- will be thrown if parameter
i is not an legitimate index, i.e, when i is a negative number or greater than size.java.lang.IllegalArgumentException
- will be thrown if the item can't be
inserted into the position, i.e, the insertion will cause the item in the array out of order.MyList.add(int, java.lang.Object)
public T set(int i, T item)
set
in interface MyList<T extends java.lang.Comparable<T>>
set
in class MyArrayList<T extends java.lang.Comparable<T>>
i
- is an index.item
- is an object T to be set at i.java.lang.ArrayIndexOutOfBoundsException
- will be thrown if parameter
i is not an legitimate index, i.e, when i is a negative number or greater than size.java.lang.IllegalArgumentException
- will be thrown if the item is out of order.MyList.set(int, java.lang.Object)
public int indexOf(java.lang.Object item)