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:SortedMultiSet.java

public Iterator<Type> iterator() {
    return new Iterator<Type>() {
        int idx = 0;

        public boolean hasNext() {
            return idx < size;
        }/*from   ww w  . j a va2 s  .  com*/

        public Type next() {
            if (hasNext()) {
                return field[idx++];
            }
            throw new NoSuchElementException();
        }

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

    };
}

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

@Override
public T next() {
    if (this.nextElement == null) {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }/*from  ww  w .j  a  va  2 s  .co  m*/
    }

    T out = this.nextElement;
    this.nextElement = null;
    return out;
}

From source file:com.hp.application.automation.tools.octane.tests.TestResultIterator.java

@Override
public JUnitTestResult next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }//from www .j a v a2  s .com
    return items.removeFirst();
}

From source file:com.github.jillesvangurp.osm2geojson.OsmBlobIterable.java

@Override
public Iterator<String> iterator() {

    final Iterator<String> it = lineIterable.iterator();
    return new Iterator<String>() {
        String next = null;//from www.  jav  a2 s . c  o  m
        StringBuilder buf = new StringBuilder();

        @Override
        public boolean hasNext() {
            if (next != null) {
                return true;
            } else {
                String line;
                while (it.hasNext() && next == null) {
                    line = it.next();
                    if (line.length() > 0) {
                        String stripped = StringUtils.strip(line);
                        if (stripped.startsWith("<node")) {
                            buf.delete(0, buf.length());
                            buf.append(line);
                            if (!fastEndsWith(stripped, "/>")) {
                                while (!fastEndsWith(StringUtils.strip(line), "</node>")) {
                                    line = it.next();
                                    buf.append(line);
                                }
                            }
                            next = StringUtils.strip(buf.toString());
                        } else if (stripped.startsWith("<way")) {
                            buf.delete(0, buf.length());
                            buf.append(line);
                            if (!fastEndsWith(line, "/>")) {
                                while (!fastEndsWith(StringUtils.strip(line), "</way>")) {
                                    line = it.next();
                                    buf.append(line);
                                }
                            }
                            next = StringUtils.strip(buf.toString());
                        } else if (stripped.startsWith("<relation")) {
                            buf.delete(0, buf.length());
                            buf.append(line);
                            if (!fastEndsWith(line, "/>")) {
                                while (!fastEndsWith(StringUtils.strip(line), "</relation>")) {
                                    line = it.next();
                                    buf.append(line);
                                }
                            }
                            next = StringUtils.strip(buf.toString());
                        }
                    }
                }
                return next != null;
            }
        }

        @Override
        public String next() {
            if (hasNext()) {
                String result = next;
                next = null;
                return result;
            } else {
                throw new NoSuchElementException();
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Remove is not supported");
        }
    };
}

From source file:dk.statsbiblioteket.doms.integration.summa.SummaRecordIterator.java

/**
 * @throws DOMSCommunicationError// ww  w  .  j ava  2 s  .c  om
 *             if the operation fails due to a communication or server
 *             error.
 * @see java.util.Iterator#next()
 */
public Record next() {
    if (log.isTraceEnabled()) {
        log.trace("next(): Entering.");
    }

    // The hasNext() method will ensure that the BaseRecordDescription cache
    // is re-filled if necessary/possible.
    if (!hasNext()) {
        throw new NoSuchElementException();
    }

    // Get the next RecordDescription from the cache.
    final BaseRecordDescription baseRecordDescription = getNextBaseRecordDescription();
    try {
        // Build a Record and return it.
        final Record nextRecord = buildRecord(baseRecordDescription);

        if (log.isTraceEnabled()) {
            log.trace("next(): Returning record: " + nextRecord);
        }
        return nextRecord;
    } catch (ServerOperationFailed serverOperationFailed) {
        // The Record could not be built due to a communication/server
        // error. Push back the BaseRecordDescription and hope for success
        // later.

        pushBackBaseRecordDescription(baseRecordDescription);
        throw new DOMSCommunicationError(
                "next() operation failed for base ID: " + baseRecordDescription.getSummaBaseID(),
                serverOperationFailed);
    }
}

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

public Object next() {
    LOGGER.debug("next():");
    Traverser top = (Traverser) traverserStack.peek();

    LOGGER.debug("  Calling hasNext() on top Traverser.");
    if (!top.hasNext()) {
        LOGGER.debug("  Top Traverser has nothing left to return.");
        if (nodeStack.isEmpty()) {
            throw new NoSuchElementException();
        }/* www  . j a va  2 s.c  o  m*/
        LOGGER.debug("  Popping top Traverser and top node, returning the node.");
        traverserStack.pop();
        return nodeStack.pop();
    }

    while (true) {
        Object node = top.next();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("  Creating new Traverser for " + node + ".");
        }
        top = (Traverser) traverserFactory.transform(node);
        if (!top.hasNext()) {
            LOGGER.debug("  Node is a leaf, return it.");
            return node;
        }
        LOGGER.debug("  Node is not a leaf, push it and push its Traverser.");
        nodeStack.push(node);
        traverserStack.push(top);
    }
}

From source file:la.alsocan.jsonshapeshifter.Transformation.java

/**
 * Iterates through the target schema to look for {@link SchemaNode} still requiring a 
 * binding. This iterates through the nodes of the target schema but skips those which 
 * already have a binding defined as well as <i>object</i> and <i>null</i> nodes (which
 * do not require any binding).<br>
 * <br>/* w  w  w  .  ja va2  s  . com*/
 * When {@link Iterator#hasNext()} returns <code>false</code>, the transformation can 
 * be considered fully defined (and invoking {@link #apply(JsonNode)} is safe).
 * 
 * @return An iterator for all target {@link SchemaNode} still requiring a binding
 */
public Iterator<SchemaNode> toBind() {

    final Iterator<SchemaNode> itNodes = target.iterator();
    return new Iterator<SchemaNode>() {

        private SchemaNode remainingNode = getNextNode();

        @Override
        public boolean hasNext() {
            return remainingNode != null;
        }

        @Override
        public SchemaNode next() {
            if (remainingNode == null) {
                throw new NoSuchElementException();
            }
            SchemaNode toReturn = remainingNode;
            remainingNode = getNextNode();
            return toReturn;
        }

        private SchemaNode getNextNode() {
            SchemaNode node = null;
            do {
                if (!itNodes.hasNext()) {
                    return null;
                }
                node = itNodes.next();
            } while (bindings.containsKey(node) || ENodeType.OBJECT.equals(node.getType())
                    || ENodeType.NULL.equals(node.getType()));
            return node;
        }
    };
}

From source file:data.io.csv.CSVDataReader.java

/**
 * {@inheritDoc}/*from w w  w.  j  av a 2s  . c o  m*/
 */
@Override
public MVDataEntry next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    // Pop the lookahead record
    MVDataEntry res = nextEntry;
    nextEntry = null;
    // And return it
    return res;
}

From source file:com.boundlessgeo.geoserver.api.controllers.ApiController.java

protected FileItemIterator doFileUpload(final HttpServletRequest request)
        throws FileUploadException, IOException {
    final ServletFileUpload upload = newFileUpload();
    //Delegate FileItemIterator to only return files
    return new FileItemIterator() {
        FileItemIterator delegate = upload.getItemIterator(request);
        FileItemStream next = null;/*from  w w w . j a  v a2 s  .c  o m*/

        @Override
        public boolean hasNext() throws FileUploadException, IOException {
            if (next != null) {
                return true;
            }
            while (delegate.hasNext()) {
                FileItemStream item = delegate.next();
                if (!item.isFormField()) {
                    next = item;
                    break;
                }
            }
            return next != null;
        }

        @Override
        public FileItemStream next() throws FileUploadException, IOException {
            if (hasNext()) {
                FileItemStream current = next;
                next = null;
                return current;
            }
            throw new NoSuchElementException();
        }
    };
}

From source file:com.opengamma.util.timeseries.fast.integer.object.FastMapIntObjectTimeSeries.java

@Override
public T getValueFast(final int time) {
    T value = _map.get(time);/*from  w  w w .jav  a 2s  .c  o  m*/
    if (value == _defaultReturnValue) {
        throw new NoSuchElementException();
    }
    return value;
}