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(String s) 

Source Link

Document

Constructs a NoSuchElementException , saving a reference to the error message string s for later retrieval by the getMessage method.

Usage

From source file:it.drwolf.ridire.util.JumpToLine.java

/**
 * Seeks to a given line number in a file.
 * //from   w w  w . j a  v  a2s  .c  o m
 * @param line
 */
public long seek(long line) {
    long lineCount = 1L;
    while (this.it_ != null && this.it_.hasNext() && lineCount < line) {
        this.it_.nextLine();
        lineCount += 1L;
    }
    // If we got to the end of the file, but haven't read as many
    // lines as we should have, then the requested line number is
    // out of range.
    if (lineCount < line) {
        throw new NoSuchElementException("Invalid line number; " + "out of range.");
    }
    this.lastLineRead_ = lineCount;
    return lineCount;
}

From source file:fr.cs.examples.KeyValueFileParser.java

/** Get a raw string value from a parameters map.
 * @param key parameter key/*from w  w w .  jav  a 2  s .c  om*/
 * @return string value corresponding to the key
 * @exception NoSuchElementException if key is not in the map
 */
public String getString(final Key key) throws NoSuchElementException {
    final String value = map.get(key);
    if (value == null) {
        throw new NoSuchElementException(key.toString());
    }
    return value.trim();
}

From source file:ShortPriorityQueue.java

/**
 * Returns the largest element in this queue according to
 * the comparator, throwing an exception if the queue is
 * empty./*www . j  ava2  s  . c o  m*/
 *
 * <p>This method differs from {@link #peek()} only in
 * that it throws an exception if the queue is empty
 * rather than returning {@code null}.
 *
 * @return The largest element in this queue.
 * @throws NoSuchElementException If the queue is empty.
 */
public E element() {
    E result = peek();
    if (result == null)
        throw new NoSuchElementException("");
    return result;
}

From source file:com.github.javaplugs.mybatis.JsonNodeValue.java

/**
 * Return JSON node value (will parse node from string at first call).
 * WARNING if object constructed using JSON as string, and this string is invalid,
 * that exception will be thrown.//  w  w  w.  j  a  va 2  s .  com
 *
 * @return Not null value.
 * @throws NoSuchElementException if value is not present.
 * @throws RuntimeException On JSON parsing errors.
 */
public JsonNode get() throws NoSuchElementException, RuntimeException {
    if (!isPresent()) {
        throw new NoSuchElementException("No value present");
    }

    if (value == null) {
        synchronized (this) {
            if (value == null) {
                try {
                    value = ReaderWriter.readTree(source);
                } catch (Exception ex) {
                    throw new RuntimeException("Can not parse JSON string. " + ex.getMessage(), ex);
                }
            }
        }
    }
    return value;
}

From source file:com.sampas.socbs.core.data.arcsde.impl.ArcSDEPooledConnection.java

public synchronized SeLayer getLayer(final String layerName) throws DataSourceException {
    checkActive();/*from w w  w .j  av  a2 s.c om*/
    if (!cachedLayers.containsKey(layerName)) {
        try {
            cacheLayers();
        } catch (SeException e) {
            throw new DataSourceException("Can't obtain layer " + layerName, e);
        }
    }
    SeLayer seLayer = (SeLayer) cachedLayers.get(layerName);
    if (seLayer == null) {
        throw new NoSuchElementException("Layer '" + layerName + "' not found");
    }
    return seLayer;
}

From source file:FileSerializeCollection.java

public Iterator<Type> iterator() {
    try {/*from   www. j  a  v a2s.  co  m*/
        oos.flush();
        return new Iterator<Type>() {

            private Type next = null;

            private final ObjectInputStream ois = new ObjectInputStream(
                    new BufferedInputStream(new FileInputStream(file)));

            @SuppressWarnings("unchecked")
            public boolean hasNext() {
                try {
                    if (next == null) {
                        next = (Type) ois.readObject();
                    }
                } catch (final EOFException eof) {
                    // do not report exception
                } catch (final Exception e) {
                    System.err.println(e);
                }

                try {
                    if (next == null) {
                        ois.close();
                    }
                } catch (final IOException io) {
                    System.err.println(io);
                }

                return (next != null);
            }

            public Type next() {
                if (hasNext()) {
                    final Type ret = next;
                    next = null;
                    return ret;
                }
                throw new NoSuchElementException("No more elements");
            }

            public void remove() {
                throw new UnsupportedOperationException("remove not supported in DumpSet$iterator()");
            }
        };
    } catch (final IOException io) {
        System.err.println(io);
    }
    return null;
}

From source file:info.rmarcus.birkhoffvonneumann.MatrixUtils.java

private static Iterator<BitSet> bitStringsOfSize(int n) {
    return new Iterator<BitSet>() {
        private BigInteger b = new BigInteger("0");

        @Override/*from  w ww.  j a  v  a  2s.com*/
        public boolean hasNext() {
            return b.compareTo((new BigInteger("2")).pow(n)) < 0;
        }

        @Override
        public @NonNull BitSet next() {
            byte[] bytes = b.toByteArray();
            BitSet toR = BitSet.valueOf(bytes);
            BigInteger nxt = b.add(new BigInteger("1"));
            if (nxt == null || toR == null) {
                throw new NoSuchElementException("Unable to increment big int");
            }
            b = nxt;
            return toR;
        }

    };
}

From source file:eu.crisis_economics.configuration.FromFileConfigurationContext.java

public DefinitionExpression tryGetDefinitionExpression(String literalName) {
    if (!hasDefinitionExpression(literalName))
        throw new NoSuchElementException("'" + literalName + "' has not been defined.");
    return knownDefinitions.get(literalName);
}

From source file:edu.berkeley.compbio.sequtils.sequencefragmentiterator.StubSFI.java

@NotNull
public SequenceFragment next()//Supplies the next read
{
    //assert length == 50;  // test methods should request this
    assert initialized;
    try {//w ww . jav a2  s  .c  o  m
        if (pos >= 14) {
            throw new NoSuchElementException("No more sequences");
        }
        SequenceFragment result = new SequenceFragment(null, "Seq " + pos, 0, sections.get(pos), 50,
                spectrumScanner);
        result.checkAvailable();
        //         Kcount result = theScanner.scanSequence(sections.get(pos), 50);
        //         result.getMetadata().setSequenceName("Seq " + pos);
        charactersRead += result.getLength();
        pos++;
        result.doneLabelling();
        return result;
    } catch (NotEnoughSequenceException e) {
        logger.error("Error", e);
        assert false;
    }
    //   assert false;
    throw new NoSuchElementException();
}

From source file:com.francetelecom.clara.cloud.commons.MavenReference.java

/**
 * Construct a MavenReference from a gav String
 * @param gav/*from  www  . j  a  va 2 s  . c o m*/
 *            format : Group:artifact:version:[classifier:[extension]]
 * @return Corresponding maven reference
 */
public static MavenReference fromGavString(String gav) {
    MavenReference resultMavenRef;

    if (gav == null || gav.length() < 5) {
        throw new IllegalArgumentException("String gav cannot be null nor empty");
    }
    StringTokenizer gavTokenizer = new StringTokenizer(gav, ":", true);
    try {
        String groupId = gavTokenizer.nextToken();
        if (":".equals(groupId)) {
            throw new NoSuchElementException("Missing groupId");
        }
        gavTokenizer.nextToken();
        String artifactId = gavTokenizer.nextToken();
        if (":".equals(artifactId)) {
            throw new NoSuchElementException("Missing artifactId");
        }
        gavTokenizer.nextToken();
        String version = gavTokenizer.nextToken();
        if (":".equals(version)) {
            throw new NoSuchElementException("Missing version");
        }
        if (gavTokenizer.hasMoreTokens()) {
            gavTokenizer.nextToken();
        }

        resultMavenRef = new MavenReference(groupId, artifactId, version);
        if (gavTokenizer.hasMoreTokens()) {
            String classifier = gavTokenizer.nextToken();
            if (!":".equals(classifier)) {
                resultMavenRef.setClassifier(classifier);
                if (gavTokenizer.hasMoreTokens()) {
                    gavTokenizer.nextToken();
                }
            }
        }

        if (gavTokenizer.hasMoreTokens()) {
            String extension = gavTokenizer.nextToken();
            if (!":".equals(extension)) {
                resultMavenRef.setExtension(extension);
            }
        }

    } catch (NoSuchElementException nsee) {
        throw new IllegalArgumentException(
                "Wrong format, should be groupId:artifactId:version:[classifier:[extension]]");
    }

    return resultMavenRef;

}