org.omnaest.utils.structure.collection.list.sorted
Class SortedListAbstract<E>

java.lang.Object
  extended by org.omnaest.utils.structure.collection.CollectionAbstract<E>
      extended by org.omnaest.utils.structure.collection.list.ListAbstract<E>
          extended by org.omnaest.utils.structure.collection.list.sorted.SortedListAbstract<E>
Type Parameters:
E -
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, Deque<E>, List<E>, Queue<E>, SortedList<E>, SortedSplitableList<E>
Direct Known Subclasses:
InsertionSortedList, TreeList

public abstract class SortedListAbstract<E>
extends ListAbstract<E>
implements SortedSplitableList<E>

Abstract implementation of a SortedList which reduces the need to implement all methods

Author:
Omnaest
See Also:
Serialized Form

Nested Class Summary
protected static class SortedListAbstract.SortedListAbstractSublist<E>
          Sublist implementation for SortedListAbstract
 
Nested classes/interfaces inherited from class org.omnaest.utils.structure.collection.list.ListAbstract
ListAbstract.ListAbstractSublist<E>
 
Field Summary
protected  Comparator<E> comparator
          The constructor will ensure that the Comparator will not be null
 
Constructor Summary
SortedListAbstract()
          Using this constructor enforces that all element types implement the Comparable interface
SortedListAbstract(Comparator<E> comparator)
           
 
Method Summary
 void add(int index, E element)
          The SortedList.add(int, Object) ignores the given index position and acts similar to the SortedList.add(Object) method
 Comparator<? super E> comparator()
          Returns the Comparator used by this SortedList
 E first()
          Returns the first (lowest) element currently in this SortedList.
protected static
<E> E
first(SortedList<E> sortedList)
           
 E getFirst()
           
 E getLast()
           
 SortedList<E> headList(E toElement)
          Returns a view to the current SortedList which starts at the beginning and ends by the given element which itself is excluded from the head list.
protected static
<E> SortedList<E>
headList(SortedList<E> list, E toElement)
           
 E last()
          Returns the last (highest) element currently in this SortedList.
protected static
<E> E
last(SortedList<E> sortedList)
           
protected  SortedList<E> newInstance(Collection<E> collection)
          Creates a new SortedList instance
 E set(int index, E element)
          Uses List.remove(int) to remove the element from the given index position an returns it.
 SortedList<E> splitAt(int index)
          Splits the current SortedList at the given index position.
 SortedList<E> subList(E fromElement, E toElement)
          Returns a sublist view of the current SortedList starting by the given fromElement which will be included in the sublist and ending by the given toElement which will be excluded from the sublist.
 SortedList<E> subList(int fromIndex, int toIndex)
          Similar to List#subList(int, int)
protected static
<E> SortedList<E>
subList(SortedList<E> list, E fromElement, E toElement)
           
 SortedList<E> tailList(E fromElement)
          Returns a view to the current SortedList starting by the given element up to the end including the given element.
protected static
<E> SortedList<E>
tailList(SortedList<E> list, E fromElement)
           
 
Methods inherited from class org.omnaest.utils.structure.collection.list.ListAbstract
addAll, addFirst, addLast, clear, contains, descendingIterator, element, isValidIndex, iterator, listIterator, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence
 
Methods inherited from class org.omnaest.utils.structure.collection.CollectionAbstract
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.omnaest.utils.structure.collection.list.sorted.SortedList
add
 
Methods inherited from interface java.util.List
addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.Deque
add, size
 

Field Detail

comparator

protected final Comparator<E> comparator
The constructor will ensure that the Comparator will not be null

Constructor Detail

SortedListAbstract

public SortedListAbstract(Comparator<E> comparator)
Parameters:
comparator -
See Also:
SortedListAbstract

SortedListAbstract

public SortedListAbstract()
Using this constructor enforces that all element types implement the Comparable interface

See Also:
SortedListAbstract
Method Detail

comparator

public Comparator<? super E> comparator()
Description copied from interface: SortedList
Returns the Comparator used by this SortedList

Specified by:
comparator in interface SortedList<E>
Returns:

first

public E first()
Description copied from interface: SortedList
Returns the first (lowest) element currently in this SortedList.

Specified by:
first in interface SortedList<E>

first

protected static <E> E first(SortedList<E> sortedList)
Parameters:
sortedList -
Returns:

last

public E last()
Description copied from interface: SortedList
Returns the last (highest) element currently in this SortedList.

Specified by:
last in interface SortedList<E>

last

protected static <E> E last(SortedList<E> sortedList)
Parameters:
sortedList -
Returns:

subList

public SortedList<E> subList(E fromElement,
                             E toElement)
Description copied from interface: SortedList
Returns a sublist view of the current SortedList starting by the given fromElement which will be included in the sublist and ending by the given toElement which will be excluded from the sublist.

Specified by:
subList in interface SortedList<E>
Parameters:
fromElement - lower point (inclusive)
toElement - higher pint (exclusive)

headList

public SortedList<E> headList(E toElement)
Description copied from interface: SortedList
Returns a view to the current SortedList which starts at the beginning and ends by the given element which itself is excluded from the head list.

Specified by:
headList in interface SortedList<E>
Parameters:
toElement - end element (exclusive)
Returns:

tailList

public SortedList<E> tailList(E fromElement)
Description copied from interface: SortedList
Returns a view to the current SortedList starting by the given element up to the end including the given element.

Specified by:
tailList in interface SortedList<E>
Returns:

subList

protected static <E> SortedList<E> subList(SortedList<E> list,
                                           E fromElement,
                                           E toElement)
Parameters:
list -
fromElement -
toElement -
Returns:

headList

protected static <E> SortedList<E> headList(SortedList<E> list,
                                            E toElement)
Parameters:
list -
toElement -
Returns:

tailList

protected static <E> SortedList<E> tailList(SortedList<E> list,
                                            E fromElement)
Parameters:
list -
fromElement -
Returns:

subList

public SortedList<E> subList(int fromIndex,
                             int toIndex)
Description copied from interface: SortedList
Similar to List#subList(int, int)

Specified by:
subList in interface List<E>
Specified by:
subList in interface SortedList<E>
Overrides:
subList in class ListAbstract<E>

add

public void add(int index,
                E element)
Description copied from interface: SortedList
The SortedList.add(int, Object) ignores the given index position and acts similar to the SortedList.add(Object) method

Specified by:
add in interface List<E>
Specified by:
add in interface SortedList<E>

set

public E set(int index,
             E element)
Description copied from interface: SortedList
Uses List.remove(int) to remove the element from the given index position an returns it. The newly given element will NOT be inserted at the given index position, instead it will be inserted at its right sort position similar to calling the SortedList.add(Object) method on it.

Specified by:
set in interface List<E>
Specified by:
set in interface SortedList<E>

splitAt

public SortedList<E> splitAt(int index)
Description copied from interface: SortedSplitableList
Splits the current SortedList at the given index position. The current List will retain all elements up to this index position excluding the index position itself.
The returned SortedList will hold all elements starting and including the one at the given index position till the end of the current List.

Specified by:
splitAt in interface SortedSplitableList<E>
Returns:

newInstance

protected SortedList<E> newInstance(Collection<E> collection)
Creates a new SortedList instance

Parameters:
collection -
Returns:

getFirst

public E getFirst()
Specified by:
getFirst in interface Deque<E>
Overrides:
getFirst in class ListAbstract<E>

getLast

public E getLast()
Specified by:
getLast in interface Deque<E>
Overrides:
getLast in class ListAbstract<E>


Copyright © 2013. All Rights Reserved.