Search in sources :

Example 21 with NoSuchElementException

use of java.util.NoSuchElementException in project checkstyle by checkstyle.

the class XdocsPagesTest method validateStyleModules.

private static void validateStyleModules(Set<Node> checks, Set<Node> configs, Set<String> styleChecks, String fileName, String ruleName) {
    final Iterator<Node> itrChecks = checks.iterator();
    final Iterator<Node> itrConfigs = configs.iterator();
    while (itrChecks.hasNext()) {
        final Node module = itrChecks.next();
        final String moduleName = module.getTextContent().trim();
        if (!module.getAttributes().getNamedItem("href").getTextContent().startsWith("config_")) {
            continue;
        }
        Assert.assertTrue(fileName + " rule '" + ruleName + "' module '" + moduleName + "' shouldn't end with 'Check'", !moduleName.endsWith("Check"));
        styleChecks.remove(moduleName);
        for (String configName : new String[] { "config", "test" }) {
            Node config = null;
            try {
                config = itrConfigs.next();
            } catch (NoSuchElementException ignore) {
                Assert.fail(fileName + " rule '" + ruleName + "' module '" + moduleName + "' is missing the config link: " + configName);
            }
            Assert.assertEquals(fileName + " rule '" + ruleName + "' module '" + moduleName + "' has mismatched config/test links", configName, config.getTextContent().trim());
            final String configUrl = config.getAttributes().getNamedItem("href").getTextContent();
            if ("config".equals(configName)) {
                final String expectedUrl = "https://github.com/search?q=" + "path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+" + "repo%3Acheckstyle%2Fcheckstyle+" + moduleName;
                Assert.assertEquals(fileName + " rule '" + ruleName + "' module '" + moduleName + "' should have matching " + configName + " url", expectedUrl, configUrl);
            } else if ("test".equals(configName)) {
                Assert.assertTrue(fileName + " rule '" + ruleName + "' module '" + moduleName + "' should have matching " + configName + " url", configUrl.startsWith("https://github.com/checkstyle/checkstyle/" + "blob/master/src/it/java/com/google/checkstyle/test/"));
                Assert.assertTrue(fileName + " rule '" + ruleName + "' module '" + moduleName + "' should have matching " + configName + " url", configUrl.endsWith("/" + moduleName + "Test.java"));
                Assert.assertTrue(fileName + " rule '" + ruleName + "' module '" + moduleName + "' should have a test that exists", new File(configUrl.substring(53).replace('/', File.separatorChar)).exists());
            }
        }
    }
    Assert.assertFalse(fileName + " rule '" + ruleName + "' has too many configs", itrConfigs.hasNext());
}
Also used : Node(org.w3c.dom.Node) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException)

Example 22 with NoSuchElementException

use of java.util.NoSuchElementException in project crate by crate.

the class RowGenerator method range.

/**
     * Generate a range of rows.
     * Both increasing (e.g. 0 -> 10) and decreasing ranges (10 -> 0) are supported.
     *
     * @param from start (inclusive)
     * @param to   end (exclusive)
     */
public static Iterable<Row> range(final int from, final int to) {
    return new Iterable<Row>() {

        @Override
        public Iterator<Row> iterator() {
            return new Iterator<Row>() {

                private Object[] columns = new Object[1];

                private RowN sharedRow = new RowN(columns);

                private int i = from;

                private int step = from < to ? 1 : -1;

                @Override
                public boolean hasNext() {
                    return step >= 0 ? i < to : i > to;
                }

                @Override
                public Row next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException("Iterator exhausted");
                    }
                    columns[0] = i;
                    i += step;
                    return sharedRow;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Remove not supported");
                }
            };
        }
    };
}
Also used : RowN(io.crate.data.RowN) Iterator(java.util.Iterator) Row(io.crate.data.Row) NoSuchElementException(java.util.NoSuchElementException)

Example 23 with NoSuchElementException

use of java.util.NoSuchElementException in project druid by druid-io.

the class QueryableIndexIndexableAdapter method getRows.

@Override
public Iterable<Rowboat> getRows() {
    return new Iterable<Rowboat>() {

        @Override
        public Iterator<Rowboat> iterator() {
            return new Iterator<Rowboat>() {

                final GenericColumn timestamps = input.getColumn(Column.TIME_COLUMN_NAME).getGenericColumn();

                final Closeable[] metrics;

                final Closeable[] columns;

                final Closer closer = Closer.create();

                final int numMetrics = getMetricNames().size();

                final DimensionHandler[] handlers = new DimensionHandler[availableDimensions.size()];

                Collection<DimensionHandler> handlerSet = input.getDimensionHandlers().values();

                int currRow = 0;

                boolean done = false;

                {
                    closer.register(timestamps);
                    handlerSet.toArray(handlers);
                    this.columns = FluentIterable.from(handlerSet).transform(new Function<DimensionHandler, Closeable>() {

                        @Override
                        public Closeable apply(DimensionHandler handler) {
                            Column column = input.getColumn(handler.getDimensionName());
                            return handler.getSubColumn(column);
                        }
                    }).toArray(Closeable.class);
                    for (Closeable column : columns) {
                        closer.register(column);
                    }
                    final Indexed<String> availableMetrics = getMetricNames();
                    metrics = new Closeable[availableMetrics.size()];
                    for (int i = 0; i < metrics.length; ++i) {
                        final Column column = input.getColumn(availableMetrics.get(i));
                        final ValueType type = column.getCapabilities().getType();
                        switch(type) {
                            case FLOAT:
                            case LONG:
                                metrics[i] = column.getGenericColumn();
                                break;
                            case COMPLEX:
                                metrics[i] = column.getComplexColumn();
                                break;
                            default:
                                throw new ISE("Cannot handle type[%s]", type);
                        }
                    }
                    for (Closeable metricColumn : metrics) {
                        closer.register(metricColumn);
                    }
                }

                @Override
                public boolean hasNext() {
                    final boolean hasNext = currRow < numRows;
                    if (!hasNext && !done) {
                        CloseQuietly.close(closer);
                        done = true;
                    }
                    return hasNext;
                }

                @Override
                public Rowboat next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    final Object[] dims = new Object[columns.length];
                    int dimIndex = 0;
                    for (final Closeable column : columns) {
                        dims[dimIndex] = handlers[dimIndex].getEncodedKeyComponentFromColumn(column, currRow);
                        dimIndex++;
                    }
                    Object[] metricArray = new Object[numMetrics];
                    for (int i = 0; i < metricArray.length; ++i) {
                        if (metrics[i] instanceof IndexedFloatsGenericColumn) {
                            metricArray[i] = ((GenericColumn) metrics[i]).getFloatSingleValueRow(currRow);
                        } else if (metrics[i] instanceof IndexedLongsGenericColumn) {
                            metricArray[i] = ((GenericColumn) metrics[i]).getLongSingleValueRow(currRow);
                        } else if (metrics[i] instanceof ComplexColumn) {
                            metricArray[i] = ((ComplexColumn) metrics[i]).getRowValue(currRow);
                        }
                    }
                    final Rowboat retVal = new Rowboat(timestamps.getLongSingleValueRow(currRow), dims, metricArray, currRow, handlers);
                    ++currRow;
                    return retVal;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : Closer(com.google.common.io.Closer) IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) IndexedIterable(io.druid.segment.data.IndexedIterable) FluentIterable(com.google.common.collect.FluentIterable) ValueType(io.druid.segment.column.ValueType) Closeable(java.io.Closeable) IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) ComplexColumn(io.druid.segment.column.ComplexColumn) Column(io.druid.segment.column.Column) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) Iterator(java.util.Iterator) Collection(java.util.Collection) ISE(io.druid.java.util.common.ISE) NoSuchElementException(java.util.NoSuchElementException) ComplexColumn(io.druid.segment.column.ComplexColumn)

Example 24 with NoSuchElementException

use of java.util.NoSuchElementException in project deeplearning4j by deeplearning4j.

the class RandomWalkIterator method next.

@Override
public IVertexSequence<V> next() {
    if (!hasNext())
        throw new NoSuchElementException();
    //Generate a random walk starting at vertex order[current]
    int currVertexIdx = order[position++];
    int[] indices = new int[walkLength + 1];
    indices[0] = currVertexIdx;
    if (walkLength == 0)
        return new VertexSequence<>(graph, indices);
    Vertex<V> next;
    try {
        next = graph.getRandomConnectedVertex(currVertexIdx, rng);
    } catch (NoEdgesException e) {
        switch(mode) {
            case SELF_LOOP_ON_DISCONNECTED:
                for (int i = 1; i < walkLength; i++) indices[i] = currVertexIdx;
                return new VertexSequence<>(graph, indices);
            case EXCEPTION_ON_DISCONNECTED:
                throw e;
            default:
                throw new RuntimeException("Unknown/not implemented NoEdgeHandling mode: " + mode);
        }
    }
    indices[1] = next.vertexID();
    currVertexIdx = indices[1];
    for (int i = 2; i <= walkLength; i++) {
        //<= walk length: i.e., if walk length = 2, it contains 3 vertices etc
        next = graph.getRandomConnectedVertex(currVertexIdx, rng);
        currVertexIdx = next.vertexID();
        indices[i] = currVertexIdx;
    }
    return new VertexSequence<>(graph, indices);
}
Also used : NoEdgesException(org.deeplearning4j.graph.exception.NoEdgesException) IVertexSequence(org.deeplearning4j.graph.api.IVertexSequence) VertexSequence(org.deeplearning4j.graph.graph.VertexSequence) NoSuchElementException(java.util.NoSuchElementException)

Example 25 with NoSuchElementException

use of java.util.NoSuchElementException in project jetty.project by eclipse.

the class ByteBufferContentProvider method iterator.

@Override
public Iterator<ByteBuffer> iterator() {
    return new Iterator<ByteBuffer>() {

        private int index;

        @Override
        public boolean hasNext() {
            return index < buffers.length;
        }

        @Override
        public ByteBuffer next() {
            try {
                ByteBuffer buffer = buffers[index];
                buffers[index] = buffer.slice();
                ++index;
                return buffer;
            } catch (ArrayIndexOutOfBoundsException x) {
                throw new NoSuchElementException();
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Iterator(java.util.Iterator) ByteBuffer(java.nio.ByteBuffer) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)645 Iterator (java.util.Iterator)119 Scanner (java.util.Scanner)59 Test (org.junit.Test)53 IOException (java.io.IOException)49 ArrayList (java.util.ArrayList)47 InputMismatchException (java.util.InputMismatchException)46 StringTokenizer (java.util.StringTokenizer)43 Locale (java.util.Locale)24 HashMap (java.util.HashMap)22 NodeIterator (javax.jcr.NodeIterator)20 File (java.io.File)19 Map (java.util.Map)19 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)16 Collection (java.util.Collection)15 LinkedList (java.util.LinkedList)15 List (java.util.List)15 Set (java.util.Set)15 BufferedReader (java.io.BufferedReader)13 Enumeration (java.util.Enumeration)13