|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<T>
com.scottlogic.util.SortedList<T>
com.scottlogic.util.UnsortedList<T>
T
- the type of element that this sorted list will store.public class UnsortedList<T>
Implementation of a regular list that uses an AVL tree. Supports all optional operations.
Performs the operations: add(int, Object)
, get
and remove(int)
operations in
in time O(log(n)) and
the contains(Object)
and remove(Object)
operations in time O(n),
where n is the number of elements in the list.
This implementation is not synchronised so if you need multi-threaded access then consider wrapping
it using the Collections.synchronizedList(java.util.List
method.
The iterators this list provides are fail-fast, so any structural
modification, other than through the iterator itself, cause it to throw a
ConcurrentModificationException
.
Collection
,
AbstractList
,
Serialized FormNested Class Summary | |
---|---|
protected class |
UnsortedList.UnsortedNode
Class representing the individual nodes of an unsorted list extends the regular SortedList.Node class by storing the position of the node in the tree. |
Nested classes/interfaces inherited from class com.scottlogic.util.SortedList |
---|
SortedList.Node |
Field Summary |
---|
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
UnsortedList()
Constructs a new UnsortedList . |
Method Summary | |
---|---|
void |
add(int index,
T element)
Inserts the specified element at the specified position in this list. |
boolean |
add(T object)
Adds the given object to the end of this UnsortedList , which can be
null . |
void |
addToHead(T element)
Adds the given element to the head of this list. |
boolean |
contains(java.lang.Object obj)
Returns whether or not the given object whether or not the given object is present in this UnsortedList . |
boolean |
remove(java.lang.Object value)
Removes the first element in the list with the given value, if such a node exists, otherwise does nothing. |
T |
set(int index,
T element)
Replaces the element at the specified position in this list with the specified element. |
Methods inherited from class com.scottlogic.util.SortedList |
---|
add, clear, findFirstNodeWithValue, findNodeAtIndex, get, getRoot, isEmpty, iterator, remove, remove, size, toArray, toArray |
Methods inherited from class java.util.AbstractList |
---|
addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, subList |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, containsAll, removeAll, retainAll, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
addAll, containsAll, removeAll, retainAll |
Constructor Detail |
---|
public UnsortedList()
UnsortedList
.
Method Detail |
---|
public T set(int index, T element)
set
in interface java.util.List<T>
set
in class java.util.AbstractList<T>
index
- the index in this UnsortedList
to add this given element.element
- the object to add to this UnsortedList
.
java.lang.IllegalArgumentException
- in the case that the element is null
.
java.lang.IndexOutOfBoundsException
- in the case that (0 <= index < size()) does not hold.public boolean contains(java.lang.Object obj)
UnsortedList
.
This implementation takes O(n) time, where n is the number of element in this list.
contains
in interface java.util.Collection<T>
contains
in interface java.util.List<T>
contains
in class SortedList<T>
obj
- the object to check for.
true
if the given object is present in this UnsortedList
and false
otherwise.public boolean remove(java.lang.Object value)
UnsortedList
.
Returns whether or not a matching element was found and removed or not.
remove
in interface java.util.Collection<T>
remove
in interface java.util.List<T>
remove
in class SortedList<T>
value
- the object to remove from this SortedList
.
true
if the given object was found in this
SortedList
and removed, false
otherwise.public void add(int index, T element)
Works in time O(log(n)), where n is the number of elements in the list.
add
in interface java.util.List<T>
add
in class java.util.AbstractList<T>
index
- at which the element should be added.element
- the object to by inserted.
java.lang.IllegalArgumentException
- in the case that the given element is null.
java.lang.IndexOutOfBoundsException
- in the case that (0 <= index <= size()) does not hold.public void addToHead(T element)
Works in time O(log(n)), where n is the number of elements in the list.
element
- the object to by inserted.
java.lang.IllegalArgumentException
- in the case that the given element is null.public boolean add(T object)
UnsortedList
, which can be
null
.
add
in interface java.util.Collection<T>
add
in interface java.util.List<T>
add
in class SortedList<T>
object
- the object to add.
true
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |