Class TreeList
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
org.apache.commons.collections.list.TreeList
- All Implemented Interfaces:
Iterable,Collection,List,SequencedCollection
Deprecated.
Apache Commons Collections version 3.x is being deprecated from AEMaaCS. The upgraded version 4.4 of Commons Collections is already included as replacement. Customers are advised to upgrade to this version of the library. Please note: the package name was changed to org.apache.commons.collections4. Further note that there are AEM APIs currently exposing the old collections classes; these will be updated in upcoming releases.
A
List implementation that is optimised for fast insertions and
removals at any index in the list.
This list implementation utilises a tree structure internally to ensure that
all insertions and removals are O(log n). This provides much faster performance
than both an ArrayList and a LinkedList where elements
are inserted and removed repeatedly from anywhere in the list.
The following relative performance statistics are indicative of this class:
get add insert iterate remove
TreeList 3 5 1 2 1
ArrayList 1 1 40 1 40
LinkedList 5800 1 350 2 325
ArrayList is a good general purpose list implementation.
It is faster than TreeList for most operations except inserting
and removing in the middle of the list. ArrayList also uses less
memory as TreeList uses one object per entry.
LinkedList is rarely a good choice of implementation.
TreeList is almost always a good replacement for it, although it
does use sligtly more memory.
- Since:
- Commons Collections 3.1
-
Constructor Summary
ConstructorsConstructorDescriptionTreeList()Deprecated.Constructs a new empty list.TreeList(Collection coll) Deprecated.Constructs a new empty list that copies the specified list. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.Adds a new element to the list.voidclear()Deprecated.Clears the list, removing all entries.booleanDeprecated.Searches for the presence of an object in the list.get(int index) Deprecated.Gets the element at the specified index.intDeprecated.Searches for the index of an object in the list.iterator()Deprecated.Gets an iterator over the list.Deprecated.Gets a ListIterator over the list.listIterator(int fromIndex) Deprecated.Gets a ListIterator over the list.remove(int index) Deprecated.Removes the element at the specified index.Deprecated.Sets the element at the specified index.intsize()Deprecated.Gets the current size of the list.Object[]toArray()Deprecated.Converts the list into an array.Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, lastIndexOf, subListMethods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toStringMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, addFirst, addLast, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray
-
Constructor Details
-
TreeList
public TreeList()Deprecated.Constructs a new empty list. -
TreeList
Deprecated.Constructs a new empty list that copies the specified list.- Parameters:
coll- the collection to copy- Throws:
NullPointerException- if the collection is null
-
-
Method Details
-
get
Deprecated.Gets the element at the specified index.- Specified by:
getin interfaceList- Specified by:
getin classAbstractList- Parameters:
index- the index to retrieve- Returns:
- the element at the specified index
-
size
public int size()Deprecated.Gets the current size of the list.- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceList- Specified by:
sizein classAbstractCollection- Returns:
- the current size
-
iterator
Deprecated.Gets an iterator over the list.- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceList- Overrides:
iteratorin classAbstractList- Returns:
- an iterator over the list
-
listIterator
Deprecated.Gets a ListIterator over the list.- Specified by:
listIteratorin interfaceList- Overrides:
listIteratorin classAbstractList- Returns:
- the new iterator
-
listIterator
Deprecated.Gets a ListIterator over the list.- Specified by:
listIteratorin interfaceList- Overrides:
listIteratorin classAbstractList- Parameters:
fromIndex- the index to start from- Returns:
- the new iterator
-
indexOf
Deprecated.Searches for the index of an object in the list.- Specified by:
indexOfin interfaceList- Overrides:
indexOfin classAbstractList- Returns:
- the index of the object, -1 if not found
-
contains
Deprecated.Searches for the presence of an object in the list.- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceList- Overrides:
containsin classAbstractCollection- Returns:
- true if the object is found
-
toArray
Deprecated.Converts the list into an array.- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceList- Overrides:
toArrayin classAbstractCollection- Returns:
- the list as an array
-
add
Deprecated.Adds a new element to the list.- Specified by:
addin interfaceList- Overrides:
addin classAbstractList- Parameters:
index- the index to add beforeobj- the element to add
-
set
Deprecated.Sets the element at the specified index.- Specified by:
setin interfaceList- Overrides:
setin classAbstractList- Parameters:
index- the index to setobj- the object to store at the specified index- Returns:
- the previous object at that index
- Throws:
IndexOutOfBoundsException- if the index is invalid
-
remove
Deprecated.Removes the element at the specified index.- Specified by:
removein interfaceList- Overrides:
removein classAbstractList- Parameters:
index- the index to remove- Returns:
- the previous object at that index
-
clear
public void clear()Deprecated.Clears the list, removing all entries.- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceList- Overrides:
clearin classAbstractList
-