Example usage for java.util NoSuchElementException NoSuchElementException

List of usage examples for java.util NoSuchElementException NoSuchElementException

Introduction

In this page you can find the example usage for java.util NoSuchElementException NoSuchElementException.

Prototype

public NoSuchElementException() 

Source Link

Document

Constructs a NoSuchElementException with null as its error message string.

Usage

From source file:CircularQueue.java

public Iterator iterator() {
    return new Iterator() {
        private final int ci = consumerIndex;
        private final int pi = producerIndex;
        private int s = size;
        private int i = ci;

        public boolean hasNext() {
            checkForModification();/*from  ww  w.  j ava 2s.  c  o m*/
            return s > 0;
        }

        public Object next() {
            checkForModification();
            if (s == 0)
                throw new NoSuchElementException();

            s--;
            Object r = q[i];
            i = (i + 1) & bitmask;

            return r;
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }

        private void checkForModification() {
            if (ci != consumerIndex)
                throw new ConcurrentModificationException();
            if (pi != producerIndex)
                throw new ConcurrentModificationException();
        }
    };
}

From source file:WrapperIterator.java

public int nextInt() {
    throw new NoSuchElementException();
}

From source file:WrapperIterator.java

public long nextLong() {
    throw new NoSuchElementException();
}

From source file:ShortPriorityQueue.java

/**
 * Returns the largest element in the queue.  Unlike {@link #peek()},
 * this method throws an exception if the queue is empty.
 *
 * @return The largest element in the queue.
 * @throws IllegalArgumentException If the queue is empty.
 *///  w ww.  j  a v a  2 s . com
public E first() {
    if (isEmpty())
        throw new NoSuchElementException();
    return mElts[0];
}

From source file:WrapperIterator.java

public void remove() {
    throw new NoSuchElementException();
}

From source file:WrapperIterator.java

public void setValue(Object value) {
    throw new NoSuchElementException();
}

From source file:com.phoenixst.plexus.traversals.DepthFirstTraverser.java

public Object next() {
    LOGGER.debug("next():");
    Traverser top = (Traverser) traverserStack.peek();
    LOGGER.debug("  Calling hasNext() on top Traverser.");
    descending = top.hasNext();/*from   ww w  .  java 2s .c o m*/
    Object node;
    if (descending) {
        LOGGER.debug("  Descending, setting current Traverser to top of stack");
        current = top;
        node = top.next();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("  Creating new Traverser for " + node + ".");
            LOGGER.debug("  Pushing node and its Traverser, return node.");
        }
        nodeStack.push(node);
        traverserStack.push(traverserFactory.transform(node));
    } else {
        LOGGER.debug("  Ascending.");
        if (nodeStack.isEmpty()) {
            throw new NoSuchElementException();
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("  Popping node and Traverser.");
            LOGGER.debug("  Setting current Traverser to top of stack.");
            LOGGER.debug("  Return node.");
        }
        traverserStack.pop();
        current = (Traverser) traverserStack.peek();
        node = nodeStack.pop();
    }
    return node;
}

From source file:com.phoenixst.plexus.traversals.PreOrderTraverser.java

public Object next() {
    LOGGER.debug("next():");
    while (!traverserStack.isEmpty()) {
        Traverser t = (Traverser) traverserStack.peek();
        LOGGER.debug("  Calling hasNext() on top Traverser of stack.");
        if (t.hasNext()) {
            current = t;/*  w w  w. j  av a2  s  .c o m*/
            Object node = current.next();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("  Setting current Traverser to top of stack.");
                LOGGER.debug("  Pushing new Traverser for " + node + " onto stack.");
            }
            traverserStack.push(traverserFactory.transform(node));
            return node;
        }
        LOGGER.debug("  Popping top Traverser off of stack.");
        traverserStack.pop();
    }
    current = null;
    throw new NoSuchElementException();
}

From source file:edu.cornell.med.icb.goby.reads.ReadsReader.java

/**
 * Returns the next read entry from the input stream.
 * TODO: The current implementation will throw an exception if this is called before hasNext
 *
 * @return the next read entry from the input stream.
 *///from w w  w  . j  a v  a 2 s.  co m
public final Reads.ReadEntry next() {
    if (!reader.hasNext(collection, collection.getReadsCount())) {
        throw new NoSuchElementException();
    }
    final Reads.ReadEntry readEntry = collection.getReads(reader.incrementEntryIndex());
    if (readEntry.hasCompressedData() && codec == null) {
        codec = CodecHelper.locateReadCodec(readEntry.getCompressedData());

    }
    if (first) {

        for (int i = 0; i < readEntry.getMetaDataCount(); i++) {
            final Reads.MetaData md = readEntry.getMetaData(i);
            metaData.put(md.getKey(), md.getValue());
        }
        first = false;
    }
    if (codec != null) {
        final Reads.ReadEntry.Builder result = codec.decode(readEntry);
        if (result != null) {
            // the codec was able to decode compressed data.
            return result.build();
        }
    }
    return readEntry;
}

From source file:eu.stratosphere.pact.runtime.resettable.SpillingResettableIterator.java

@Override
public T next() {
    if (this.next != null || hasNext()) {
        final T out = this.next;
        this.next = null;
        return out;
    } else {//from  ww w .j  a va  2s.c om
        throw new NoSuchElementException();
    }
}