Class Rank<T>
- java.lang.Object
-
- org.apache.jackrabbit.commons.flat.Rank<T>
-
- Type Parameters:
T
- Type of values in thisRank
.
public class Rank<T> extends java.lang.Object
This class does efficient ranking of values of type
T
wrt. to aComparator
forT
. After creating an instance ofRank
, thetake(int)
method returns the nextk
smallest values. That is, each of these values is smaller than every value not yet retrieved. The order of the values returned bytake
is not specified in general. However if the values are in increasing order, the values returned bytake
will also be in increasing order.Note: The values may not contain duplicates or the behavior of
take
is not defined.
-
-
Constructor Summary
Constructors Constructor Description Rank(java.util.Collection<T> values, java.lang.Class<T> componentType, java.util.Comparator<? super T> order)
Create a new instance ofRank
for a given collection ofvalues
and a givenorder
.Rank(java.util.Iterator<T> values, java.lang.Class<T> componentType, int count, java.util.Comparator<? super T> order)
Create a new instance ofRank
for the firstcount
values in a a given iterator ofvalues
and a givenorder
.Rank(T[] values, java.util.Comparator<? super T> order)
Create a new instance ofRank
for a given array ofvalues
and a givenorder
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Comparable<T>>
java.util.Comparator<T>comparableComparator()
Utility method for creating aComparator
ofT
from aComparable
of typeT
.java.util.Comparator<? super T>
getOrder()
static <S extends java.lang.Comparable<S>>
Rank<S>rank(java.util.Collection<S> values, java.lang.Class<S> componentType)
Create a new instance ofRank
for a given collection ofvalues
.static <S extends java.lang.Comparable<S>>
Rank<S>rank(java.util.Iterator<S> values, java.lang.Class<S> componentType, int count)
Create a new instance ofRank
for the firstcount
values in a a given iterator ofvalues
.static <S extends java.lang.Comparable<S>>
Rank<S>rank(S[] values)
Create a new instance ofRank
for a given array ofvalues
.int
size()
Returns the number of remaining items in theRank
.java.util.Iterator<T>
take(int n)
Returns then
-th smallest values remaining in thisRank
.
-
-
-
Constructor Detail
-
Rank
public Rank(T[] values, java.util.Comparator<? super T> order)
Create a new instance ofRank
for a given array ofvalues
and a givenorder
. Thevalues
are manipulated in place, no copying is performed.- Parameters:
values
- values for ranking. Duplicates are not allowed.order
- Ordering for ranking
-
Rank
public Rank(java.util.Collection<T> values, java.lang.Class<T> componentType, java.util.Comparator<? super T> order)
Create a new instance ofRank
for a given collection ofvalues
and a givenorder
. Thevalues
are copied into an internal array before they are manipulated.- Parameters:
values
- values for ranking. Duplicates are not allowed.componentType
- type evidence for the valuesorder
- Ordering for ranking
-
Rank
public Rank(java.util.Iterator<T> values, java.lang.Class<T> componentType, int count, java.util.Comparator<? super T> order)
Create a new instance ofRank
for the firstcount
values in a a given iterator ofvalues
and a givenorder
. Thevalues
are copied into an internal array before they are manipulated.- Parameters:
values
- values for ranking. Duplicates are not allowed.componentType
- type evidence for the valuescount
- Number of items to include. -1 for all.order
- Ordering for ranking
-
-
Method Detail
-
rank
public static <S extends java.lang.Comparable<S>> Rank<S> rank(S[] values)
Create a new instance ofRank
for a given array ofvalues
. The order is determined by the natural ordering of the values (i.e. throughComparable
). Thevalues
are manipulated in place, no copying is performed.- Type Parameters:
S
- extends Comparable<S>- Parameters:
values
- values for ranking. Duplicates are not allowed.- Returns:
- A new instance of
Rank
.
-
rank
public static <S extends java.lang.Comparable<S>> Rank<S> rank(java.util.Collection<S> values, java.lang.Class<S> componentType)
Create a new instance ofRank
for a given collection ofvalues
. The order is determined by the natural ordering of the values (i.e. throughComparable
). Thevalues
are copied into an internal array before they are manipulated.- Type Parameters:
S
- extends Comparable<S>- Parameters:
values
- values for ranking. Duplicates are not allowed.componentType
- type evidence for the values- Returns:
- A new instance of
Rank
.
-
rank
public static <S extends java.lang.Comparable<S>> Rank<S> rank(java.util.Iterator<S> values, java.lang.Class<S> componentType, int count)
Create a new instance ofRank
for the firstcount
values in a a given iterator ofvalues
. The order is determined by the natural ordering of the values (i.e. throughComparable
). Thevalues
are copied into an internal array before they are manipulated.- Type Parameters:
S
- extends Comparable<S>- Parameters:
values
- values for ranking. Duplicates are not allowed.componentType
- type evidence for the valuescount
- Number of items to include. -1 for all.- Returns:
- A new instance of
Rank
.
-
comparableComparator
public static <T extends java.lang.Comparable<T>> java.util.Comparator<T> comparableComparator()
Utility method for creating aComparator
ofT
from aComparable
of typeT
.- Type Parameters:
T
- extends Comparable<T>- Returns:
- Comparator whose order is defined by
T
.
-
getOrder
public java.util.Comparator<? super T> getOrder()
-
take
public java.util.Iterator<T> take(int n)
Returns then
-th smallest values remaining in thisRank
.- Parameters:
n
- Number of values to return- Returns:
- An iterator containing the next
n
smallest values. - Throws:
java.util.NoSuchElementException
- if thisRank
has not enough remaining elements or whenn
is negative.
-
size
public int size()
Returns the number of remaining items in theRank
.- Returns:
- number of remaining items.
-
-