Code example for Cursor

Methods: closemoveToPosition

0
    } 
 
    @Override 
    /** Closes the underlying cursor: do not try to get entities not loaded (using get) before. */ 
    public void close() { 
        cursor.close();
    } 
 
    public boolean isClosed() { 
        return cursor.isClosed();
    } 
 
    public int getLoadedCount() { 
        return loadedCount;
    } 
 
    public boolean isLoadedCompletely() { 
        return loadedCount == size;
    } 
 
    @Override 
    public boolean add(E object) {
        throw new UnsupportedOperationException();
    } 
 
    @Override 
    public void add(int location, E object) {
        throw new UnsupportedOperationException();
    } 
 
    @Override 
    public boolean addAll(Collection<? extends E> arg0) {
        throw new UnsupportedOperationException();
    } 
 
    @Override 
    public boolean addAll(int arg0, Collection<? extends E> arg1) {
        throw new UnsupportedOperationException();
    } 
 
    @Override 
    public void clear() { 
        throw new UnsupportedOperationException();
    } 
 
    @Override 
    public boolean contains(Object object) {
        loadRemaining(); 
        return entities.contains(object);
    } 
 
    @Override 
    public boolean containsAll(Collection<?> collection) {
        loadRemaining(); 
        return entities.containsAll(collection);
    } 
 
    @Override 
    public E get(int location) {
        if (entities != null) {
            E entity = entities.get(location);
            if (entity == null) {
                lock.lock();
                try { 
                    entity = entities.get(location);
                    if (entity == null) {
                        entity = loadEntity(location);
                        entities.set(location, entity);
                        // Ignore FindBugs: increment of volatile is fine here because we use a lock 
                        loadedCount++;
                        if (loadedCount == size) {
                            cursor.close();
                        } 
                    } 
                } finally { 
                    lock.unlock();
                } 
            } 
            return entity;
        } else { 
            return loadEntity(location);
        } 
    } 
 
    protected E loadEntity(int location) {
        cursor.moveToPosition(location);
        E entity = daoAccess.loadCurrent(cursor, 0, true);
        if (entity == null) {
            throw new DaoException("Loading of entity failed (null) at position " + location);
        } 
        return entity;
    }