List of usage examples for java.lang Iterable Iterable
Iterable
From source file:org.apache.flink.runtime.executiongraph.ExecutionGraph.java
@Override public Iterable<ExecutionVertex> getAllExecutionVertices() { return new Iterable<ExecutionVertex>() { @Override// w w w . java 2 s .co m public Iterator<ExecutionVertex> iterator() { return new AllVerticesIterator(getVerticesTopologically().iterator()); } }; }
From source file:org.apache.accumulo.shell.Shell.java
public ClassLoader getClassLoader(final CommandLine cl, final Shell shellState) throws AccumuloException, TableNotFoundException, AccumuloSecurityException, IOException, FileSystemException { boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty(); boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt()); String classpath = null;//from ww w. j av a 2 s .c om Iterable<Entry<String, String>> tableProps; if (namespaces) { try { tableProps = shellState.getConnector().namespaceOperations() .getProperties(OptUtil.getNamespaceOpt(cl, shellState)); } catch (NamespaceNotFoundException e) { throw new IllegalArgumentException(e); } } else if (tables) { tableProps = shellState.getConnector().tableOperations() .getProperties(OptUtil.getTableOpt(cl, shellState)); } else { throw new IllegalArgumentException("No table or namespace specified"); } for (Entry<String, String> entry : tableProps) { if (entry.getKey().equals(Property.TABLE_CLASSPATH.getKey())) { classpath = entry.getValue(); } } ClassLoader classloader; if (classpath != null && !classpath.equals("")) { shellState.getConnector().instanceOperations().getSystemConfiguration() .get(Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + classpath); try { AccumuloVFSClassLoader.getContextManager().setContextConfig( new ContextManager.DefaultContextsConfig(new Iterable<Map.Entry<String, String>>() { @Override public Iterator<Entry<String, String>> iterator() { try { return shellState.getConnector().instanceOperations().getSystemConfiguration() .entrySet().iterator(); } catch (AccumuloException e) { throw new RuntimeException(e); } catch (AccumuloSecurityException e) { throw new RuntimeException(e); } } })); } catch (IllegalStateException ise) { } classloader = AccumuloVFSClassLoader.getContextManager().getClassLoader(classpath); } else { classloader = AccumuloVFSClassLoader.getClassLoader(); } return classloader; }
From source file:org.apache.jackrabbit.oak.plugins.document.util.Utils.java
/** * Wraps the given iterable and aborts iteration over elements when the * predicate on an element evaluates to {@code false}. * * @param iterable the iterable to wrap. * @param p the predicate./* w w w .ja v a 2 s . c om*/ * @return the aborting iterable. */ public static <T> Iterable<T> abortingIterable(final Iterable<T> iterable, final Predicate<T> p) { checkNotNull(iterable); checkNotNull(p); return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> it = iterable.iterator(); return new AbstractIterator<T>() { @Override protected T computeNext() { if (it.hasNext()) { T next = it.next(); if (p.apply(next)) { return next; } } return endOfData(); } }; } }; }
From source file:org.apache.hama.graph.GraphJobRunner.java
public Iterable<Writable> getIterableMessages(final byte[] valuesBytes, final int numOfValues) { return new Iterable<Writable>() { DataInputStream dis;/*w w w.j av a 2 s . co m*/ @Override public Iterator<Writable> iterator() { if (!conf.getBoolean("hama.use.unsafeserialization", false)) { dis = new DataInputStream(new ByteArrayInputStream(valuesBytes)); } else { dis = new DataInputStream(new UnsafeByteArrayInputStream(valuesBytes)); } return new Iterator<Writable>() { int index = 0; @Override public boolean hasNext() { return (index < numOfValues) ? true : false; } @Override public Writable next() { Writable v = createVertexValue(); try { v.readFields(dis); } catch (IOException e) { throw new RuntimeException(e); } index++; return v; } @Override public void remove() { } }; } }; }
From source file:uniol.apt.adt.automaton.FiniteAutomatonUtility.java
static private <S extends State> Iterable<S> statesIterable(final S initialState) { return new Iterable<S>() { @Override// w ww . j a va2 s . co m public Iterator<S> iterator() { final Deque<State> unhandled = new LinkedList<>(); final Set<State> seen = new HashSet<>(); unhandled.add(initialState); seen.add(initialState); return new Iterator<S>() { @Override public boolean hasNext() { return !unhandled.isEmpty(); } @Override public S next() { State state = unhandled.pollFirst(); if (state == null) throw new NoSuchElementException(); for (State next : state.getFollowingStates(Symbol.EPSILON)) if (seen.add(next)) unhandled.add(next); for (Symbol symbol : state.getDefinedSymbols()) for (State next : state.getFollowingStates(symbol)) if (seen.add(next)) unhandled.add(next); @SuppressWarnings("unchecked") S ret = (S) state; return ret; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:com.basho.riak.client.RiakObject.java
/** * A thread safe, snapshot Iterable view of the state of this RiakObject's {@link RiakLink}s at call time. * Modifications are *NOT* supported./*from w w w . j ava 2s. c om*/ * @return Iterable<RiakLink> for this RiakObject's {@link RiakLink}s */ public Iterable<RiakLink> iterableLinks() { return new Iterable<RiakLink>() { public Iterator<RiakLink> iterator() { return links.iterator(); } }; }
From source file:org.apache.sling.resourceresolver.impl.ResourceResolverImpl.java
/** * @see org.apache.sling.api.resource.Resource#getChildren() *//*from w w w . ja va 2 s .c o m*/ @Override public Iterable<Resource> getChildren(final Resource parent) { return new Iterable<Resource>() { @Override public Iterator<Resource> iterator() { return listChildren(parent); } }; }
From source file:com.cloudbees.plugins.credentials.CredentialsProvider.java
/** * Returns a lazy {@link Iterable} of all the {@link CredentialsStore} instances contributing credentials to the * supplied object./*from w w w .j a v a 2s . co m*/ * * @param context the {@link Item} or {@link ItemGroup} or {@link User} to get the {@link CredentialsStore}s of. * @return a lazy {@link Iterable} of all {@link CredentialsStore} instances. * @since 1.8 */ public static Iterable<CredentialsStore> lookupStores(final ModelObject context) { final ExtensionList<CredentialsProvider> providers = all(); return new Iterable<CredentialsStore>() { public Iterator<CredentialsStore> iterator() { return new Iterator<CredentialsStore>() { private ModelObject current = context; private Iterator<CredentialsProvider> iterator = providers.iterator(); private CredentialsStore next; public boolean hasNext() { if (next != null) { return true; } while (current != null) { while (iterator.hasNext()) { CredentialsProvider p = iterator.next(); if (!p.isEnabled(context)) { continue; } next = p.getStore(current); if (next != null) { return true; } } // now walk up the model object tree // TODO make this an extension point perhaps ContextResolver could help if (current instanceof Item) { current = ((Item) current).getParent(); iterator = providers.iterator(); } else if (current instanceof User) { Jenkins jenkins = Jenkins.getActiveInstance(); Authentication a; if (jenkins.hasPermission(USE_ITEM) && current == User.current()) { // this is the fast path for the 99% of cases a = Jenkins.getAuthentication(); } else { try { a = ((User) current).impersonate(); } catch (UsernameNotFoundException e) { a = null; } } if (current == User.current() && jenkins.getACL().hasPermission(a, USE_ITEM)) { current = jenkins; iterator = providers.iterator(); } else { current = null; } } else if (current instanceof Jenkins) { // escape current = null; } else if (current instanceof ComputerSet) { current = Jenkins.getActiveInstance(); iterator = providers.iterator(); } else if (current instanceof Computer) { current = Jenkins.getActiveInstance(); iterator = providers.iterator(); } else if (current instanceof Node) { current = Jenkins.getActiveInstance(); iterator = providers.iterator(); } else { // fall back to Jenkins as the ultimate parent of everything else current = Jenkins.getActiveInstance(); iterator = providers.iterator(); } } return false; } public CredentialsStore next() { if (!hasNext()) { throw new NoSuchElementException(); } try { return next; } finally { next = null; } } public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:org.apache.taverna.scufl2.api.common.Scufl2Tools.java
private <T> Iterable<T> iterable(final Iterator<T> it) { return new Iterable<T>() { @Override//from w ww. j av a 2 s .c om public Iterator<T> iterator() { return it; } }; }
From source file:org.nuclos.common.collection.CollectionUtils.java
/** * Wraps an Enumeration (often used in older libraries) in an iterable. * (Probably every library nowadays has such a wrapper...) * * @param e the enum//w ww. ja v a 2s.co m * @return an iterable of the same type */ public static <T> Iterable<T> iterableEnum(final Enumeration<T> e) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return e.hasMoreElements(); } @Override public T next() { return e.nextElement(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }