org.apache.directory.api.ldap.model.cursor
Class SetCursor<E>

java.lang.Object
  extended by org.apache.directory.api.ldap.model.cursor.AbstractCursor<E>
      extended by org.apache.directory.api.ldap.model.cursor.SetCursor<E>
Type Parameters:
E - The element on which this cursor will iterate
All Implemented Interfaces:
Iterable<E>, Cursor<E>

public class SetCursor<E>
extends AbstractCursor<E>

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

Author:
Apache Directory Project

Constructor Summary
SetCursor()
          Creates a new SetCursor without any elements.
SetCursor(Comparator<E> comparator)
          Creates a new SetCursor without any elements.
SetCursor(Comparator<E> comparator, Set<E> set)
          Creates a new SetCursor.
SetCursor(Set<E> set)
          Creates a new SetCursor As with all Cursors, this SetCursor requires a successful return from advance operations (next() or previous()) to properly return values using the get() operation.
 
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.
 void close()
          Closes this Cursor and frees any resources it my have allocated.
 void close(Exception cause)
          Closes this Cursor and frees any resources it my have allocated.
 boolean first()
          Positions this Cursor at the first element.
 E get()
          Gets the object at the current position.
 boolean isAfterLast()
          Is this Cursor positioned after the last element.
 boolean isBeforeFirst()
          Is this Cursor positioned before the first element.
 boolean isFirst()
          Is this Cursor positioned at the first element.
 boolean isLast()
          Is this Cursor positioned at the last element.
 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.
 String toString()
           
 String toString(String tabs)
          Pretty-print a cursor and its wrapped cursor.
 
Methods inherited from class org.apache.directory.api.ldap.model.cursor.AbstractCursor
checkNotClosed, isClosed, iterator, setClosureMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SetCursor

public SetCursor(Comparator<E> comparator,
                 Set<E> set)
Creates a new SetCursor. As with all Cursors, this SetCursor 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
set - the Set this StCursor operates on

SetCursor

public SetCursor(Set<E> set)
Creates a new SetCursor As with all Cursors, this SetCursor requires a successful return from advance operations (next() or previous()) to properly return values using the get() operation.

Parameters:
set - the Set this SetCursor operates on

SetCursor

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


SetCursor

public SetCursor(Comparator<E> comparator)
Creates a new SetCursor 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 a call to the get() method will succeed, false otherwise

before

public void before(E element)
            throws LdapException,
                   CursorException,
                   IOException
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
CursorException
IOException

after

public void after(E element)
           throws LdapException,
                  CursorException,
                  IOException
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
CursorException
IOException

beforeFirst

public void beforeFirst()
                 throws LdapException,
                        CursorException,
                        IOException
Positions this Cursor before the first element.

Throws:
LdapException
CursorException
IOException

afterLast

public void afterLast()
               throws LdapException,
                      CursorException,
                      IOException
Positions this Cursor after the last element.

Throws:
LdapException
CursorException
IOException

first

public boolean first()
              throws LdapException,
                     CursorException,
                     IOException
Positions this Cursor at the first element.

Returns:
true if the position has been successfully changed to the first element, false otherwise
Throws:
LdapException
CursorException
IOException

last

public boolean last()
             throws LdapException,
                    CursorException,
                    IOException
Positions this Cursor at the last element.

Returns:
true if the position has been successfully changed to the last element, false otherwise
Throws:
LdapException
CursorException
IOException

isFirst

public boolean isFirst()
Is this Cursor positioned at the first element.

Specified by:
isFirst in interface Cursor<E>
Overrides:
isFirst in class AbstractCursor<E>
Returns:
true if this cursor is positioned at the first element, false otherwise

isLast

public boolean isLast()
Is this Cursor positioned at the last element.

Specified by:
isLast in interface Cursor<E>
Overrides:
isLast in class AbstractCursor<E>
Returns:
true if this cursor is positioned at the last element, false otherwise

isAfterLast

public boolean isAfterLast()
Is this Cursor positioned after the last element.

Specified by:
isAfterLast in interface Cursor<E>
Overrides:
isAfterLast in class AbstractCursor<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:
isBeforeFirst in interface Cursor<E>
Overrides:
isBeforeFirst in class AbstractCursor<E>
Returns:
true if this cursor is positioned before the first element, false otherwise

previous

public boolean previous()
                 throws LdapException,
                        CursorException,
                        IOException
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
CursorException
IOException

next

public boolean next()
             throws LdapException,
                    CursorException,
                    IOException
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 cursor
CursorException - if there are problems advancing to this Cursor to the next position, or if this Cursor is closed
IOException - If we have had any IO Exception

get

public E get()
      throws CursorException,
             IOException
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
IOException - If we have had any IO Exception

close

public void 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.

Specified by:
close in interface Cursor<E>
Overrides:
close in class AbstractCursor<E>

close

public void close(Exception cause)
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:
close in interface Cursor<E>
Overrides:
close in class AbstractCursor<E>
Parameters:
cause - exception thrown when this Cursor is accessed after close

toString

public String toString(String tabs)
Description copied from class: AbstractCursor
Pretty-print a cursor and its wrapped cursor.

Specified by:
toString in interface Cursor<E>
Overrides:
toString in class AbstractCursor<E>
Parameters:
tabs - The spaces to add at each level
Returns:
The cursor and all it's wrapped elements, recursively printed
See Also:
Object.toString()

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2003-2013 The Apache Software Foundation. All Rights Reserved.