org.apache.directory.shared.ldap.cursor
Class ListCursor<E>

java.lang.Object
  extended by org.apache.directory.shared.ldap.cursor.AbstractCursor<E>
      extended by org.apache.directory.shared.ldap.cursor.ListCursor<E>
All Implemented Interfaces:
java.lang.Iterable<E>, Cursor<E>

public class ListCursor<E>
extends AbstractCursor<E>

A simple implementation of a Cursor on a List. Optionally, the Cursor may be limited to a specific range within the list.

Version:
$Rev$, $Date$
Author:
Apache Directory Project

Constructor Summary
ListCursor()
          Creates a new ListCursor without any elements.
ListCursor(java.util.Comparator<E> comparator)
          Creates a new ListCursor without any elements.
ListCursor(java.util.Comparator<E> comparator, int start, java.util.List<E> list)
          Creates a new ListCursor with a lower (inclusive) bound: the upper (exclusive) bound is the size of the list.
ListCursor(java.util.Comparator<E> comparator, int start, java.util.List<E> list, int end)
          Creates a new ListCursor with lower (inclusive) and upper (exclusive) bounds.
ListCursor(java.util.Comparator<E> comparator, java.util.List<E> list)
          Creates a new ListCursor without specific bounds: the bounds are acquired from the size of the list.
ListCursor(java.util.Comparator<E> comparator, java.util.List<E> list, int end)
          Creates a new ListCursor with a specific upper (exclusive) bound: the lower (inclusive) bound defaults to 0.
ListCursor(int start, java.util.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, java.util.List<E> list, int end)
          Creates a new ListCursor with lower (inclusive) and upper (exclusive) bounds.
ListCursor(java.util.List<E> list)
          Creates a new ListCursor without specific bounds: the bounds are acquired from the size of the list.
ListCursor(java.util.List<E> list, int end)
          Creates a new ListCursor with a specific upper (exclusive) bound: the lower (inclusive) bound defaults to 0.
 
Method Summary
 void after(E element)
          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.
 void afterLast()
          Positions this Cursor after the last element.
 boolean available()
          Determines whether or not a call to get() will succeed.
 void before(E element)
          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.
 void beforeFirst()
          Positions this Cursor before the first element.
 boolean first()
          Positions this Cursor at the first element.
 E get()
          Gets the object at the current position.
 boolean isAfterLast()
          
 boolean isBeforeFirst()
          
 boolean isElementReused()
          Gets whether or not this Cursor will return the same element object instance on get() operations for any position of this Cursor.
 boolean isFirst()
          
 boolean isLast()
          
 boolean last()
          Positions this Cursor at the last element.
 boolean next()
          Advances this Cursor to the next position.
 boolean previous()
          Advances this Cursor to the previous position.
 
Methods inherited from class org.apache.directory.shared.ldap.cursor.AbstractCursor
checkNotClosed, close, close, isClosed, iterator, setClosureMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListCursor

public ListCursor(java.util.Comparator<E> comparator,
                  int start,
                  java.util.List<E> list,
                  int end)
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 ordering
start - the lower bound index
list - the list this ListCursor operates on
end - the upper bound index

ListCursor

public ListCursor(int start,
                  java.util.List<E> list,
                  int end)
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 index
list - the list this ListCursor operates on
end - the upper bound index

ListCursor

public ListCursor(java.util.List<E> list,
                  int end)
Creates a new ListCursor with a specific upper (exclusive) bound: the lower (inclusive) bound defaults to 0.

Parameters:
list - the backing for this ListCursor
end - the upper bound index representing the position after the last element

ListCursor

public ListCursor(java.util.Comparator<E> comparator,
                  java.util.List<E> list,
                  int end)
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 elements
list - the backing for this ListCursor
end - the upper bound index representing the position after the last element

ListCursor

public ListCursor(int start,
                  java.util.List<E> list)
Creates a new ListCursor with a lower (inclusive) bound: the upper (exclusive) bound is the size of the list.

Parameters:
start - the lower (inclusive) bound index: the position of the first entry
list - the backing for this ListCursor

ListCursor

public ListCursor(java.util.Comparator<E> comparator,
                  int start,
                  java.util.List<E> list)
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 elements
start - the lower (inclusive) bound index: the position of the first entry
list - the backing for this ListCursor

ListCursor

public ListCursor(java.util.List<E> list)
Creates a new ListCursor without specific bounds: the bounds are acquired from the size of the list.

Parameters:
list - the backing for this ListCursor

ListCursor

public ListCursor(java.util.Comparator<E> comparator,
                  java.util.List<E> list)
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 elements
list - the backing for this ListCursor

ListCursor

public ListCursor()
Creates a new ListCursor without any elements.


ListCursor

public ListCursor(java.util.Comparator<E> comparator)
Creates a new ListCursor without any elements. We also provide a comparator.

Parameters:
comparator - The comparator to use for the elements
Method Detail

available

public boolean available()
Determines whether or not a call to get() will succeed.

Returns:
true if the cursor is valid get() will succeed, false otherwise

before

public void before(E element)
            throws java.lang.Exception
Description copied from interface: Cursor
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:
java.lang.IllegalStateException - if the underlying list is not sorted and/or a comparator is not provided.
java.lang.Exception - with problems accessing the underlying btree
java.lang.UnsupportedOperationException - if this method is not supported

after

public void after(E element)
           throws java.lang.Exception
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:
java.lang.Exception - if there are problems positioning this cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

beforeFirst

public void beforeFirst()
                 throws java.lang.Exception
Positions this Cursor before the first element.

Throws:
java.lang.Exception - if there are problems positioning this cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

afterLast

public void afterLast()
               throws java.lang.Exception
Positions this Cursor after the last element.

Throws:
java.lang.Exception - if there are problems positioning this Cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

first

public boolean first()
              throws java.lang.Exception
Positions this Cursor at the first element.

Returns:
true if the position has been successfully changed to the first element, false otherwise
Throws:
java.lang.Exception - if there are problems positioning this Cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

last

public boolean last()
             throws java.lang.Exception
Positions this Cursor at the last element.

Returns:
true if the position has been successfully changed to the last element, false otherwise
Throws:
java.lang.Exception - if there are problems positioning this Cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

isFirst

public boolean isFirst()
                throws java.lang.Exception

Throws:
java.lang.Exception

isLast

public boolean isLast()
               throws java.lang.Exception

Throws:
java.lang.Exception

isAfterLast

public boolean isAfterLast()
                    throws java.lang.Exception

Throws:
java.lang.Exception

isBeforeFirst

public boolean isBeforeFirst()
                      throws java.lang.Exception

Throws:
java.lang.Exception

previous

public boolean previous()
                 throws java.lang.Exception
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:
java.lang.Exception - if there are problems advancing to the next position
java.lang.UnsupportedOperationException - if this method is not supported

next

public boolean next()
             throws java.lang.Exception
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:
java.lang.Exception - if there are problems advancing to this Cursor to the next position, or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

get

public E get()
      throws java.lang.Exception
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:
java.lang.Exception - if the object at this Cursor's current position cannot be retrieved, or if this Cursor is closed

isElementReused

public boolean isElementReused()
Gets whether or not this Cursor will return the same element object instance on get() operations for any position of this Cursor. Some Cursor implementations may reuse the same element copying values into it for every position rather than creating and emit new element objects on each advance. Some Cursor implementations may return different elements for each position yet the same element instance is returned for the same position. In these cases this method should return true.

Returns:
true if elements are reused by this Cursor


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.