|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.omnaest.utils.structure.collection.CollectionAbstract<E>
org.omnaest.utils.structure.collection.list.ListAbstract<E>
org.omnaest.utils.structure.collection.list.sorted.SortedListAbstract<E>
org.omnaest.utils.structure.collection.list.sorted.TreeList<E>
E - public class TreeList<E>
This sorted List implementation does use an internal TreeMap to provide all features a SortedSet has,
except the fact that duplicate elements are allowed.
But be aware, that the order of elements, which are considered equal due to the Comparator.compare(Object, Object)
method, is not determined.
The TreeList has a quite fast add(Object) method which uses the advantages of the underlying TreeMap.
All index based operations like get(int) or remove(int) are slow for large Lists with many different
elements, since all elements of the TreeMap have to be traversed to identify the right index position.
The TreeList does break the contract of the List.add(Object), as well as the List.add(int, Object) in
the way, that it does insert new elements at the appropriate sort position.
The listIterator() does currently not support ListIterator.nextIndex() and
ListIterator.previousIndex() and throws UnsupportedOperationException in the case calling those methods.
Performance is about 2x-3x slower compared to a TreeSet and quite similar to the performance of the
TreeMultiset.
The following example is based on
Stringscontains(Object)TreeList and a TreeMultiset will contain about 100 times more elements than the TreeSet
since they allow duplicates )
--- TreeList --- samples: 50 max: 640 average: 187.08 median: 167 --- TreeSet --- samples: 50 max: 280 average: 80.08 median: 75 --- TreeMultiSet --- samples: 50 max: 862 average: 182.2 median: 163 (durations in milliseconds)
SortedList,
Serialized Form| Nested Class Summary | |
|---|---|
protected class |
TreeList.ElementList
An TreeList.ElementList is based on an regular ArrayList but additionally removes itself from the underlying
SortedMap if its last element is removed and the List is going to get empty. |
protected static interface |
TreeList.ElementVisitor<E>
|
| Nested classes/interfaces inherited from class org.omnaest.utils.structure.collection.list.sorted.SortedListAbstract |
|---|
SortedListAbstract.SortedListAbstractSublist<E> |
| Nested classes/interfaces inherited from class org.omnaest.utils.structure.collection.list.ListAbstract |
|---|
ListAbstract.ListAbstractSublist<E> |
| Field Summary |
|---|
| Fields inherited from class org.omnaest.utils.structure.collection.list.sorted.SortedListAbstract |
|---|
comparator |
| Constructor Summary | |
|---|---|
|
TreeList()
|
|
TreeList(Collection<E> collection)
|
|
TreeList(Comparator<E> comparator)
|
|
TreeList(Comparator<E> comparator,
Collection<E> collection)
|
protected |
TreeList(Factory<SortedMap<AccessorReadable<E>,TreeList.ElementList>> elementToEqualElementListMapFactory)
|
| Method Summary | |
|---|---|
boolean |
add(E element)
This does add the given element at the right order position. |
void |
clear()
|
boolean |
contains(Object object)
Returns true if any element within the TreeList is Object.equals(Object) to the given Object |
E |
get(int index)
|
int |
indexOf(Object object)
Returns the index position of the first occurrence of an element which is Object.equals(Object) to the given
Object |
boolean |
isEmpty()
|
int |
lastIndexOf(Object object)
|
ListIterator<E> |
listIterator()
|
protected SortedList<E> |
newInstance(Collection<E> collection)
Creates a new SortedList instance |
E |
remove(int index)
|
boolean |
remove(Object object)
Removes the first occurring element within the TreeList, which is Object.equals(Object) to the given
Object |
int |
size()
|
protected void |
visitElements(TreeList.ElementVisitor<E> elementVisitor)
Similar to visitElements(ElementVisitor, Iterable) which uses all available TreeList.ElementList instances of the
internal SortedMap in their sort order. |
protected void |
visitElements(TreeList.ElementVisitor<E> elementVisitor,
Iterable<TreeList.ElementList> elementListCollection)
Visitor method which allows to traverse over all given TreeList.ElementList in their current order and execute the
TreeList.ElementVisitor.beforeTraversalOfElementList(int, int, List) on them. |
| Methods inherited from class org.omnaest.utils.structure.collection.list.sorted.SortedListAbstract |
|---|
add, comparator, first, first, getFirst, getLast, headList, headList, last, last, set, splitAt, subList, subList, subList, tailList, tailList |
| Methods inherited from class org.omnaest.utils.structure.collection.list.ListAbstract |
|---|
addAll, addFirst, addLast, descendingIterator, element, isValidIndex, iterator, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence |
| Methods inherited from class org.omnaest.utils.structure.collection.CollectionAbstract |
|---|
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
addAll, addAll, containsAll, equals, hashCode, iterator, listIterator, removeAll, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public TreeList()
TreeListpublic TreeList(Comparator<E> comparator)
comparator - TreeListpublic TreeList(Collection<E> collection)
collection - TreeList
public TreeList(Comparator<E> comparator,
Collection<E> collection)
comparator - collection - TreeListprotected TreeList(Factory<SortedMap<AccessorReadable<E>,TreeList.ElementList>> elementToEqualElementListMapFactory)
elementToEqualElementListMapFactory - TreeList| Method Detail |
|---|
public int size()
public boolean add(E element)
SortedListCollection
interface, since the new element is not appended to the Collection.
public E get(int index)
protected void visitElements(TreeList.ElementVisitor<E> elementVisitor)
visitElements(ElementVisitor, Iterable) which uses all available TreeList.ElementList instances of the
internal SortedMap in their sort order.
elementVisitor - #visitElements(ElementVisitor, int)
protected void visitElements(TreeList.ElementVisitor<E> elementVisitor,
Iterable<TreeList.ElementList> elementListCollection)
TreeList.ElementList in their current order and execute the
TreeList.ElementVisitor.beforeTraversalOfElementList(int, int, List) on them.
elementVisitor - elementListCollection - #visitElements(ElementVisitor, int)public E remove(int index)
public int indexOf(Object object)
Object.equals(Object) to the given
Object
public int lastIndexOf(Object object)
public boolean remove(Object object)
TreeList, which is Object.equals(Object) to the given
Object
remove in interface Collection<E>remove in interface Deque<E>remove in interface List<E>remove in class ListAbstract<E>Object is foundpublic boolean contains(Object object)
TreeList is Object.equals(Object) to the given Object
contains in interface Collection<E>contains in interface Deque<E>contains in interface List<E>contains in class ListAbstract<E>public boolean isEmpty()
isEmpty in interface Collection<E>isEmpty in interface List<E>isEmpty in class CollectionAbstract<E>public void clear()
clear in interface Collection<E>clear in interface List<E>clear in class ListAbstract<E>public ListIterator<E> listIterator()
listIterator in interface List<E>listIterator in class ListAbstract<E>protected SortedList<E> newInstance(Collection<E> collection)
SortedListAbstractSortedList instance
newInstance in class SortedListAbstract<E>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||