List of usage examples for java.lang Iterable Iterable
Iterable
From source file:com.github.mjeanroy.spring.mappers.InMemoryObjectMapperTest.java
@Test public void it_should_create_linked_list_with_iterable_sources() throws Exception { ObjectMapper<Foo, FooDto> objectMapper = inMemoryObjectMapper(mapper, Foo.class, FooDto.class); final Iterator<Foo> iterator = new Iterator<Foo>() { @Override/*from w ww . ja v a 2 s. c o m*/ public boolean hasNext() { return false; } @Override public Foo next() { return null; } @Override public void remove() { // Nothing to do. } }; Iterable<Foo> iterable = new Iterable<Foo>() { @Override public Iterator<Foo> iterator() { return iterator; } }; Iterable<FooDto> results = objectMapper.map(iterable); assertThat(results).isInstanceOf(LinkedList.class); }
From source file:org.omnaest.utils.structure.iterator.IterableUtils.java
/** * Returns an {@link Iterable} which returns always a new empty {@link Iterator} * /* ww w. ja va 2 s . c o m*/ * @see IteratorUtils#empty() * @return */ public static <E> Iterable<E> empty() { return new Iterable<E>() { @Override public Iterator<E> iterator() { return IteratorUtils.empty(); } }; }
From source file:com.boundlessgeo.geoserver.api.controllers.FormatController.java
Iterable<DataFormat> vectorFormats() { Iterable<DataAccessFactory> it = new Iterable<DataAccessFactory>() { @Override// w ww. j a v a2 s . c om public Iterator<DataAccessFactory> iterator() { return DataAccessFinder.getAllDataStores(); } }; return transform(filter(it, not(instanceOf(JDBCJNDIDataStoreFactory.class))), new Function<DataAccessFactory, DataFormat>() { @Nullable @Override public DataFormat apply(@Nullable DataAccessFactory f) { return format(f); } }); }
From source file:name.martingeisse.stackd.server.section.SectionWorkingSet.java
/** * Returns multiple objects, loading them if necessary. * //from w ww . ja va 2s .c om * @param sectionDataIds the section data IDs * @return the section-related objects */ public ImmutableMap<SectionDataId, SectionDataCacheEntry> getAll(final SectionDataId... sectionDataIds) { try { return cache.getAll(new Iterable<SectionDataId>() { @Override @SuppressWarnings("unchecked") public Iterator<SectionDataId> iterator() { return new ArrayIterator(sectionDataIds); } }); } catch (final ExecutionException e) { throw new RuntimeException(e); } }
From source file:ca.uhn.fhir.parser.BaseParser.java
protected Iterable<CompositeChildElement> compositeChildIterator(IBase theCompositeElement, final boolean theContainedResource, final CompositeChildElement theParent) { BaseRuntimeElementCompositeDefinition<?> elementDef = (BaseRuntimeElementCompositeDefinition<?>) myContext .getElementDefinition(theCompositeElement.getClass()); final List<BaseRuntimeChildDefinition> children = elementDef.getChildrenAndExtension(); return new Iterable<BaseParser.CompositeChildElement>() { @Override/*from ww w.j a v a 2s. co m*/ public Iterator<CompositeChildElement> iterator() { return new Iterator<CompositeChildElement>() { private Iterator<? extends BaseRuntimeChildDefinition> myChildrenIter; private Boolean myHasNext = null; private CompositeChildElement myNext; /** * Constructor */ { myChildrenIter = children.iterator(); } @Override public boolean hasNext() { if (myHasNext != null) { return myHasNext; } myNext = null; do { if (myChildrenIter.hasNext() == false) { myHasNext = Boolean.FALSE; return false; } myNext = new CompositeChildElement(theParent, myChildrenIter.next()); /* * There are lots of reasons we might skip encoding a particular child */ if (myNext.getDef().getElementName().equals("id")) { myNext = null; } else if (!myNext.shouldBeEncoded()) { myNext = null; } else if (isSummaryMode() && !myNext.getDef().isSummary()) { myNext = null; } else if (myNext.getDef() instanceof RuntimeChildNarrativeDefinition) { if (isSuppressNarratives() || isSummaryMode()) { myNext = null; } else if (theContainedResource) { myNext = null; } } else if (myNext.getDef() instanceof RuntimeChildContainedResources) { if (theContainedResource) { myNext = null; } } } while (myNext == null); myHasNext = true; return true; } @Override public CompositeChildElement next() { if (myHasNext == null) { if (!hasNext()) { throw new IllegalStateException(); } } CompositeChildElement retVal = myNext; myNext = null; myHasNext = null; return retVal; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:com.atomicleopard.thundr.ftp.FtpSession.java
/** * List remote contents in batches - includes both files and directories * //from w w w . j a v a 2s .com * @param directory * @param batchSize * @return */ public Iterable<FTPFile[]> listBatch(final String directory, final int batchSize) { return timeLogAndCatch("List files in batch", new Callable<Iterable<FTPFile[]>>() { @Override public Iterable<FTPFile[]> call() throws Exception { final FTPListParseEngine engine = preparedClient.initiateListParsing(directory); return new Iterable<FTPFile[]>() { @Override public Iterator<FTPFile[]> iterator() { return new Iterator<FTPFile[]>() { @Override public boolean hasNext() { return engine.hasNext(); } @Override public FTPFile[] next() { return engine.getNext(batchSize); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; } }); }
From source file:com.trenako.values.DeliveryDate.java
private static Iterable<Integer> inverseRange(final int start, final int end) { return new Iterable<Integer>() { @Override/*from www .ja va 2 s . co m*/ public Iterator<Integer> iterator() { return new Iterator<Integer>() { private int current = end; @Override public boolean hasNext() { return current >= start; } @Override public Integer next() { if (!hasNext()) { throw new NoSuchElementException(); } int n = current; current--; return n; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:org.apache.hadoop.yarn.server.api.records.impl.pb.NodeStatusPBImpl.java
private synchronized void addContainerMemoryStatusesToProto() { maybeInitBuilder();//w w w. j a v a2 s . c o m builder.clearContainerMemoryStatuses(); if (containerMemoryStatuses == null) return; Iterable<ContainerSqueezeUnitProto> iterable = new Iterable<ContainerSqueezeUnitProto>() { @Override public Iterator<ContainerSqueezeUnitProto> iterator() { return new Iterator<ContainerSqueezeUnitProto>() { Iterator<ContainerSqueezeUnit> iter = containerMemoryStatuses.iterator(); @Override public boolean hasNext() { return iter.hasNext(); } @Override public ContainerSqueezeUnitProto next() { return convertToProtoFormat(iter.next()); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; builder.addAllContainerMemoryStatuses(iterable); }
From source file:com.intelligentsia.dowsers.entity.store.fs.FileEntityStore.java
@Override public Iterable<Reference> find(final Class<?> expectedType) throws NullPointerException { final Collection<File> files = FileUtils.listFiles(root, new RegexFileFilter("^(.*?)"), DirectoryFileFilter.DIRECTORY); final Iterator<File> iterator = files.iterator(); return new Iterable<Reference>() { @Override//from w w w . j a v a 2 s . c om public Iterator<Reference> iterator() { return new Iterator<Reference>() { @Override public void remove() { throw new UnsupportedOperationException(); } @Override public Reference next() { return Reference.newReference(expectedType, iterator.next().getName()); } @Override public boolean hasNext() { return iterator.hasNext(); } }; } }; }
From source file:org.apache.apex.malhar.lib.window.impl.SpillableWindowedKeyedStorage.java
@Override public Iterable<Map.Entry<K, V>> entries(final Window window) { return new Iterable<Map.Entry<K, V>>() { @Override// w w w . j av a 2s.co m public Iterator<Map.Entry<K, V>> iterator() { return new KVIterator(window); } }; }