T
- Type of values in this Rank
.public class Rank<T>
extends java.lang.Object
This class does efficient ranking of values of type T
wrt. to a
Comparator
for T
. After creating an instance of
Rank
, the take(int)
method returns the next
k
smallest values. That is, each of these values is smaller than
every value not yet retrieved. The order of the values returned by
take
is not specified in general. However if the values are in
increasing order, the values returned by take
will also be in
increasing order.
Note: The values may not contain duplicates or the behavior
of take
is not defined.
Constructor and Description |
---|
Rank(java.util.Collection<T> values,
java.lang.Class<T> componentType,
java.util.Comparator<? super T> order)
Create a new instance of
Rank for a given collection of
values and a given order . |
Rank(java.util.Iterator<T> values,
java.lang.Class<T> componentType,
int count,
java.util.Comparator<? super T> order)
Create a new instance of
Rank for the first
count values in a a given iterator of values
and a given order . |
Rank(T[] values,
java.util.Comparator<? super T> order)
Create a new instance of
Rank for a given array of
values and a given order . |
Modifier and Type | Method and Description |
---|---|
static <T extends java.lang.Comparable<T>> |
comparableComparator()
Utility method for creating a
Comparator of T from a
Comparable of type T . |
java.util.Comparator<? super T> |
getOrder() |
static <S extends java.lang.Comparable<S>> |
rank(java.util.Collection<S> values,
java.lang.Class<S> componentType)
Create a new instance of
Rank for a given collection of
values . |
static <S extends java.lang.Comparable<S>> |
rank(java.util.Iterator<S> values,
java.lang.Class<S> componentType,
int count)
Create a new instance of
Rank for the first
count values in a a given iterator of values . |
static <S extends java.lang.Comparable<S>> |
rank(S[] values)
Create a new instance of
Rank for a given array of
values . |
int |
size()
Returns the number of remaining items in the
Rank . |
java.util.Iterator<T> |
take(int n)
Returns the
n -th smallest values remaining in this
Rank . |
public Rank(T[] values, java.util.Comparator<? super T> order)
Rank
for a given array of
values
and a given order
. The
values
are manipulated in place, no copying is performed.values
- values for ranking. Duplicates are not allowed.order
- Ordering for rankingpublic Rank(java.util.Collection<T> values, java.lang.Class<T> componentType, java.util.Comparator<? super T> order)
Rank
for a given collection of
values
and a given order
. The
values
are copied into an internal array before they are
manipulated.values
- values for ranking. Duplicates are not allowed.componentType
- type evidence for the valuesorder
- Ordering for rankingpublic Rank(java.util.Iterator<T> values, java.lang.Class<T> componentType, int count, java.util.Comparator<? super T> order)
Rank
for the first
count
values in a a given iterator of values
and a given order
. The values
are copied into
an internal array before they are manipulated.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 rankingpublic static <S extends java.lang.Comparable<S>> Rank<S> rank(S[] values)
Rank
for a given array of
values
. The order is determined by the natural ordering of
the values (i.e. through Comparable
). The values
are
manipulated in place, no copying is performed.S
- extends Comparable<S>values
- values for ranking. Duplicates are not allowed.Rank
.public static <S extends java.lang.Comparable<S>> Rank<S> rank(java.util.Collection<S> values, java.lang.Class<S> componentType)
Rank
for a given collection of
values
. The order is determined by the natural ordering of
the values (i.e. through Comparable
). The values
are
copied into an internal array before they are manipulated.S
- extends Comparable<S>values
- values for ranking. Duplicates are not allowed.componentType
- type evidence for the valuesRank
.public static <S extends java.lang.Comparable<S>> Rank<S> rank(java.util.Iterator<S> values, java.lang.Class<S> componentType, int count)
Rank
for the first
count
values in a a given iterator of values
.
The order is determined by the natural ordering of the values (i.e.
through Comparable
). The values
are copied into an
internal array before they are manipulated.S
- extends Comparable<S>values
- values for ranking. Duplicates are not allowed.componentType
- type evidence for the valuescount
- Number of items to include. -1 for all.Rank
.public static <T extends java.lang.Comparable<T>> java.util.Comparator<T> comparableComparator()
Comparator
of T
from a
Comparable
of type T
.T
- extends Comparable<T>T
.public java.util.Comparator<? super T> getOrder()
public java.util.Iterator<T> take(int n)
n
-th smallest values remaining in this
Rank
.n
- Number of values to returnn
smallest values.java.util.NoSuchElementException
- if this Rank
has not enough
remaining elements or when n
is negative.public int size()
Rank
."Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"