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

/**
 * Returns the next token from this string tokenizer.
 *
 * @return the next token from this string tokenizer
 *
 * @exception NoSuchElementException  if there are no more tokens in this
 *                                    tokenizer's string
 *//*from w w w .j a va 2 s.  co m*/
public String nextToken() throws NoSuchElementException {
    if (current == max && (max == 0 || (returnTokens && delim.indexOf(str.charAt(previous)) >= 0))) {

        current++;
        return new String();
    }

    if (current >= max)
        throw new NoSuchElementException();

    int start = current;
    String result = null;

    if (delim.indexOf(str.charAt(start)) >= 0) {
        if (previous == -1
                || (returnTokens && previous != current && delim.indexOf(str.charAt(previous)) >= 0)) {

            result = new String();
        } else if (returnTokens)
            result = str.substring(start, ++current);

        if (!returnTokens)
            current++;
    }

    previous = start;
    start = current;

    if (result == null)
        while (current < max && delim.indexOf(str.charAt(current)) < 0)
            current++;

    return result == null ? str.substring(start, current) : result;
}

From source file:edu.cornell.med.icb.goby.alignments.AlignmentReaderImpl.java

private Alignments.AlignmentEntry nextEntry() {
    //      System.out.println("nextEntry");
    if (!hasNextEntry()) {
        throw new NoSuchElementException();
    }/*from w  ww . j  ava 2s  . com*/
    try {
        return nextEntryNoFilter;
    } finally {
        nextEntryNoFilter = null;
    }
    //    LOG.warn(String.format("returning entry %d/%d%n", entry.getTargetIndex(), entry.getPosition()));
}

From source file:net.lightbody.bmp.proxy.jetty.http.HttpFields.java

/** Get enumeration of header _names.
 * Returns an enumeration of strings representing the header _names
 * for this request. //from   w w  w.j  a  v a  2s . co m
 */
public Enumeration getFieldNames() {
    return new Enumeration() {
        int i = 0;
        Field field = null;

        public boolean hasMoreElements() {
            if (field != null)
                return true;
            while (i < _fields.size()) {
                Field f = (Field) _fields.get(i++);
                if (f != null && f._version == _version && f._prev == null) {
                    field = f;
                    return true;
                }
            }
            return false;
        }

        public Object nextElement() throws NoSuchElementException {
            if (field != null || hasMoreElements()) {
                String n = field._info._name;
                field = null;
                return n;
            }
            throw new NoSuchElementException();
        }
    };
}

From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java

/**
 * Removes the first element of this list, if any.
 *///from  ww  w . j  a v a 2 s  .c o m
public Object removeFirst() {
    if (_head.next() != null) {
        Object val = _head.next().value();
        removeListable(_head.next());
        return val;
    } else {
        throw new NoSuchElementException();
    }
}

From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java

/**
 * Removes the last element of this list, if any.
 *//*from w ww  .j  a  v a  2 s  .c  om*/
public Object removeLast() {
    if (_head.prev() != null) {
        Object val = _head.prev().value();
        removeListable(_head.prev());
        return val;
    } else {
        throw new NoSuchElementException();
    }
}

From source file:net.lightbody.bmp.proxy.jetty.http.HttpFields.java

/** Get multi headers
 * @return Enumeration of the values, or null if no such header.
 * @param name the case-insensitive field name
 *//*  w  w w . j a  va2s . c o m*/
public Enumeration getValues(String name) {
    FieldInfo info = getFieldInfo(name);
    final Field field = getField(info, true);

    if (field != null) {
        return new Enumeration() {
            Field f = field;

            public boolean hasMoreElements() {
                while (f != null && f._version != _version)
                    f = f._next;
                return f != null;
            }

            public Object nextElement() throws NoSuchElementException {
                if (f == null)
                    throw new NoSuchElementException();
                Field n = f;
                do
                    f = f._next;
                while (f != null && f._version != _version);
                return n._value;
            }
        };
    }
    return null;
}

From source file:edu.umd.cfar.lamp.viper.geometry.ConvexPolygon.java

public Iterator getVerteces() {
    if (edgeList == null) {
        return new Iterator() {
            public boolean hasNext() {
                return false;
            }//from  www  .  j av  a  2 s .  c o  m

            public Object next() {
                throw new NoSuchElementException();
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    } else {
        return new Iterator() {
            private Iterator iter = edgeList.iterator();

            public boolean hasNext() {
                return iter.hasNext();
            }

            public Object next() {
                return new Pnt((Pnt) iter.next());
            }

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

From source file:net.lightbody.bmp.proxy.jetty.http.HttpFields.java

/** Get multi field values with separator.
 * The multiple values can be represented as separate headers of
 * the same name, or by a single header using the separator(s), or
 * a combination of both. Separators may be quoted.
 * @param name the case-insensitive field name
 * @param separators String of separators.
 * @return Enumeration of the values, or null if no such header.
 *///from  w w  w .  jav  a  2 s  .co  m
public Enumeration getValues(String name, final String separators) {
    final Enumeration e = getValues(name);
    if (e == null)
        return null;
    return new Enumeration() {
        QuotedStringTokenizer tok = null;

        public boolean hasMoreElements() {
            if (tok != null && tok.hasMoreElements())
                return true;
            while (e.hasMoreElements()) {
                String value = (String) e.nextElement();
                tok = new QuotedStringTokenizer(value, separators, false, false);
                if (tok.hasMoreElements())
                    return true;
            }
            tok = null;
            return false;
        }

        public Object nextElement() throws NoSuchElementException {
            if (!hasMoreElements())
                throw new NoSuchElementException();
            String next = (String) tok.nextElement();
            if (next != null)
                next = next.trim();
            return next;
        }
    };
}

From source file:it.unimi.dsi.sux4j.io.ChunkedHashStore.java

/** Returns an iterator over the chunks of this chunked hash store.
 *
 * @return an iterator over the chunks of this chunked hash store.
 *///  www.jav  a 2  s.  com

public Iterator<Chunk> iterator() {
    if (closed)
        throw new IllegalStateException("This " + getClass().getSimpleName() + " has been closed ");
    for (DataOutputStream d : dos)
        try {
            d.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    int m = 0;
    for (int i = 0; i < virtualDiskChunks; i++) {
        int s = 0;
        for (int j = 0; j < diskChunkStep; j++)
            s += count[i * diskChunkStep + j];
        if (s > m)
            m = s;
    }

    final int maxCount = m;

    return new AbstractObjectIterator<Chunk>() {
        private int chunk;
        private FastBufferedInputStream fbis;
        private int last;
        private int chunkSize;
        private final long[] buffer0 = new long[maxCount];
        private final long[] buffer1 = new long[maxCount];
        private final long[] buffer2 = new long[maxCount];
        private final long[] data = hashMask != 0 ? null : new long[maxCount];

        public boolean hasNext() {
            return chunk < chunks;
        }

        @SuppressWarnings("unchecked")
        public Chunk next() {
            if (!hasNext())
                throw new NoSuchElementException();
            final long[] buffer0 = this.buffer0;

            if (chunk % (chunks / virtualDiskChunks) == 0) {
                final int diskChunk = (int) (chunk / (chunks / virtualDiskChunks));
                final long[] buffer1 = this.buffer1, buffer2 = this.buffer2;

                chunkSize = 0;
                try {
                    if (diskChunkStep == 1) {
                        fbis = new FastBufferedInputStream(new FileInputStream(file[diskChunk]));
                        chunkSize = count[diskChunk];
                    } else {
                        final FileInputStream[] fis = new FileInputStream[diskChunkStep];
                        for (int i = 0; i < fis.length; i++) {
                            fis[i] = new FileInputStream(file[diskChunk * diskChunkStep + i]);
                            chunkSize += count[diskChunk * diskChunkStep + i];
                        }
                        fbis = new FastBufferedInputStream(new SequenceInputStream(
                                new IteratorEnumeration(Arrays.asList(fis).iterator())));
                    }
                    final DataInputStream dis = new DataInputStream(fbis);

                    final long triple[] = new long[3];
                    int count = 0;
                    for (int j = 0; j < chunkSize; j++) {
                        triple[0] = dis.readLong();
                        triple[1] = dis.readLong();
                        triple[2] = dis.readLong();

                        if (DEBUG)
                            System.err.println("From disk: " + Arrays.toString(triple));

                        if (filter == null || filter.evaluate(triple)) {
                            buffer0[count] = triple[0];
                            buffer1[count] = triple[1];
                            buffer2[count] = triple[2];
                            if (hashMask == 0)
                                data[count] = dis.readLong();
                            count++;
                        } else if (hashMask == 0)
                            dis.readLong(); // Discard data
                    }

                    chunkSize = count;
                    dis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

                it.unimi.dsi.fastutil.Arrays.quickSort(0, chunkSize, new AbstractIntComparator() {
                    private static final long serialVersionUID = 0L;

                    public int compare(final int x, final int y) {
                        int t = Long.signum(buffer0[x] - buffer0[y]);
                        if (t != 0)
                            return t;
                        t = Long.signum(buffer1[x] - buffer1[y]);
                        if (t != 0)
                            return t;
                        return Long.signum(buffer2[x] - buffer2[y]);
                    }
                }, new Swapper() {
                    public void swap(final int x, final int y) {
                        final long e0 = buffer0[x], e1 = buffer1[x], e2 = buffer2[x];
                        buffer0[x] = buffer0[y];
                        buffer1[x] = buffer1[y];
                        buffer2[x] = buffer2[y];
                        buffer0[y] = e0;
                        buffer1[y] = e1;
                        buffer2[y] = e2;
                        if (hashMask == 0) {
                            final long v = data[x];
                            data[x] = data[y];
                            data[y] = v;
                        }
                    }
                });

                if (DEBUG) {
                    for (int i = 0; i < chunkSize; i++)
                        System.err.println(buffer0[i] + ", " + buffer1[i] + ", " + buffer2[i]);
                }

                if (!checkedForDuplicates && chunkSize > 1)
                    for (int i = chunkSize - 1; i-- != 0;)
                        if (buffer0[i] == buffer0[i + 1] && buffer1[i] == buffer1[i + 1]
                                && buffer2[i] == buffer2[i + 1])
                            throw new ChunkedHashStore.DuplicateException();
                if (chunk == chunks - 1)
                    checkedForDuplicates = true;
                last = 0;
            }

            final int start = last;
            while (last < chunkSize && (chunkShift == Long.SIZE ? 0 : buffer0[last] >>> chunkShift) == chunk)
                last++;
            chunk++;

            return new Chunk(buffer0, buffer1, buffer2, data, hashMask, start, last);
        }
    };
}

From source file:jp.terasoluna.fw.file.dao.standard.AbstractFileLineIterator.java

/**
 * ???<br>// w  ww  . j a  va  2  s .c  o  m
 * ??????????<br>
 * @throws FileException ??????
 */
private void buildHeader() {
    if (0 < headerLineCount) {
        for (int i = 0; i < headerLineCount; i++) {
            if (!hasNext()) {
                throw new FileException("The data which can be acquired doesn't exist.",
                        new NoSuchElementException(), fileName);
            }
            try {
                header.add(lineReader.readLine());
            } catch (FileException e) {
                throw new FileException("Error occurred by reading processing of a File.", e, fileName);
            }
        }
    }
}