@Immutable public class Window<T> extends Object implements Iterable<T>
List.subList(int, int)
because it allows more operations and also can tell whether either start or end is obstructed.Modifier and Type | Method and Description |
---|---|
Window<T> |
dropUntil(Predicate<T> predicate)
Drop elements that don't match the predicate.
|
Window<T> |
dropUntilElement(T expected)
Drop all the elements before the requested element.
|
static <T> Window<T> |
empty()
Create a window over an empty collection.
|
T |
first()
Returns the first element of the visible part or the only element if the visible part has only one.
|
Window<T> |
focusElement(T expected,
int radius)
Drop elements from beginning and end until there are number of elements
on both sides of the requested element.
|
List<T> |
get()
Returns the visible part
|
boolean |
hasElementsAfter()
Returns true if there are elements after the end of the visible part of the underlying collection
|
boolean |
hasElementsBefore()
Returns true if there are elements before the start of the visible part of the underlying collection
|
boolean |
isEmpty()
Checks whether the visible part is empty
|
Iterator<T> |
iterator() |
Window<T> |
keepUntil(Predicate<T> predicate)
Keep only elements that match the predicate.
|
Window<T> |
keepUntilElement(T expected)
Drop all elements after the requested element.
|
T |
last()
Returns the last element of the visible part or the only element if the visible part is has only one.
|
static <T> Window<T> |
of(Collection<T> coll)
Create a window over a whole collection
|
Window<T> |
reverse()
Return a copy of the window where all the elements are in reverse order.
|
Window<T> |
shrinkFromEnd(int size)
Drop elements from the start until the new visible part is of the requested size
|
Window<T> |
shrinkFromStart(int size)
Drop elements from the beginning until the new visible part is of the requested size
|
int |
size()
Returns the size of the visible part
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static <T> Window<T> of(Collection<T> coll)
coll
- the underlying collectionpublic static <T> Window<T> empty()
public int size()
public boolean hasElementsAfter()
public boolean hasElementsBefore()
public T first()
IndexOutOfBoundsException
- if there are no elementspublic T last()
IndexOutOfBoundsException
- if there are no elementspublic Window<T> keepUntil(Predicate<T> predicate)
public Window<T> dropUntil(Predicate<T> predicate)
public Window<T> dropUntilElement(T expected)
expected
- requested elementIllegalArgumentException
- if the requested element is not in the current visible partpublic Window<T> keepUntilElement(T expected)
expected
- requested elementIllegalArgumentException
- if the requested element is not in the current visible partpublic Window<T> focusElement(T expected, int radius)
expected
- the element that should be surroundedradius
- number of elements before and afterIllegalArgumentException
- if the requested element is not the visible partIllegalArgumentException
- if radius is less than zeropublic Window<T> shrinkFromStart(int size)
size
- requested sizepublic Window<T> shrinkFromEnd(int size)
size
- requested sizepublic boolean isEmpty()
public Window<T> reverse()
Copyright © 2002-2023 Atlassian. All Rights Reserved.