Example usage for java.lang Iterable Iterable

List of usage examples for java.lang Iterable Iterable

Introduction

In this page you can find the example usage for java.lang Iterable Iterable.

Prototype

Iterable

Source Link

Usage

From source file:com.boundlessgeo.geoserver.json.JSONArr.java

public Iterable<JSONObj> objects() {
    return new Iterable<JSONObj>() {
        @Override//  w w w  .  jav a  2  s .  c om
        public Iterator<JSONObj> iterator() {
            return Iterators.transform(JSONArr.this.iterator(), new Function<Object, JSONObj>() {
                @Nullable
                @Override
                public JSONObj apply(@Nullable Object input) {
                    return (JSONObj) input;
                }
            });
        }
    };
}

From source file:org.apache.jackrabbit.core.Tail.java

/**
 * Returns the lines that were written to the file since
 * <code>Tail.start()</code> or the last call to <code>getLines()</code>.
 *
 * @return the matching lines./*from   w  w w . ja v  a2 s . c  om*/
 * @throws IOException if an error occurs while reading from the file.
 */
public Iterable<String> getLines() throws IOException {
    return new Iterable<String>() {
        public Iterator<String> iterator() {
            Iterator<String> it = IOUtils.lineIterator(reader);
            if (grep == null || grep.length() == 0) {
                return it;
            } else {
                // filter
                return new FilterIterator<String>(it, new Predicate() {
                    public boolean evaluate(Object o) {
                        return o.toString().contains(grep);
                    }
                });
            }
        }
    };
}

From source file:nl.opengeogroep.filesetsync.FileRecord.java

/**
 * Return an Iterable of FileRecords in this fileset recursing into
 * directories. The resulting FileRecords have no hash calculated.
 *///from www . jav a 2  s. c  o  m
public static Iterable<FileRecord> getFileRecordsInDir(final String path, final String regexp,
        final MutableInt noRegexpMatches) throws IOException {
    final File f = new File(path);
    if (f.isFile()) {
        return Arrays.asList(new FileRecord(f, "."));
    } else {
        return new Iterable<FileRecord>() {
            @Override
            public Iterator<FileRecord> iterator() {
                return new FileRecordIterator(f, regexp, noRegexpMatches);
            }
        };
    }
}

From source file:com.reprezen.swaggerparser.test.ExamplesTest.java

private static <T> Iterable<T> iterable(final Iterator<T> iterator) {
    return new Iterable<T>() {
        @Override//from  w  w  w .  j av a 2s . co  m
        public Iterator<T> iterator() {
            return iterator;
        }
    };
}

From source file:Main.java

public static Iterable<Node> eval(Node element, String path) throws XPathExpressionException {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    // xpath.setNamespaceContext(new NamespaceContext() {
    ///*ww w  .j a  v a2  s . c o  m*/
    // /**
    // * @WARNING this code will work only if the namespace is present at
    // * each node of the xml dom and within the xpath queries.
    // * Otherwise you can fix like that:
    // *
    // * <pre>
    // * // FIXME: this is a
    // * hack!! if ("atom".equals(prefix)) return
    // * "http://www.w3.org/2005/Atom"; but it wont work with
    // * </pre>
    // *
    // * different namespaces
    // * @see
    // javax.xml.namespace.NamespaceContext#getNamespaceURI(java.lang.String)
    // */
    // public String getNamespaceURI(String prefix) {
    // String namespace = DOMUtil.lookupNamespaceURI(node, prefix);
    // return namespace;
    // }
    //
    // public String getPrefix(String namespaceURI) {
    // String prefix = node.lookupPrefix(namespaceURI);
    // return prefix;
    // }
    //
    // public Iterator<?> getPrefixes(final String namespaceURI) {
    // return new Iterator<String>() {
    // String ns = getPrefix(namespaceURI);
    //
    // public boolean hasNext() {
    // return ns != null;
    // }
    //
    // public String next() {
    // String r = ns;
    // ns = null;
    // return r;
    // }
    //
    // public void remove() {
    // }
    //
    // };
    // }
    // });
    XPathExpression expr = xpath.compile(path);
    final NodeList result = (NodeList) expr.evaluate(element, XPathConstants.NODESET);
    return new Iterable<Node>() {
        public Iterator<Node> iterator() {
            return new Iterator<Node>() {
                int len = result.getLength();

                int pos;

                public boolean hasNext() {
                    return pos < len;
                }

                public Node next() {
                    if (pos >= len) {
                        return null;
                    }
                    return result.item(pos++);
                }

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

            };
        }
    };
}

From source file:Utils.java

/**
 * Treat an {@link Iterator} as an {@link Iterable} so it can be used in an enhanced for-loop.
 * Bear in mind that the iterator is "consumed" by the loop and so should be used only once.
 * Generally it is best to put the code which obtains the iterator inside the loop header.
 * <div class="nonnormative">/*from   w ww.ja  v a 2s . c  o m*/
 * <p>Example of correct usage:</p>
 * <pre>
 * String text = ...;
 * for (String token : NbCollections.iterable(new {@link java.util.Scanner}(text))) {
 *     // ...
 * }
 * </pre>
 * </div>
 * @param iterator an iterator
 * @return an iterable wrapper which will traverse the iterator once
 * @throws NullPointerException if the iterator is null
 * @see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6312085">Java bug #6312085</a>
 * @see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6360734">Java bug #6360734</a>
 * @see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4988624">Java bug #4988624</a>
 * @since org.openide.util 7.5
 */
public static <E> Iterable<E> iterable(final Iterator<E> iterator) {
    if (iterator == null) {
        throw new NullPointerException();
    }
    return new Iterable<E>() {
        public Iterator<E> iterator() {
            return iterator;
        }
    };
}

From source file:org.opencastproject.oaipmh.harvester.ListRecordsResponse.java

/**
 * Get all metadata performing a complete request resuming any partial responses.
 *///from   w w w .  j  av  a 2s . c o m
public static Iterable<Node> getAllMetadataElems(final ListRecordsResponse first,
        final OaiPmhRepositoryClient client) {
    return new Iterable<Node>() {
        @Override
        public Iterator<Node> iterator() {
            return new ResponseIterator(first) {
                @Override
                protected OaiPmhRepositoryClient getClient() {
                    return client;
                }

                @Override
                protected NodeList extractNodes(ListRecordsResponse response) {
                    return response.getMetadataElems();
                }
            };
        }
    };
}

From source file:org.caleydo.core.view.opengl.canvas.AGLCanvas.java

public AGLCanvas(GLAutoDrawable drawable) {
    float s = MyPreferences.getViewZoomFactor();
    if (s <= 0)
        s = 1;/*  w ww. java  2s.co m*/
    scale = s;
    drawable.addGLEventListener(new ReshapeOnScaleChange());

    this.dnd = new DnDAdapter(this, new Iterable<IGLMouseListener>() {
        @Override
        public Iterator<IGLMouseListener> iterator() {
            return mouseListeners();
        }
    });
}

From source file:hudson.util.TextFile.java

/**
 * Parse text file line by line./*www  .  j  av a  2  s. co m*/
 */
public Iterable<String> lines() {
    return new Iterable<String>() {
        @Override
        public Iterator<String> iterator() {
            try {
                final BufferedReader in = new BufferedReader(
                        new InputStreamReader(new FileInputStream(file), "UTF-8"));

                return new AbstractIterator<String>() {
                    @Override
                    protected String computeNext() {
                        try {
                            String r = in.readLine();
                            if (r == null) {
                                in.close();
                                return endOfData();
                            }
                            return r;
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                };
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
}

From source file:com.emc.ecs.sync.config.ConfigUtil.java

public static Iterable<ConfigWrapper<?>> allStorageConfigWrappers() {
    return new Iterable<ConfigWrapper<?>>() {
        @Override/*from w w w . ja v  a 2 s.  c  o m*/
        public Iterator<ConfigWrapper<?>> iterator() {
            return new WrapperIterator(storageScanner.findCandidateComponents("com.emc.ecs.sync").iterator());
        }
    };
}