|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectListArrayBased
Array implementation of the List interface. Permits all elements, including null.
The size
, isEmpty
, get
, and removeAll
,
operations run in constant time.
The add
and remove
operations run in linear time.
Each ListArrayBased
instance has a capacity.
The capacity is the size of the array used to store the elements in the list.
It is always at least as large as the list size.
Constructor Summary | |
ListArrayBased()
|
Method Summary | |
void |
add(int index,
java.lang.Object item)
Inserts the specified element at the specified position in this list. |
java.lang.Object |
get(int index)
Returns the element at the specified position in this list. |
boolean |
isEmpty()
Returns true if this list contains no elements. |
void |
remove(int index)
Removes the element at the specified position in this list. |
void |
removeAll()
Removes from this list all the elements that are contained in the specified collection. |
int |
size()
Returns the number of elements in this list. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ListArrayBased()
Method Detail |
public boolean isEmpty()
ListInterface
true
if this list contains no elements.
Pre-condition: None
Post-condition: Returns true
if the list is empty
and false
otherwise
isEmpty
in interface ListInterface
true
if this list contains no elementspublic int size()
ListInterface
Pre-condition: None
Post-condition: Returns the number of elements in the list, or
Integer.MAX_VALUE
if there are more than Integer.MAX_VALUE
elements in the list.
size
in interface ListInterface
public void removeAll()
ListInterface
Pre-condition: None.
Post-condition: The list is empty (this.isEmpty()
returns true).
removeAll
in interface ListInterface
public void add(int index, java.lang.Object item) throws ListIndexOutOfBoundsException
ListInterface
Pre-condition: index
is between 1
and this.size()+1
.
Post-condition: item
becomes the list element
at position index
; the position of later elements in the list
is increased by 1
to make room for it.
add
in interface ListInterface
index
- index at which the specified element is to be inserted.item
- element to be inserted.
ListIndexOutOfBoundsException
- if the index is out of the range 1 up to the size of the listpublic java.lang.Object get(int index) throws ListIndexOutOfBoundsException
ListInterface
Pre-condition: index
is between 1
and this.size()
.
Post-condition: Returns the element at position index
.
get
in interface ListInterface
index
- index of element to return.
ListIndexOutOfBoundsException
- if the index is out of the range 1 up to the size of the listpublic void remove(int index) throws ListIndexOutOfBoundsException
ListInterface
Pre-condition: index
is between 1
and this.size()+1
.
Post-condition: Removes the element at position index
;
the position of later elements in the list is decreased by 1
.
remove
in interface ListInterface
index
- index of element to remove.
ListIndexOutOfBoundsException
- if the index is out of the range 1 up to the size of the list
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |