Interface OrderStatisticSet<E>
-
- Type Parameters:
E
- the type of elements maintained by this set
- All Superinterfaces:
Collection<E>
,Iterable<E>
,NavigableSet<E>
,Set<E>
,SortedSet<E>
public interface OrderStatisticSet<E> extends NavigableSet<E>
ANavigableSet
that allows two additional operations: receiving (and deleting) an element by its rank, and getting the rank of an element.Implementations should adhere to all contracts of the
NavigableSet
interface.Implementing classes should provide two means for comparing elements:
- Using the natural ordering of the elements. In this case, all elements of the set have to
implement the
Comparable
interface. - Using a
Comparator
to create an order over the elements of the set.
In both cases, the used compare-method should be consistent with
equals
, i.e.,compare(a, b) == 0 => a.equals(b)
, so that the contract provided bySet
is fulfilled. If the used compare-method is not consistent withequals
, the Set contract is not fulfilled.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <E> OrderStatisticSet<E>
create()
Creates a new empty OrderStatisticSet using natural ordering.static <E> OrderStatisticSet<E>
create(Comparator<? super E> pComparator)
Creates a new empty OrderStatisticSet using the given comparator.static <E> OrderStatisticSet<E>
createWithNaturalOrder(Iterable<E> pCollection)
Creates a new OrderStatisticSet containing the same elements as the given Iterable, using natural ordering.static <E> OrderStatisticSet<E>
createWithSameOrder(SortedSet<E> pSortedSet)
Creates a new OrderStatisticSet containing the same elements and using the same order as the givenSortedSet
.OrderStatisticSet<E>
descendingSet()
E
getByRank(int pIndex)
Returns the element of this set with the given rank.OrderStatisticSet<E>
headSet(E pToElement)
OrderStatisticSet<E>
headSet(E pToElement, boolean inclusive)
int
rankOf(E pObj)
Return the rank of the given element in this set.E
removeByRank(int pIndex)
Remove the element of this set with the given rank and return it.OrderStatisticSet<E>
subSet(E pFromElement, boolean fromInclusive, E pToElement, boolean toInclusive)
OrderStatisticSet<E>
subSet(E pFromElement, E pToElement)
OrderStatisticSet<E>
tailSet(E pFromElement)
OrderStatisticSet<E>
tailSet(E pFromElement, boolean inclusive)
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.NavigableSet
ceiling, descendingIterator, floor, higher, iterator, lower, pollFirst, pollLast
-
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
-
Methods inherited from interface java.util.SortedSet
comparator, first, last, spliterator
-
-
-
-
Method Detail
-
getByRank
E getByRank(int pIndex)
Returns the element of this set with the given rank. The lowest element in the set has rank == 0, the largest element in the set has rank == size - 1.If this OrderStatisticSet is a view on some backing OrderStatisticSet (as created, e.g., by
descendingSet()
orheadSet(Object)
), the returned rank is in relation to the elements in the view, not in relation to the elements in the backing set. Thus, one can always expect that element of rank 0 is the first element in this set, and element of rankSet.size()
- 1- Parameters:
pIndex
- the rank of the element to return- Returns:
- the element of this set with the given rank
- Throws:
IndexOutOfBoundsException
- if the given rank is out of the range of this set (i.e., pRank < 0 || pRank >= size)
-
removeByRank
@CanIgnoreReturnValue E removeByRank(int pIndex)
Remove the element of this set with the given rank and return it.The lowest element in the set has rank == 0, the largest element in the set has rank == size - 1.
If this OrderStatisticSet is a view on some backing OrderStatisticSet (as created, e.g., by
descendingSet()
orheadSet(Object)
), the returned rank is in relation to the elements in the view, not in relation to the elements in the backing set. Thus, one can always expect that element of rank 0 is the first element in this set, and element of rankSet.size()
- 1- Parameters:
pIndex
- the rank of the element to remove- Returns:
- the removed element
- Throws:
IndexOutOfBoundsException
- if the given rank is out of the range of this set (i.e., pRank < 0 || pRank >= size)- See Also:
getByRank(int)
-
rankOf
int rankOf(E pObj)
Return the rank of the given element in this set. Returns -1 if the element does not exist in the set.The lowest element in the set has rank == 0, the largest element in the set has rank == size - 1.
If this OrderStatisticSet is a view on some backing OrderStatisticSet (as created, e.g., by
descendingSet()
orheadSet(Object)
), the returned rank is in relation to the elements in the view, not in relation to the elements in the backing set. Thus, one can always expect that element of rank 0 is the first element in this set, and element of rankSet.size()
- 1- Parameters:
pObj
- the element to return the rank for- Returns:
- the rank of the given element in the set, or -1 if the element is not in the set
- Throws:
NullPointerException
- if the given element isnull
-
descendingSet
OrderStatisticSet<E> descendingSet()
- Specified by:
descendingSet
in interfaceNavigableSet<E>
-
subSet
OrderStatisticSet<E> subSet(E pFromElement, boolean fromInclusive, E pToElement, boolean toInclusive)
- Specified by:
subSet
in interfaceNavigableSet<E>
-
headSet
OrderStatisticSet<E> headSet(E pToElement, boolean inclusive)
- Specified by:
headSet
in interfaceNavigableSet<E>
-
tailSet
OrderStatisticSet<E> tailSet(E pFromElement, boolean inclusive)
- Specified by:
tailSet
in interfaceNavigableSet<E>
-
subSet
OrderStatisticSet<E> subSet(E pFromElement, E pToElement)
-
headSet
OrderStatisticSet<E> headSet(E pToElement)
-
tailSet
OrderStatisticSet<E> tailSet(E pFromElement)
-
create
static <E> OrderStatisticSet<E> create()
Creates a new empty OrderStatisticSet using natural ordering. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticSet interface.
-
create
static <E> OrderStatisticSet<E> create(Comparator<? super E> pComparator)
Creates a new empty OrderStatisticSet using the given comparator. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticSet interface.
-
createWithNaturalOrder
static <E> OrderStatisticSet<E> createWithNaturalOrder(Iterable<E> pCollection)
Creates a new OrderStatisticSet containing the same elements as the given Iterable, using natural ordering. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticSet interface.
-
createWithSameOrder
static <E> OrderStatisticSet<E> createWithSameOrder(SortedSet<E> pSortedSet)
Creates a new OrderStatisticSet containing the same elements and using the same order as the givenSortedSet
. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticSet interface.- Type Parameters:
E
- type of the elements of the given and new set- Parameters:
pSortedSet
- set to use elements and ordering of- Returns:
- a new OrderStatisticSet containing the same elements and using the same order as the given set
-
-