List of usage examples for java.lang Iterable Iterable
Iterable
From source file:org.jahia.services.deamons.filewatcher.FileMonitorResult.java
public Iterable<File> getAll() { return new Iterable<File>() { @SuppressWarnings("unchecked") @Override/*from w w w . j av a2 s . c om*/ public Iterator<File> iterator() { return IteratorUtils.chainedIterator(getDeleted().iterator(), IteratorUtils.chainedIterator(getChanged().iterator(), getCreated().iterator())); } }; }
From source file:waazdoh.client.storage.local.FileBeanStorage.java
private Iterable<MStringID> getStringIDIterator(final Iterator<File> fileiterator) { return new Iterable<MStringID>() { @Override/*from w w w . ja v a 2 s.c o m*/ public Iterator<MStringID> iterator() { return new Iterator<MStringID>() { @Override public void remove() { throw new UnsupportedOperationException(); } @Override public boolean hasNext() { return fileiterator.hasNext(); } @Override public MStringID next() { File f = fileiterator.next(); String name = f.getName(); return new MStringID(name.replace(".xml", "")); } }; } }; }
From source file:com.wrmsr.kleist.util.Itertools.java
public static <T> Iterable<EnumeratedElement<T>> enumerate(Iterable<T> iterable) { return new Iterable<EnumeratedElement<T>>() { @Override/*from www . j a v a2 s . c o m*/ public Iterator<EnumeratedElement<T>> iterator() { return enumerate(iterable.iterator()); } }; }
From source file:jetbrains.exodus.util.BackupBean.java
@Override public BackupStrategy getBackupStrategy() { final int targetsCount = targets.length; final BackupStrategy[] wrapped = new BackupStrategy[targetsCount]; for (int i = 0; i < targetsCount; i++) { wrapped[i] = targets[i].getBackupStrategy(); }/*w ww. j av a 2 s .c o m*/ return new BackupStrategy() { @Override public void beforeBackup() throws Exception { backupStartTicks = System.currentTimeMillis(); log.info("Backing up database..."); for (final BackupStrategy strategy : wrapped) { strategy.beforeBackup(); } } @Override public Iterable<FileDescriptor> listFiles() { return new Iterable<FileDescriptor>() { @Override public Iterator<FileDescriptor> iterator() { return new Iterator<FileDescriptor>() { @Nullable private FileDescriptor next = null; private int i = 0; @NotNull private Iterator<FileDescriptor> it = EMPTY.listFiles().iterator(); @Override public boolean hasNext() { return getNext() != null; } @Override public FileDescriptor next() { try { return getNext(); } finally { next = null; } } @Override public void remove() { throw new UnsupportedOperationException("remove"); } private FileDescriptor getNext() { if (next == null) { while (!it.hasNext()) { if (i >= targetsCount) { return next; } it = wrapped[i++].listFiles().iterator(); } next = it.next(); } return next; } }; } }; } @Override public void afterBackup() throws Exception { try { for (final BackupStrategy strategy : wrapped) { strategy.afterBackup(); } } finally { backupStartTicks = 0; } if (commandAfterBackup != null) { log.info("Executing \"" + commandAfterBackup + "\"..."); //noinspection CallToRuntimeExecWithNonConstantString,CallToRuntimeExec Runtime.getRuntime().exec(commandAfterBackup); } log.info("Backup finished."); } @Override public void onError(Throwable t) { backupException = t; } }; }
From source file:de.codesourcery.eve.skills.ui.utils.CalendarWidget.java
private Iterable<MyButton> buttons() { return new Iterable<MyButton>() { @Override//from w w w. j av a 2s. c om public Iterator<MyButton> iterator() { return buttonIterator(); } }; }
From source file:cc.aileron.accessor.PojoAccessorMixerImpl.java
@Override public PojoAccessor<?> mixin(final List<PojoAccessor<?>> accessors, final List<Object> parents) { final InstanceManager i = accessors.get(0).instanceManager(); final HashMap<String, PojoAccessor<?>> map = new HashMap<String, PojoAccessor<?>>(); final EnumMap<PojoAccessorMethod, List<String>> keys = new EnumMap<PojoAccessorMethod, List<String>>( PojoAccessorMethod.class); keys.put(PojoAccessorMethod.GET, new SkipList<String>()); keys.put(PojoAccessorMethod.SET, new SkipList<String>()); final HashMap<String, PojoAccessor<?>> setmap = new HashMap<String, PojoAccessor<?>>(); for (final PojoAccessor<?> accessor : accessors) { for (final PojoAccessorMethod method : PojoAccessorMethod.values()) { final List<String> methodKeys = accessor.keys(method); keys.get(method).addAll(methodKeys); }//w w w. j av a 2 s . c o m for (final String key : accessor.keys(PojoAccessorMethod.GET)) { map.put(key, accessor); } for (final String key : accessor.keys(PojoAccessorMethod.SET)) { setmap.put(key, accessor); } } final PojoAccessorManagerLocal manager = this.manager; return new PojoAccessor<Object>() { @Override public boolean exist(final String key) { for (final PojoAccessor<?> accessor : accessors) { if (accessor.exist(key)) { return true; } } return false; } @Override public InstanceManager instanceManager() { return i; } @Override public List<String> keys(final PojoAccessorMethod method) { return keys.get(method); } @Override public PojoAccessor<?> mixin(final Object... objects) { final SkipList<PojoAccessor<?>> list = new SkipList<PojoAccessor<?>>(); list.add(this); for (final Object object : objects) { list.add(manager.from(object, parents)); } return PojoAccessorMixerImpl.this.mixin(list, parents); } @Override public Iterable<PojoAccessorValue> set(final PojoAccessorMethod method) { final HashMap<String, PojoAccessor<?>> m = method == PojoAccessorMethod.GET ? map : setmap; return new Iterable<PojoAccessorValue>() { @Override public Iterator<PojoAccessorValue> iterator() { final Iterator<Entry<String, PojoAccessor<?>>> ite = m.entrySet().iterator(); return new Iterator<PojoAccessorValue>() { @Override public boolean hasNext() { return ite.hasNext(); } @Override public PojoAccessorValue next() { final Entry<String, PojoAccessor<?>> e = ite.next(); try { return e.getValue().to(e.getKey()); } catch (final PojoAccessorValueNotFoundException e1) { throw new Error(e1); } catch (final PojoPropertiesNotFoundException e1) { throw new Error(e1); } } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; } @Override public PojoAccessorValue to(final String key) throws PojoAccessorValueNotFoundException, PojoPropertiesNotFoundException { { final PojoAccessor<?> a = map.get(key); if (a != null) { return a.to(key); } } for (final PojoAccessor<?> a : accessors) { if (a.exist(key)) { return a.to(key); } } for (final PojoAccessor<?> a : accessors) { try { final PojoAccessorValue result = a.to(key); if (result != null) { return result; } } catch (final PojoAccessorValueNotFoundException e) { } catch (final PojoPropertiesNotFoundException e) { } } throw new PojoAccessorValueNotFoundException(accessors, key); } @Override public String toString() { return ReflectionToStringBuilder.toString(this); } @Override public Object toTarget() { throw new UnsupportedOperationException(); } }; }
From source file:org.apache.hama.graph.OutgoingVertexMessagesManager.java
@SuppressWarnings("rawtypes") @Override/*w w w. j av a 2 s .c o m*/ public void addMessage(String peerName, GraphJobMessage msg) { InetSocketAddress targetPeerAddress = getSocketAddress(peerName); if (msg.isVertexMessage() && combiner != null) { WritableComparable vertexID = msg.getVertexId(); Writable vertexValue = msg.getVertexValue(); if (!vertexMessageMap.containsKey(targetPeerAddress)) { vertexMessageMap.put(targetPeerAddress, new HashMap<WritableComparable, Writable>()); } Map<WritableComparable, Writable> combinedMessage = vertexMessageMap.get(targetPeerAddress); if (combinedMessage.containsKey(vertexID)) { tmp = new ArrayList<Writable>(); tmp.add(combinedMessage.get(vertexID)); tmp.add(vertexValue); Iterable<Writable> iterable = new Iterable<Writable>() { @Override public Iterator<Writable> iterator() { return tmp.iterator(); } }; combinedMessage.put(vertexID, combiner.combine(iterable)); } else { combinedMessage.put(vertexID, vertexValue); } } else { outgoingBundles.get(targetPeerAddress).addMessage(msg); } }
From source file:org.apache.flink.runtime.state.StateInitializationContextImpl.java
@Override public Iterable<StatePartitionStreamProvider> getRawOperatorStateInputs() { if (null != operatorStateHandles) { return new Iterable<StatePartitionStreamProvider>() { @Override//from w w w .j a v a 2s .com public Iterator<StatePartitionStreamProvider> iterator() { return new OperatorStateStreamIterator(DefaultOperatorStateBackend.DEFAULT_OPERATOR_STATE_NAME, getOperatorStateHandles().iterator(), getClosableRegistry()); } }; } else { return Collections.emptyList(); } }
From source file:org.carewebframework.common.MiscUtil.java
/** * Returns an iterable that produces only collection members of the specified type. * * @param <T> Class of collection elements. * @param <S> Subclass of T to be used by iterable. * @param collection Collection to iterate. * @param type Type of element to return. * @return An iterable.//from ww w. j ava 2s.com */ public static <T, S extends T> Iterable<S> iterableForType(Collection<T> collection, Class<S> type) { return new Iterable<S>() { @Override public Iterator<S> iterator() { return iteratorForType(collection, type); } }; }
From source file:mvm.rya.indexing.accumulo.freetext.query.ASTNodeUtils.java
public static Iterable<SimpleNode> getNodeIterator(final SimpleNode n) { return new Iterable<SimpleNode>() { @Override//from w ww . java 2 s . co m public Iterator<SimpleNode> iterator() { return new Iterator<SimpleNode>() { int pointer = 0; @Override public boolean hasNext() { return pointer < n.jjtGetNumChildren(); } @Override public SimpleNode next() { Node rtn = n.jjtGetChild(pointer); pointer++; return (SimpleNode) rtn; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }