List of usage examples for java.lang Iterable Iterable
Iterable
From source file:util.AdjacencyList.java
/** * The edges of node n as an Iterable. This is much slower than for(int * i=getStartOf(n); i<getEndOf(n); i++); * * @param n the from node/*from w ww .ja va 2s .c o m*/ * @return the edges as an Iterable. */ public Iterable<Integer> getEdgesFrom(int n) { final int start = getStartOf(n); final int end = getEndOf(n); return new Iterable<Integer>() { private final Iterator<Integer> iterator = new Iterator<Integer>() { private int i = 0; @Override public boolean hasNext() { return start + i < end; } @Override public Integer next() { return start + i++; } }; @Override public Iterator<Integer> iterator() { return iterator; } }; }
From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java
@Override public Iterable<IScan1D> subsetByScanAcquisitionTime(double startSat, double stopSat) { final int startIndex = getIndexFor(startSat); if (startIndex < 0) { throw new ArrayIndexOutOfBoundsException(startIndex); }/*from w w w . j a va 2s . com*/ final int stopIndex = getIndexFor(stopSat); if (stopIndex > getNumberOfScans() - 1) { throw new ArrayIndexOutOfBoundsException(stopIndex); } final Iterator<IScan1D> iter = new Iterator<IScan1D>() { private int currentPos = startIndex; @Override public boolean hasNext() { return this.currentPos < stopIndex; } @Override public IScan1D next() { return getScan(this.currentPos++); } @Override public void remove() { throw new UnsupportedOperationException("Can not remove scans with iterator!"); } }; return new Iterable<IScan1D>() { @Override public Iterator<IScan1D> iterator() { return iter; } }; }
From source file:com.oltpbenchmark.util.CollectionUtil.java
/** * Wrap an Iterable around an Enumeration * @param <T>/*from w w w .ja v a2s .c o m*/ * @param e * @return */ public static <T> Iterable<T> iterable(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 NotImplementedException(); } }; } }); }
From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.ExternalToolActivityParser.java
@SuppressWarnings("unused") private Iterable<Element> elementIter(final NodeList nodeList) { return new Iterable<Element>() { @Override/*from ww w . j av a 2 s . c o m*/ public Iterator<Element> iterator() { return new Iterator<Element>() { int position = 0; @Override public boolean hasNext() { return nodeList.getLength() > position; } @Override public Element next() { return (Element) nodeList.item(position++); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:org.sakaiproject.nakamura.lite.content.InternalContent.java
/** * @return an iterable for all children of this content item. *//* w w w . j a v a2 s. co m*/ public Iterable<Content> listChildren() { if (newcontent) { return Iterables.emptyIterable(); } return new Iterable<Content>() { public Iterator<Content> iterator() { try { return contentManager.listChildren(path); } catch (StorageClientException e) { LOGGER.error(e.getMessage(), e); } return Iterators.emptyIterator(); } }; }
From source file:com.slytechs.utils.region.FlexRegion.java
/** * @return/* ww w . java2s.c o m*/ */ public Iterable<RegionSegment<T>> getSegmentIterable() { return new Iterable<RegionSegment<T>>() { public Iterator<RegionSegment<T>> iterator() { return segments.iterator(); } }; }
From source file:net.metanotion.web.servlets.SimpleRequestObject.java
@Override public Iterable<String> getHeaders() { return new Iterable<String>() { @Override/*from w w w .j a v a2s .c om*/ public Iterator<String> iterator() { final Enumeration<String> e = req.getHeaderNames(); if (e == null) { return new Iterator<String>() { @Override public boolean hasNext() { return false; } @Override public String next() { throw new java.util.NoSuchElementException(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } else { return new Iterator<String>() { @Override public boolean hasNext() { return e.hasMoreElements(); } @Override public String next() { return e.nextElement(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } } }; }
From source file:com.basho.riak.client.raw.http.HTTPClientAdapter.java
public Iterable<String> listKeys(String bucketName) throws IOException { final BucketResponse bucketResponse = client.streamBucket(bucketName); if (bucketResponse.isSuccess()) { final KeySource keyStream = new KeySource(bucketResponse); return new Iterable<String>() { public Iterator<String> iterator() { return keyStream; }/*from w ww. ja v a 2s . co m*/ }; } else { throw new IOException("stream keys for bucket " + bucketName + " failed with response code : " + bucketResponse.getStatusCode() + ", body: " + bucketResponse.getBodyAsString()); } }
From source file:oculus.aperture.common.JSONProperties.java
@Override public Iterable<Double> getDoubles(String key) { try {/* w w w .j a v a2 s .c om*/ final JSONArray array = obj.getJSONArray(key); return new Iterable<Double>() { @Override public Iterator<Double> iterator() { return new Iterator<Double>() { private final int n = array.length(); private int i = 0; @Override public boolean hasNext() { return n > i; } @Override public Double next() { try { return (n > i) ? array.getDouble(i++) : null; } catch (JSONException e) { return null; } } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; } catch (JSONException e) { return EmptyIterable.instance(); } }
From source file:io.coala.time.AbstractInstant.java
/** @see Instant#getRange(Instant, Instant) */ @Override/* ww w .j ava2 s. c om*/ public Iterable<THIS> getRange(final Instant<?> interval, final Instant<?> max) { @SuppressWarnings("unchecked") final Iterator<THIS> iterator = Range.of((THIS) this, interval, max); return new Iterable<THIS>() { @Override public Iterator<THIS> iterator() { return iterator; } }; }