org.hsqldb.lib.HsqlLinkedList

Here are the examples of the java api org.hsqldb.lib.HsqlLinkedList taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

18 Source : RowSetNavigatorLinkedList.java
with GNU General Public License v3.0
from s-store

/*
 * All-in-memory implementation of RowSetNavigator for simple client or server
 * side result sets. These are the result sets used for batch or other internal
 * operations.
 *
 * @author Fred Toussi (fredt@users dot sourceforge.net)
 * @version 1.9.0
 * @since 1.9.0
 */
public clreplaced RowSetNavigatorLinkedList extends RowSetNavigator {

    HsqlLinkedList list;

    final Node root;

    Node previous;

    Node current;

    public RowSetNavigatorLinkedList() {
        list = new HsqlLinkedList();
        root = list.getHeadNode();
        current = root;
    }

    /**
     * Returns the current row object. Type of object is implementation defined.
     */
    public Object[] getCurrent() {
        return ((Row) current.data).getData();
    }

    public Row getCurrentRow() {
        return (Row) current.data;
    }

    public void remove() {
        // avoid consecutive removes without next()
        if (previous == null) {
            throw new NoSuchElementException();
        }
        if (currentPos < size && currentPos != -1) {
            list.removeAfter(previous);
            current = previous;
            size--;
            currentPos--;
            return;
        }
        throw new NoSuchElementException();
    }

    public boolean next() {
        boolean result = super.next();
        if (result) {
            previous = current;
            current = current.next;
        }
        return result;
    }

    public void reset() {
        super.reset();
        current = root;
        previous = null;
    }

    // reading and writing
    public void write(RowOutputInterface out, ResultMetaData meta) throws IOException {
        beforeFirst();
        out.writeLong(id);
        out.writeInt(size);
        // offset
        out.writeInt(0);
        out.writeInt(size);
        while (hasNext()) {
            Object[] data = getNext();
            out.writeData(meta.getColumnCount(), meta.columnTypes, data, null, null);
        }
        beforeFirst();
    }

    public void read(RowInputInterface in, ResultMetaData meta) throws IOException {
        id = in.readLong();
        int count = in.readInt();
        // offset
        in.readInt();
        // size again
        in.readInt();
        while (count-- > 0) {
            add(in.readData(meta.columnTypes));
        }
    }

    public void clear() {
        reset();
        list.clear();
        size = 0;
    }

    /**
     *  Method declaration
     *
     * @param  d
     */
    public void add(Object d) {
        list.add(d);
        size++;
    }
}