Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*-
  * See the file LICENSE for redistribution information.
  *
  * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
  *
  */
 
 package com.sleepycat.persist;
 
Implements Iterator for an arbitrary EntityCursor.

Author(s):
Mark Hayes
class BasicIterator<V> implements Iterator<V> {
    private EntityCursor<V> entityCursor;
    private ForwardCursor<V> forwardCursor;
    private LockMode lockMode;
    private V nextValue;

    
An EntityCursor is given and the remove() method is supported.
    BasicIterator(EntityCursor<V> entityCursorLockMode lockMode) {
        this. = entityCursor;
        this. = entityCursor;
        this. = lockMode;
    }

    
A ForwardCursor is given and the remove() method is not supported.
    BasicIterator(ForwardCursor<V> forwardCursorLockMode lockMode) {
        this. = forwardCursor;
        this. = lockMode;
    }
    public boolean hasNext() {
        if ( == null) {
            try {
                 = .next();
            } catch (DatabaseException e) {
                throw RuntimeExceptionWrapper.wrapIfNeeded(e);
            }
            return  != null;
        } else {
            return true;
        }
    }
    public V next() {
        if (hasNext()) {
            V v = ;
             = null;
            return v;
        } else {
            throw new NoSuchElementException();
        }
    }
    public void remove() {
        if ( == null) {
            throw new UnsupportedOperationException();
        }
        try {
            if (!.delete()) {
                throw new IllegalStateException
                    ("Record at cursor position is already deleted");
            }
        } catch (DatabaseException e) {
            throw RuntimeExceptionWrapper.wrapIfNeeded(e);
        }
    }
New to GrepCode? Check out our FAQ X