public final class Cursors extends Object
Modifier and Type | Method and Description |
---|---|
static <T> Cursor<T> |
concat(Cursor<? extends T>... cursors)
Concatenate cursors.
|
static <T> Cursor<T> |
concat(Iterable<? extends Cursor<? extends T>> cursors)
Concatenate cursors.
|
static <T> Cursor<T> |
consume(int n,
Cursor<T> cursor)
Consume and discard the first
n elements from a cursor. |
static <T> Cursor<T> |
empty()
Create an empty cursor.
|
static <T> Cursor<T> |
filter(Cursor<?> cursor,
Class<T> type)
Filter a cursor to only contain elements of type type.
|
static <T> Cursor<T> |
filter(Cursor<T> cursor,
Predicate<? super T> predicate)
Filter a cursor.
|
static <T> ArrayList<T> |
makeList(Cursor<? extends T> cursor)
Read a cursor into a list, closing when it is finished.
|
static <T> Cursor<T> |
of(T... contents)
Create a cursor over a fixed set of elements.
|
static <T> Cursor<T> |
sort(Cursor<T> cursor,
Comparator<? super T> comp)
Sort a cursor.
|
static <S,T> Cursor<T> |
transform(Cursor<S> cursor,
Function<? super S,? extends T> function)
Transform a cursor's values.
|
static <T> Cursor<T> |
wrap(Collection<? extends T> collection)
Wrap a collection in a cursor.
|
static <T> Cursor<T> |
wrap(Iterator<? extends T> iterator)
Wrap an iterator in a cursor.
|
public static <T> Cursor<T> wrap(Iterator<? extends T> iterator)
T
- The type of data to return.iterator
- An iterator to wrappublic static <T> Cursor<T> wrap(Collection<? extends T> collection)
T
- The type of data to return.collection
- A collection to wrappublic static <T> Cursor<T> filter(@WillCloseWhenClosed Cursor<T> cursor, Predicate<? super T> predicate)
T
- The type of cursor rows.cursor
- The source cursor.predicate
- A predicate indicating which rows to return.true
.public static <T> Cursor<T> filter(@WillCloseWhenClosed Cursor<?> cursor, Class<T> type)
filter(Cursor, Predicate)
with a predicate from
Predicates.instanceOf(Class)
, this method also transforms the
cursor to be of the target type.T
- The type of value in the cursor.cursor
- The source cursor.type
- The type to filter.public static <T> Cursor<T> consume(int n, Cursor<T> cursor)
n
elements from a cursor.T
- The cursor's element type.n
- The number of elements to drop.cursor
- The cursor.cursor
is modified.public static <S,T> Cursor<T> transform(@WillCloseWhenClosed Cursor<S> cursor, Function<? super S,? extends T> function)
S
- The type of source cursor rowsT
- The type of output cursor rowscursor
- The source cursorfunction
- A function to apply to each row in the cursor.public static <T> Cursor<T> empty()
T
- The type of value in the cursor.public static <T> ArrayList<T> makeList(@WillClose Cursor<? extends T> cursor)
T
- The type of item in the cursor.cursor
- The cursor.Cursor.getRowCount()
if possible,
but has not been trimmed.public static <T> Cursor<T> sort(@WillClose Cursor<T> cursor, Comparator<? super T> comp)
T
- The type of value in the cursor.cursor
- The cursor to sort.comp
- The comparator to use to sort the cursor.public static <T> Cursor<T> of(T... contents)
T
- The data type.contents
- The contents.public static <T> Cursor<T> concat(Iterable<? extends Cursor<? extends T>> cursors)
T
- The type of data.cursors
- The cursors to concatenate.public static <T> Cursor<T> concat(Cursor<? extends T>... cursors)
concat(Iterable)