List of usage examples for java.util Iterator Iterator
Iterator
From source file:com.cloudera.recordbreaker.analyzer.XMLSchemaDescriptor.java
/** * Return an object that steps through all the data items in the file. * It's a bit unclear how this should work, as an XML file is really a tree, * but we usually assume an Iterator is giving back tuples. So what's a "row" * in the case of XML?/* www . ja v a 2 s . c o m*/ * * Ideally, the iterator gives back a result for every "repeated leaf". Just * being a leaf in the XML tree is not enough: there should be a level of * repetition that makes it interesting. If there's no repetition then * the object is just returned once. * * We can detect when repeats happen: it yields an Avro array. But what about * when we have multiple levels of this? Probably we want a row for the * product of repetitions. * * Definitely do not want a record for each individual leaf-level field. * * Maybe we want to fill out as many non-exclusive columns as we can? * As soon as a repetition means we have a column-repetition-conflict, then * time for a new row. * * How do we translate an Avro tree into a series of tuples? Basically * we have one new Record for each leaf-level array entry. There is never * an array in an object returned by getIterator(). If it's just a nested * set of Records, then it's one big tuple. */ public Iterator getIterator() { return new Iterator() { // NOTE: We should eventually modify this so we don't have to // materialize the entire tree. This is pretty inefficient right now. Object nextElt = null; List<Object> lookaheadList = new ArrayList<Object>(); { rootTag.accumulateObjects(lookaheadList); nextElt = lookahead(); } public boolean hasNext() { return nextElt != null; } public synchronized Object next() { Object toReturn = nextElt; nextElt = lookahead(); return toReturn; } public void remove() { throw new UnsupportedOperationException(); } Object lookahead() { if (lookaheadList.size() > 0) { return lookaheadList.remove(0); } else { return null; } } }; }
From source file:com.su.search.client.solrj.PaHttpSolrServer.java
/** * Adds the beans supplied by the given iterator. * /* w w w .j a va2 s . c o m*/ * @param beanIterator * the iterator which returns Beans * * @return the response from the SolrServer */ public UpdateResponse addBeans(final Iterator<?> beanIterator) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.setDocIterator(new Iterator<SolrInputDocument>() { public boolean hasNext() { return beanIterator.hasNext(); } public SolrInputDocument next() { Object o = beanIterator.next(); if (o == null) return null; return getBinder().toSolrInputDocument(o); } public void remove() { beanIterator.remove(); } }); return req.process(this); }
From source file:com.github.jsonj.JsonObject.java
@Override public Set<Entry<String, JsonElement>> entrySet() { final Set<Entry<Integer, JsonElement>> entrySet = intMap.entrySet(); return new Set<Map.Entry<String, JsonElement>>() { @Override/* www. j av a2 s. c o m*/ public boolean add(java.util.Map.Entry<String, JsonElement> e) { throw new UnsupportedOperationException("entry set is immutable"); } @Override public boolean addAll(Collection<? extends java.util.Map.Entry<String, JsonElement>> c) { throw new UnsupportedOperationException("entry set is immutable"); } @Override public void clear() { throw new UnsupportedOperationException("entry set is immutable"); } @Override public boolean contains(Object o) { throw new UnsupportedOperationException("not supported"); } @Override public boolean containsAll(Collection<?> c) { throw new UnsupportedOperationException("not supported"); } @Override public boolean isEmpty() { return entrySet.isEmpty(); } @Override public Iterator<Entry<String, JsonElement>> iterator() { return new Iterator<Entry<String, JsonElement>>() { private final Iterator<Entry<Integer, JsonElement>> it = entrySet.iterator(); @Override public boolean hasNext() { return it.hasNext(); } @Override public Entry<String, JsonElement> next() { final Entry<Integer, JsonElement> next = it.next(); return new Entry<String, JsonElement>() { @Override public String getKey() { EfficientString es = EfficientString.get(next.getKey()); return es.toString(); } @Override public JsonElement getValue() { return next.getValue(); } @Override public JsonElement setValue(JsonElement value) { throw new UnsupportedOperationException("immutable entry"); } }; } @Override public void remove() { it.remove(); } }; } @Override public boolean remove(Object o) { throw new UnsupportedOperationException("entry set is immutable"); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException("entry set is immutable"); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException("entry set is immutable"); } @Override public int size() { return entrySet.size(); } @Override public Object[] toArray() { @SuppressWarnings("unchecked") Entry<String, JsonElement>[] result = new Entry[entrySet.size()]; int i = 0; for (final Entry<Integer, JsonElement> e : entrySet) { result[i] = new Entry<String, JsonElement>() { @Override public String getKey() { EfficientString es = EfficientString.get(e.getKey()); return es.toString(); } @Override public JsonElement getValue() { return e.getValue(); } @Override public JsonElement setValue(JsonElement value) { throw new UnsupportedOperationException("immutable"); } }; i++; } return result; } @SuppressWarnings("unchecked") @Override public <T> T[] toArray(T[] a) { return (T[]) toArray(); } }; }
From source file:edu.umd.cfar.lamp.viper.geometry.ConvexPolygon.java
public Iterator getVerteces() { if (edgeList == null) { return new Iterator() { public boolean hasNext() { return false; }//from w w w. j av a2 s.co m public Object next() { throw new NoSuchElementException(); } public void remove() { throw new UnsupportedOperationException(); } }; } else { return new Iterator() { private Iterator iter = edgeList.iterator(); public boolean hasNext() { return iter.hasNext(); } public Object next() { return new Pnt((Pnt) iter.next()); } public void remove() { throw new UnsupportedOperationException(); } }; } }
From source file:org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.java
/** * Adds the beans supplied by the given iterator, specifying max time before they become committed * @param commitWithinMs the time in milliseconds before a commit automatically is triggered * @param beanIterator the iterator which returns Beans * @return the response from the SolrServer *///from www .ja v a 2 s .c o m public UpdateResponse addBeans(final Iterator<?> beanIterator, int commitWithinMs) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.setDocIterator(new Iterator<SolrInputDocument>() { public boolean hasNext() { return beanIterator.hasNext(); } public SolrInputDocument next() { Object o = beanIterator.next(); if (o == null) return null; return getBinder().toSolrInputDocument(o); } public void remove() { beanIterator.remove(); } }); req.setCommitWithin(commitWithinMs); return req.process(this); }
From source file:sk.datalan.solr.impl.HttpSolrServer.java
/** * Adds the beans supplied by the given iterator. * * @param beanIterator the iterator which returns Beans * * @return the response from the SolrServer *//*w w w.ja v a2 s. c om*/ public UpdateResponse addBeans(final Iterator<?> beanIterator) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.setDocIterator(new Iterator<SolrInputDocument>() { @Override public boolean hasNext() { return beanIterator.hasNext(); } @Override public SolrInputDocument next() { Object o = beanIterator.next(); if (o == null) { return null; } return getBinder().toSolrInputDocument(o); } @Override public void remove() { beanIterator.remove(); } }); return req.process(this); }
From source file:com.nkang.kxmoment.util.SolrUtils.HttpSolrServer.java
/** * Adds the beans supplied by the given iterator. * /*from w w w .j a va 2 s.c o m*/ * @param beanIterator * the iterator which returns Beans * * @return the response from the SolrServer */ public UpdateResponse addBeans(final Iterator<?> beanIterator) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.setDocIterator(new Iterator<SolrInputDocument>() { //@Override public boolean hasNext() { return beanIterator.hasNext(); } //@Override public SolrInputDocument next() { Object o = beanIterator.next(); if (o == null) { return null; } return getBinder().toSolrInputDocument(o); } //@Override public void remove() { beanIterator.remove(); } }); return req.process(this); }
From source file:com.datumbox.framework.core.common.dataobjects.Dataframe.java
/** * Returns a read-only Iterable on the keys and Records of the Dataframe. * * @return/*from w ww. j a v a 2 s.c om*/ */ public Iterable<Map.Entry<Integer, Record>> entries() { return () -> new Iterator<Map.Entry<Integer, Record>>() { private final Iterator<Map.Entry<Integer, Record>> it = data.records.entrySet().iterator(); /** {@inheritDoc} */ @Override public boolean hasNext() { return it.hasNext(); } /** {@inheritDoc} */ @Override public Map.Entry<Integer, Record> next() { return it.next(); } /** {@inheritDoc} */ @Override public void remove() { throw new UnsupportedOperationException( "This is a read-only iterator, remove operation is not supported."); } }; }
From source file:org.diorite.command.Arguments.java
@Override public Iterator<String> iterator() { return new Iterator<String>() { private int index = 0; @Override/*from w ww . ja v a 2s. c om*/ public boolean hasNext() { return this.index < Arguments.this.args.length; } @Override public String next() { if (Arguments.this.args.length <= this.index) { throw new ArrayIndexOutOfBoundsException( "Out of range, length: " + Arguments.this.args.length + ", index: " + this.index); } return Arguments.this.args[this.index++]; } }; }
From source file:org.apache.solr.client.solrj.impl.HttpSolrServer.java
/** * Adds the beans supplied by the given iterator. * /*from w ww . j ava 2 s. c om*/ * @param beanIterator * the iterator which returns Beans * * @return the response from the SolrServer */ public UpdateResponse addBeans(final Iterator<?> beanIterator) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.setDocIterator(new Iterator<SolrInputDocument>() { @Override public boolean hasNext() { return beanIterator.hasNext(); } @Override public SolrInputDocument next() { Object o = beanIterator.next(); if (o == null) return null; return getBinder().toSolrInputDocument(o); } @Override public void remove() { beanIterator.remove(); } }); return req.process(this); }