List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException()
From source file:ConcurrentDoublyLinkedList.java
/** * Returns element unless it is null, in which case throws * NoSuchElementException./*from ww w .j a v a 2s . com*/ * * @param v * the element * @return the element */ private E screenNullResult(E v) { if (v == null) throw new NoSuchElementException(); return v; }
From source file:net.javacoding.queue.DiskQueue.java
/** * @see org.archive.queue.Queue#peek()/* w ww. ja va2s. co m*/ */ public Object peek() { if (isEmpty()) { throw new NoSuchElementException(); } if (headObject == null) { loadHead(); } return headObject; }
From source file:ShortPriorityQueue.java
/** * Returns the smallest element in the queue. Unlike {@link * #peekLast()}, this method throws an exception if the queue is * empty.//from w w w . ja v a2 s .co m * * @return The smallest element in the queue. * @throws IllegalArgumentException If the queue is empty. */ public E last() { if (isEmpty()) throw new NoSuchElementException(); return mElts[mSize - 1]; }
From source file:edu.berkeley.compbio.sequtils.sequencefragmentiterator.SequentialMatePairSFI.java
public SequenceFragment next() { // return theSectionList.hasNext(); // doesn't guarantee that the next NucleotideKcount is not null // we don't use a SectionSequenceFragmentIterator here, because that way we'd unnecessarily count // every section whether or not it ends up in a mate pair try {/*from ww w . j a v a 2 s.c o m*/ SequenceFragmentMetadata s1; SequenceFragmentMetadata s2 = sectionList.next(); SequenceFragment result = null; while (true) //(s2 != null) { s1 = s2; s2 = sectionList.next(); if (isMatePair(s1, s2)) { sectionList.seek(s1); SequenceFragment k1 = new SequenceFragment(s1.getParentMetadata(), s1.getSequenceName(), s1.getStartPosition(), sectionList, SequenceFragment.UNKNOWN_LENGTH, spectrumScanner); k1.checkAvailable(); //Kcount k1 = scanner.scanSequence(theSectionList, Integer.MAX_VALUE); sectionList.seek(s2); //Kcount k2 = scanner.scanSequence(theSectionList, Integer.MAX_VALUE); SequenceFragment k2 = new SequenceFragment(s1.getParentMetadata(), s1.getSequenceName(), s1.getStartPosition(), sectionList, SequenceFragment.UNKNOWN_LENGTH, spectrumScanner); k2.checkAvailable(); result = joinMatePair(k1, k2); break; } //theNextKcount = joinPotentialMatePair(s1, s2); } charactersRead += result.getLength(); return result; } catch (IOException e) { logger.error("Error", e); throw new NoSuchElementException(); } catch (NotEnoughSequenceException e) { // no problem, end of sequence throw new NoSuchElementException(); } }
From source file:edu.cornell.med.icb.goby.readers.FastXReader.java
/** * Return the next FASTA entries. This returns next FastaEntry that is * re-used for every next! Do not directly store this value as it is reused. * @return the next FastaEntry entry//from w w w.j a v a 2 s . com */ public FastXEntry next() { if (nextEntry == null) { try { readNextEntry(); if (nextEntry == null) { throw new NoSuchElementException(); } } catch (IOException e) { throw new GobyRuntimeException(e); } } final FastXEntry toReturn = nextEntry; nextEntry = null; return toReturn; }
From source file:org.dataconservancy.access.connector.HttpDcsSearchIterator.java
@Override public DcsEntity next() { try {// w w w . j a v a 2s . c o m refreshCurrentIterator(); } catch (IOException e) { log.error(e.getMessage(), e); reset(); } catch (InvalidXmlException e) { log.error(e.getMessage(), e); reset(); } if (currentItr != null) { currentIterPosition++; return currentItr.next(); } throw new NoSuchElementException(); }
From source file:com.phoenixst.plexus.traversals.BreadthFirstTraverser.java
public Object next() { LOGGER.debug("next():"); if (current != null && current.hasNext()) { LOGGER.debug(" Adding last created Traverser to end of queue."); traverserQueue.addLast(current); }//from w w w.j a v a 2 s . co m current = null; while (!traverserQueue.isEmpty()) { Traverser t = (Traverser) traverserQueue.getFirst(); LOGGER.debug(" Calling hasNext() on first Traverser in queue."); if (t.hasNext()) { Object node = t.next(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" Creating new Traverser for " + node + "."); } current = (Traverser) traverserFactory.transform(node); return node; } LOGGER.debug(" Removing first Traverser in queue."); traverserQueue.removeFirst(); } throw new NoSuchElementException(); }
From source file:com.martinkampjensen.thesis.util.gromacs.EnergyExtractor.java
/** * Reads and returns the next energy value. * //from w ww . java 2 s. c o m * @return the energy value. * @throws IllegalStateException if {@link #close()} has been called. * @throws NoSuchElementException if there are no more energy values. This * means that {@link #hasNext()} would have returned * <code>false</code> immediately before this method was called or * that an {@link IOException} occurred. */ @Override public double next() { checkState(); if (!_hasNext) { throw new NoSuchElementException(); } _nValues++; final double toReturn = _next; try { _next = readReal(_input, _useDoublePrecision); skipBytes(_input, _bytesBetweenValues); } catch (EOFException e) { _hasNext = false; } catch (IOException e) { final NoSuchElementException nsee = new NoSuchElementException(); nsee.initCause(e); try { _input.close(); } catch (IOException e2) { // Ignore second IOException. } throw nsee; } return toReturn; }
From source file:MiniMap.java
/** * @see java.util.Map#keySet()//from w ww.ja v a 2s. c om */ public Set<K> keySet() { return new AbstractSet<K>() { @Override public Iterator<K> iterator() { return new Iterator<K>() { public boolean hasNext() { return i < size - 1; } public K next() { // Just in case... (WICKET-428) if (!hasNext()) { throw new NoSuchElementException(); } // Find next key i = nextKey(nextIndex(i)); // Get key return keys[i]; } public void remove() { keys[i] = null; values[i] = null; size--; } int i = -1; }; } @Override public int size() { return size; } }; }
From source file:com.metamx.druid.indexing.common.index.StaticS3FirehoseFactory.java
@Override public Firehose connect() throws IOException { Preconditions.checkNotNull(s3Client, "null s3Client"); return new Firehose() { LineIterator lineIterator = null; final Queue<URI> objectQueue = Lists.newLinkedList(uris); // Rolls over our streams and iterators to the next file, if appropriate private void maybeNextFile() throws Exception { if (lineIterator == null || !lineIterator.hasNext()) { // Close old streams, maybe. if (lineIterator != null) { lineIterator.close(); }/*from w w w .j a v a 2s . c om*/ // Open new streams, maybe. final URI nextURI = objectQueue.poll(); if (nextURI != null) { final String s3Bucket = nextURI.getAuthority(); final S3Object s3Object = new S3Object( nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath()); log.info("Reading from bucket[%s] object[%s] (%s)", s3Bucket, s3Object.getKey(), nextURI); int ntry = 0; try { final InputStream innerInputStream = s3Client.getObject(s3Bucket, s3Object.getKey()) .getDataInputStream(); final InputStream outerInputStream = s3Object.getKey().endsWith(".gz") ? new GZIPInputStream(innerInputStream) : innerInputStream; lineIterator = IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (IOException e) { log.error(e, "Exception reading from bucket[%s] object[%s] (try %d) (sleeping %d millis)", s3Bucket, s3Object.getKey(), ntry, retryMillis); ntry++; if (ntry <= retryCount) { Thread.sleep(retryMillis); } } } } } @Override public boolean hasMore() { try { maybeNextFile(); } catch (Exception e) { throw Throwables.propagate(e); } return lineIterator != null && lineIterator.hasNext(); } @Override public InputRow nextRow() { try { maybeNextFile(); } catch (Exception e) { throw Throwables.propagate(e); } if (lineIterator == null) { throw new NoSuchElementException(); } return parser.parse(lineIterator.next()); } @Override public Runnable commit() { // Do nothing. return new Runnable() { public void run() { } }; } @Override public void close() throws IOException { objectQueue.clear(); if (lineIterator != null) { lineIterator.close(); } } }; }