Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.iq80.leveldb.util;
 
 
 
 public final class TableIterator extends AbstractSeekingIterator<SliceSlice>
    private final Table table;
    private final BlockIterator blockIterator;
    private BlockIterator current;
    public TableIterator(Table tableBlockIterator blockIterator)
    {
        this. = table;
        this. = blockIterator;
         = null;
    }
    @Override
    protected void seekToFirstInternal()
    {
        // reset index to before first and clear the data iterator
        .seekToFirst();
         = null;
    }
    @Override
    protected void seekInternal(Slice targetKey)
    {
        // seek the index to the block containing the key
        .seek(targetKey);
        // if indexIterator does not have a next, it mean the key does not exist in this iterator
        if (.hasNext()) {
            // seek the current iterator to the key
             = getNextBlock();
            .seek(targetKey);
        }
        else {
             = null;
        }
    }
    @Override
    protected Entry<SliceSlicegetNextElement()
    {
        // note: it must be here & not where 'current' is assigned,
        // because otherwise we'll have called inputs.next() before throwing
        // the first NPE, and the next time around we'll call inputs.next()
        // again, incorrectly moving beyond the error.
        boolean currentHasNext = false;
        while (true) {
            if ( != null) {
                currentHasNext = .hasNext();
            }
            if (!(currentHasNext)) {
                if (.hasNext()) {
                     = getNextBlock();
                }
                else {
                    break;
                }
            }
            else {
                break;
            }
        }
        if (currentHasNext) {
            return .next();
        }
        else {
            // set current to empty iterator to avoid extra calls to user iterators
             = null;
            return null;
        }
    }
    private BlockIterator getNextBlock()
    {
        Slice blockHandle = .next().getValue();
        Block dataBlock = .openBlock(blockHandle);
        return dataBlock.iterator();
    }
    @Override
    public String toString()
    {
        final StringBuilder sb = new StringBuilder();
        sb.append("ConcatenatingIterator");
        sb.append("{blockIterator=").append();
        sb.append(", current=").append();
        sb.append('}');
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X