List of usage examples for java.util Iterator Iterator
Iterator
From source file:edu.brown.utils.CollectionUtil.java
/** * Wrap an Iterable around an Enumeration that is automatically * cast to the specified type//from www . j av a 2 s .c o m * @param <T> * @param e * @return */ public static <T> Iterable<T> iterable(final Enumeration<?> e, Class<T> castType) { return (new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return (e.hasMoreElements()); } @SuppressWarnings("unchecked") @Override public T next() { return ((T) e.nextElement()); } @Override public void remove() { throw new NotImplementedException(); } }; } }); }
From source file:net.sf.nmedit.jpatch.impl.PBasicConnectionManager.java
public Iterator<PConnection> iterator() { return new Iterator<PConnection>() { Iterator<Node> iter = nodemap.values().iterator(); Node next;/*from www. j a v a 2 s . co m*/ int expectedModCount = modCount; void align() { if (next == null) { Node n; while (iter.hasNext()) { n = iter.next(); if (n.p != null) { next = n; break; } } } } public boolean hasNext() { align(); return next != null; } public PConnection next() { if (expectedModCount != modCount) throw new ConcurrentModificationException(); if (!hasNext()) throw new NoSuchElementException(); PConnection c = new PConnection(next.c, next.parent()); next = null; return c; } public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:de.csw.expertfinder.mediawiki.api.MediaWikiAPI.java
private Iterator<Element> getInfoForAllRevisions(final int articleId, final int startRevId, boolean fetchContent) { return new Iterator<Element>() { private int current = 0; private int rvstartid = startRevId; private NodeList revisions; private boolean queryContinue = true; public void remove() { throw new UnsupportedOperationException(); }/*from ww w. j a v a 2s .c o m*/ public Element next() { if (hasNext()) return (Element) revisions.item(current++); throw new NoSuchElementException(); } public boolean hasNext() { if (revisions == null || // first call queryContinue && current == revisions.getLength()) { // current // list // exhausted, // but // there's // more // to // fetch fetchNext(); } if (!queryContinue && current == revisions.getLength()) // current // list // exhausted // and // nothing // more // to // fetch: // finished! return false; return true; } private void fetchNext() { BasicNameValuePair[] params = new BasicNameValuePair[] { new BasicNameValuePair("prop", "revisions"), new BasicNameValuePair("pageids", "" + articleId), new BasicNameValuePair("rvstartid", "" + rvstartid), new BasicNameValuePair("rvdir", "newer"), new BasicNameValuePair("rvlimit", "500"), new BasicNameValuePair("rvprop", "ids|user"), new BasicNameValuePair("redirects", "") }; try { Document document = queryMediaWiki("query", params); revisions = document.getElementsByTagName("rev"); current = 0; NodeList queryContinues = document.getElementsByTagName("query-continue"); if (queryContinues.getLength() == 0) { queryContinue = false; } else { Element queryContinueElement = (Element) queryContinues.item(0); NodeList nextRevisionsElements = queryContinueElement.getElementsByTagName("revisions"); Element nextRevisions = (Element) nextRevisionsElements.item(0); String rvstartidStr = nextRevisions.getAttribute("rvstartid"); if (rvstartidStr == null || rvstartidStr.isEmpty()) { rvstartidStr = nextRevisions.getAttribute("rvcontinue"); } rvstartid = Integer.parseInt(rvstartidStr); } } catch (MediaWikiAPIException e) { log.error("Request to MediaWiki API failed", e); } } }; }
From source file:com.ibm.research.rdf.store.jena.impl.DB2QueryExecutionImpl.java
@Override public Iterator<Triple> execDescribeTriples() { // TODO: Implement a lazy iterator return new Iterator<Triple>() { StmtIterator it = execDescribe().listStatements(); @Override// ww w. j a v a 2s. c o m public boolean hasNext() { return it.hasNext(); } @Override public Triple next() { Statement st = it.next(); return st.asTriple(); } @Override public void remove() { it.remove(); } }; }
From source file:org.deegree.feature.persistence.shape.ShapeFeatureStore.java
@Override public FeatureInputStream query(final Query[] queries) throws FeatureStoreException, FilterEvaluationException { Iterator<FeatureInputStream> rsIter = new Iterator<FeatureInputStream>() { int i = 0; @Override//from w w w . jav a 2 s . com public boolean hasNext() { return i < queries.length; } @Override public FeatureInputStream next() { if (!hasNext()) { throw new NoSuchElementException(); } FeatureInputStream rs; try { rs = query(queries[i++]); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } return rs; } @Override public void remove() { throw new UnsupportedOperationException(); } }; return new CombinedFeatureInputStream(rsIter); }
From source file:com.facebook.share.ShareApi.java
private void stageArrayList(final ArrayList arrayList, final CollectionMapper.OnMapValueCompleteListener onArrayListStagedListener) { final JSONArray stagedObject = new JSONArray(); final CollectionMapper.Collection<Integer> collection = new CollectionMapper.Collection<Integer>() { @Override/* ww w. j av a2s . c om*/ public Iterator<Integer> keyIterator() { final int size = arrayList.size(); final Mutable<Integer> current = new Mutable<Integer>(0); return new Iterator<Integer>() { @Override public boolean hasNext() { return current.value < size; } @Override public Integer next() { return current.value++; } @Override public void remove() { } }; } @Override public Object get(Integer key) { return arrayList.get(key); } @Override public void set(Integer key, Object value, CollectionMapper.OnErrorListener onErrorListener) { try { stagedObject.put(key, value); } catch (final JSONException ex) { String message = ex.getLocalizedMessage(); if (message == null) { message = "Error staging object."; } onErrorListener.onError(new FacebookException(message)); } } }; final CollectionMapper.OnMapperCompleteListener onStagedArrayMapperCompleteListener = new CollectionMapper.OnMapperCompleteListener() { @Override public void onComplete() { onArrayListStagedListener.onComplete(stagedObject); } @Override public void onError(FacebookException exception) { onArrayListStagedListener.onError(exception); } }; stageCollectionValues(collection, onStagedArrayMapperCompleteListener); }
From source file:com.github.jsonj.JsonArray.java
/** * Convenience method to prevent casting JsonElement to JsonObject when iterating in the common case that you have * an array of JsonObjects./*from w w w.j a va 2 s . com*/ * * @return iterable that iterates over JsonObjects instead of JsonElements. */ public Iterable<JsonObject> objects() { final JsonArray parent = this; return new Iterable<JsonObject>() { @Override public Iterator<JsonObject> iterator() { final Iterator<JsonElement> iterator = parent.iterator(); return new Iterator<JsonObject>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public JsonObject next() { return iterator.next().asObject(); } @Override public void remove() { iterator.remove(); } }; } }; }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.IndividualDaoSDB.java
private Iterator<Individual> getIndividualIterator(final List<String> individualURIs) { if (individualURIs.size() > 0) { log.info("Number of individuals from source: " + individualURIs.size()); return new Iterator<Individual>() { Iterator<String> innerIt = individualURIs.iterator(); public boolean hasNext() { return innerIt.hasNext(); }/* w w w. j a v a 2 s . c o m*/ public Individual next() { String indURI = innerIt.next(); Individual ind = makeIndividual(indURI); if (ind != null) { return ind; } else { return new IndividualImpl(indURI); } } public void remove() { //not used } }; } else return null; }
From source file:org.netxilia.server.rest.html.sheet.impl.SheetModelServiceImpl.java
private Iterable<Integer> getRowIdIterable(final int firstRow, final int lastRow) { return CollectionUtils.iterable(new Iterator<Integer>() { private int i = firstRow; @Override//from ww w . j a va2 s . c o m public boolean hasNext() { return i < lastRow; } @Override public Integer next() { if (i >= lastRow) { throw new IllegalStateException(); } return i++; } @Override public void remove() { throw new UnsupportedOperationException(); } }); }
From source file:com.datumbox.common.dataobjects.Dataset.java
/** * Implementing read-only iterator on the Record IDs to use it in loops. * //from w ww.jav a 2 s . c o m * @return */ @Override public Iterator<Integer> iterator() { //Instead of looping through the recordList keyset we exploit the way //that the Dataset builds the Ids and instead we loop through them using //a counter. If the construction of the Dataset changes, this optimization //should be removed. return new Iterator<Integer>() { //private Iterator<Integer> it = recordList.keySet().iterator(); private Integer counter = 0; private final int n = recordList.size(); @Override public boolean hasNext() { //return it.hasNext(); return counter < n; } @Override public Integer next() { //return it.next(); return counter++; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }