Class ListCursor<E>
java.lang.Object
org.apache.directory.api.ldap.model.cursor.AbstractCursor<E>
org.apache.directory.api.ldap.model.cursor.ListCursor<E>
- Type Parameters:
E- The element on which this cursor will iterate
- All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<E>, Cursor<E>
A simple implementation of a Cursor on a
List. Optionally, the
Cursor may be limited to a specific range within the list.- Author:
- Apache Directory Project
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ListCursor without any elements.ListCursor(int start, List<E> list) Creates a new ListCursor with a lower (inclusive) bound: the upper (exclusive) bound is the size of the list.ListCursor(int start, List<E> list, int end) Creates a new ListCursor with lower (inclusive) and upper (exclusive) bounds.ListCursor(Comparator<E> comparator) Creates a new ListCursor without any elements.ListCursor(Comparator<E> comparator, int start, List<E> list) Creates a new ListCursor with a lower (inclusive) bound: the upper (exclusive) bound is the size of the list.ListCursor(Comparator<E> comparator, int start, List<E> list, int end) Creates a new ListCursor with lower (inclusive) and upper (exclusive) bounds.ListCursor(Comparator<E> comparator, List<E> list) Creates a new ListCursor without specific bounds: the bounds are acquired from the size of the list.ListCursor(Comparator<E> comparator, List<E> list, int end) Creates a new ListCursor with a specific upper (exclusive) bound: the lower (inclusive) bound defaults to 0.ListCursor(List<E> list) Creates a new ListCursor without specific bounds: the bounds are acquired from the size of the list.ListCursor(List<E> list, int end) Creates a new ListCursor with a specific upper (exclusive) bound: the lower (inclusive) bound defaults to 0. -
Method Summary
Modifier and TypeMethodDescriptionvoidPrepares this Cursor, so a subsequent call to Cursor#previous() with a true return value, will have positioned the Cursor on a dataSet element equal to or less than the element argument but not greater.voidPositions this Cursor after the last element.booleanDetermines whether or not a call to get() will succeed.voidPrepares this Cursor, so a subsequent call to Cursor#next() with a true return value, will have positioned the Cursor on a dataSet element equal to or less than the element argument but not greater.voidPositions this Cursor before the first element.voidclose()voidCloses this Cursor and frees any resources it my have allocated.booleanfirst()Positions this Cursor at the first element.get()Gets the object at the current position.booleanIs this Cursor positioned after the last element.booleanIs this Cursor positioned before the first element.booleanisFirst()Is this Cursor positioned at the first element.booleanisLast()Is this Cursor positioned at the last element.booleanlast()Positions this Cursor at the last element.booleannext()Advances this Cursor to the next position.booleanprevious()Advances this Cursor to the previous position.Methods inherited from class AbstractCursor
checkNotClosed, isClosed, iterator, setClosureMonitor, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
ListCursor
Creates a new ListCursor with lower (inclusive) and upper (exclusive) bounds. As with all Cursors, this ListCursor requires a successful return from advance operations (next() or previous()) to properly return values using the get() operation.- Parameters:
comparator- an optional comparator to use for orderingstart- the lower bound indexlist- the list this ListCursor operates onend- the upper bound index
-
ListCursor
Creates a new ListCursor with lower (inclusive) and upper (exclusive) bounds. As with all Cursors, this ListCursor requires a successful return from advance operations (next() or previous()) to properly return values using the get() operation.- Parameters:
start- the lower bound indexlist- the list this ListCursor operates onend- the upper bound index
-
ListCursor
-
ListCursor
Creates a new ListCursor with a specific upper (exclusive) bound: the lower (inclusive) bound defaults to 0. We also provide a comparator.- Parameters:
comparator- The comparator to use for the <E> elementslist- the backing for this ListCursorend- the upper bound index representing the position after the last element
-
ListCursor
-
ListCursor
Creates a new ListCursor with a lower (inclusive) bound: the upper (exclusive) bound is the size of the list. We also provide a comparator.- Parameters:
comparator- The comparator to use for the <E> elementsstart- the lower (inclusive) bound index: the position of the first entrylist- the backing for this ListCursor
-
ListCursor
-
ListCursor
Creates a new ListCursor without specific bounds: the bounds are acquired from the size of the list. We also provide a comparator.- Parameters:
comparator- The comparator to use for the <E> elementslist- the backing for this ListCursor
-
ListCursor
public ListCursor()Creates a new ListCursor without any elements. -
ListCursor
Creates a new ListCursor without any elements. We also provide a comparator.- Parameters:
comparator- The comparator to use for the <E> elements
-
-
Method Details
-
available
public boolean available()Determines whether or not a call to get() will succeed.- Returns:
- true if a call to the get() method will succeed, false otherwise
-
before
Prepares this Cursor, so a subsequent call to Cursor#next() with a true return value, will have positioned the Cursor on a dataSet element equal to or less than the element argument but not greater. A call to Cursor#previous() with a true return value will position the Cursor on a dataSet element less than the argument. If Cursor#next() returns false then the Cursor is past the last element and so all values in the dataSet are less than the argument. If Cursor#previous() returns false then the Cursor is positioned before the first element and all elements in the dataSet are greater than the argument.- Parameters:
element- the element to be positioned before- Throws:
LdapException- if we have get any LDAP exception while operating the cursorCursorException- if there are problems advancing to this Cursor before the given element, or if this Cursor is closed
-
after
Prepares this Cursor, so a subsequent call to Cursor#previous() with a true return value, will have positioned the Cursor on a dataSet element equal to or less than the element argument but not greater. A call to Cursor#next() with a true return value will position the Cursor on a dataSet element greater than the argument. If Cursor#next() returns false then the Cursor is past the last element and so all values in the dataSet are less than or equal to the argument. If Cursor#previous() returns false then the Cursor is positioned before the first element and all elements in the dataSet are greater than the argument.- Parameters:
element- the element to be positioned after- Throws:
LdapException- if we have get any LDAP exception while operating the cursorCursorException- if there are problems advancing to this Cursor after the given element, or if this Cursor is closed
-
beforeFirst
Positions this Cursor before the first element.- Throws:
LdapException- if we have get any LDAP exception while operating the cursorCursorException- if there are problems advancing to this Cursor before the first position, or if this Cursor is closed
-
afterLast
Positions this Cursor after the last element.- Throws:
LdapException- if we have get any LDAP exception while operating the cursorCursorException- if there are problems advancing to this Cursor after the last position, or if this Cursor is closed
-
first
Positions this Cursor at the first element.- Returns:
- true if the position has been successfully changed to the first element, false otherwise
- Throws:
LdapException- if we have get any LDAP exception while operating the cursorCursorException- if there are problems advancing to this Cursor to the first position, or if this Cursor is closed
-
last
Positions this Cursor at the last element.- Returns:
- true if the position has been successfully changed to the last element, false otherwise
- Throws:
LdapException- if we have get any LDAP exception while operating the cursorCursorException- if there are problems advancing to this Cursor to the last position, or if this Cursor is closed
-
isFirst
-
isLast
-
isAfterLast
public boolean isAfterLast()Is this Cursor positioned after the last element.- Specified by:
isAfterLastin interfaceCursor<E>- Overrides:
isAfterLastin classAbstractCursor<E>- Returns:
- true if this cursor is positioned after the last element, false otherwise
-
isBeforeFirst
public boolean isBeforeFirst()Is this Cursor positioned before the first element.- Specified by:
isBeforeFirstin interfaceCursor<E>- Overrides:
isBeforeFirstin classAbstractCursor<E>- Returns:
- true if this cursor is positioned before the first element, false otherwise
-
previous
Advances this Cursor to the previous position. If called before explicitly positioning this Cursor, the position is presumed to be after the last element and this method moves the cursor back to the last element.- Returns:
- true if the advance succeeded, false otherwise
- Throws:
LdapException- if we have get any LDAP exception while operating the cursorCursorException- if there are problems advancing to this Cursor to the previous position, or if this Cursor is closed
-
next
Advances this Cursor to the next position. If called before explicitly positioning this Cursor, the position is presumed to be before the first element and this method moves the cursor forward to the first element.- Returns:
- true if the advance succeeded, false otherwise
- Throws:
LdapException- if we have get any LDAP exception while operating the cursorCursorException- if there are problems advancing to this Cursor to the next position, or if this Cursor is closed
-
get
Gets the object at the current position. Cursor implementations may choose to reuse element objects by re-populating them on advances instead of creating new objects on each advance.- Returns:
- the object at the current position
- Throws:
CursorException- if the object at this Cursor's current position cannot be retrieved, or if this Cursor is closed
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractCursor<E>- Throws:
IOException
-
close
Closes this Cursor and frees any resources it my have allocated. Repeated calls to this method after this Cursor has already been called should not fail with exceptions. The reason argument is the Exception instance thrown instead of the standard CursorClosedException.- Specified by:
closein interfaceCursor<E>- Overrides:
closein classAbstractCursor<E>- Parameters:
cause- exception thrown when this Cursor is accessed after close- Throws:
IOException- If we can't close the Cursor
-