public interface SizedIterable<T>
extends java.lang.Iterable<T>
Iterable
which can also report the size of its contents.Modifier and Type | Interface and Description |
---|---|
static class |
SizedIterable.FixedSizedIterable<T> |
static class |
SizedIterable.SizeType |
Modifier and Type | Method and Description |
---|---|
static <T> SizedIterable<T> |
from(java.util.Collection<T> collection) |
static <T> SizedIterable<T> |
from(java.util.Collection<T> collection,
SizedIterable.SizeType sizeType) |
static <T> SizedIterable<T> |
from(java.lang.Iterable<T> iterable) |
default boolean |
isEmpty() |
static boolean |
isEmpty(SizedIterable<?> iterable) |
default int |
size() |
static int |
size(SizedIterable<?> iterable) |
default int |
sizeIfKnown() |
default SizedIterable.SizeType |
sizeType()
|
static <T> SizedIterable<T> from(java.lang.Iterable<T> iterable)
static <T> SizedIterable<T> from(java.util.Collection<T> collection)
static <T> SizedIterable<T> from(java.util.Collection<T> collection, SizedIterable.SizeType sizeType)
static int size(SizedIterable<?> iterable)
static boolean isEmpty(SizedIterable<?> iterable)
default SizedIterable.SizeType sizeType()
SizedIterable
has, which provides the guarantees that can be assumed on the
evaluation of the size()
and isEmpty()
methods.
If this method returns SizedIterable.SizeType.AVAILABLE
, size()
and isEmpty()
is guaranteed to
evaluate correct results without having to traverse the SizedIterable
.
If this method returns SizedIterable.SizeType.FIXED
, size()
and isEmpty()
is guaranteed to
evaluate to the same result for the lifetime of the SizedIterable
without having to traverse it.
If this method returns SizedIterable.SizeType.UNAVAILABLE
, size()
and isEmpty()
may require
traversal of the SizedIterable
to determine their results, and may thus be an O(n)
operation.
If this method returns SizedIterable.SizeType.INFINITE
, size()
should always throw
UnsupportedOperationException
and isEmpty()
should always return false.
default int size()
default int sizeIfKnown()
SizedIterable
if known a-priori, or -1 if the size is not known.default boolean isEmpty()