List of usage examples for java.util Iterator Iterator
Iterator
From source file:org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSinkTest.java
@Test public void testPutMetrics() throws Exception { HadoopTimelineMetricsSink sink = new HadoopTimelineMetricsSink(); SubsetConfiguration conf = createNiceMock(SubsetConfiguration.class); expect(conf.getString(eq("slave.host.name"))).andReturn("testhost").anyTimes(); expect(conf.getParent()).andReturn(null).anyTimes(); expect(conf.getPrefix()).andReturn("service").anyTimes(); expect(conf.getString(eq(COLLECTOR_HOST_PROPERTY))).andReturn("localhost:63188").anyTimes(); expect(conf.getString(eq("serviceName-prefix"), eq(""))).andReturn("").anyTimes(); expect(conf.getInt(eq(MAX_METRIC_ROW_CACHE_SIZE), anyInt())).andReturn(10).anyTimes(); expect(conf.getInt(eq(METRICS_SEND_INTERVAL), anyInt())).andReturn(1000).anyTimes(); conf.setListDelimiter(eq(',')); expectLastCall().anyTimes();//from www .j a v a 2 s .com expect(conf.getKeys()).andReturn(new Iterator() { @Override public boolean hasNext() { return false; } @Override public Object next() { return null; } @Override public void remove() { } }).once(); HttpClient httpClient = createNiceMock(HttpClient.class); expect(httpClient.executeMethod(anyObject(PostMethod.class))).andReturn(200).once(); //metrics send only once due to caching AbstractMetric metric = createNiceMock(AbstractMetric.class); expect(metric.name()).andReturn("metricName").anyTimes(); expect(metric.value()).andReturn(9.5687).anyTimes(); //TODO currently only numeric metrics are supported MetricsRecord record = createNiceMock(MetricsRecord.class); expect(record.name()).andReturn("testName").anyTimes(); expect(record.context()).andReturn("testContext").anyTimes(); expect(record.timestamp()).andAnswer(new IAnswer<Long>() { @Override public Long answer() throws Throwable { return System.currentTimeMillis(); } }).anyTimes(); expect(record.metrics()).andReturn(Arrays.asList(metric)).anyTimes(); replay(conf, httpClient, record, metric); sink.setHttpClient(httpClient); sink.init(conf); sink.putMetrics(record); Thread.sleep(1500L); sink.putMetrics(record); verify(conf, httpClient, record, metric); }
From source file:fr.itinerennes.bundler.gtfs.GtfsAdvancedDao.java
public Iterable<ServiceDate> getAllServiceDates() { final ServiceDate start = getStartDate(); final ServiceDate end = getEndDate(); return new Iterable<ServiceDate>() { @Override//from ww w . j a va2 s .com public Iterator<ServiceDate> iterator() { return new Iterator<ServiceDate>() { private ServiceDate next = start; @Override public boolean hasNext() { return next.compareTo(end) <= 0; } @Override public ServiceDate next() { final ServiceDate current = next; next = next.next(TimeZone.getDefault()); return current; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:ListOrderedMap.java
public Collection values() { return new AbstractCollection() { public int size() { return map.size(); }/*from ww w .ja va 2 s.co m*/ public boolean contains(Object value) { return map.containsValue(value); } public void clear() { ListOrderedMap.this.clear(); } public Iterator iterator() { return new Iterator() { Object last = null; Iterator keys = lst.iterator(); public Object next() { return map.get(last = keys.next()); } public boolean hasNext() { return keys.hasNext(); } public void remove() { keys.remove(); map.remove(last); } }; } }; }
From source file:io.mindmaps.migration.csv.CSVDataMigrator.java
public Iterator<Collection<Var>> iterator() { return new Iterator<Collection<Var>>() { /**//from ww w . j a va 2 s . co m * Returns true if the CSVParser has more rows to process and the last CSVParser has not been completed. * @return true if the iteration has more elements */ @Override public boolean hasNext() { return records.hasNext(); } /** * Returns the migrated result of the next iteration (i.e. row) * @return collection of vars representing a migrated row of the CSVParser */ @Override public Collection<Var> next() { return migrateEntity(entityName, records.next()); } /** * This operation is not supported. */ @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:edu.dfci.cccb.mev.limma.domain.simple.FileBackedLimma.java
public Iterable<GoEntry> topGo() { return new Iterable<GoEntry>() { /* (non-Javadoc) * @see java.lang.Iterable#iterator() */ @Override/*from w ww . ja va2s . c o m*/ @SneakyThrows(IOException.class) public Iterator<GoEntry> iterator() { return new Iterator<GoEntry>() { private final BufferedReader reader = new BufferedReader(new FileReader(topGo)); private String current = null; /* (non-Javadoc) * @see java.util.Iterator#hasNext() */ @Override @SneakyThrows(IOException.class) public boolean hasNext() { return current == null ? (current = reader.readLine()) != null : true; } /* (non-Javadoc) * @see java.util.Iterator#next() */ @Override public GoEntry next() { hasNext(); final String[] split = current.split("\t"); GoEntry result = new GoEntry() { @Override public String term() { return string(1, split); } @Override public String significant() { return string(3, split); } @Override public double pValue() { return number(5, split); } @Override public String id() { return string(0, split); } @Override public String expected() { return string(4, split); } @Override public String annotated() { return string(2, split); } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "{id:" + id() + ", term:" + term() + ", annotated:" + annotated() + ", significant:" + significant() + ", expected:" + expected() + ", pValue:" + pValue() + "}"; } }; current = null; return result; } /* (non-Javadoc) * @see java.util.Iterator#remove() */ @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:com.oltpbenchmark.benchmarks.seats.util.CustomerIdIterable.java
@Override public Iterator<CustomerId> iterator() { return new Iterator<CustomerId>() { @Override/*from w w w . j a v a 2 s . co m*/ public boolean hasNext() { return (!CustomerIdIterable.this.airport_ids.isEmpty() || (last_id != -1 && last_id < last_max_id)); } @Override public CustomerId next() { if (last_airport_id == null) { last_airport_id = airport_ids.remove(0); last_id = 0; last_max_id = airport_max_customer_id.get(last_airport_id); } CustomerId next_id = new CustomerId(last_id, last_airport_id); if (++last_id == last_max_id) last_airport_id = null; return next_id; } @Override public void remove() { // Not implemented } }; }
From source file:org.jsonman.node.MapNode.java
public Iterable<Pair<String, Node>> getChildrenWithName() { return new Iterable<Pair<String, Node>>() { @Override/*w w w. j a v a 2s . c o m*/ public Iterator<Pair<String, Node>> iterator() { return new Iterator<Pair<String, Node>>() { @Override public boolean hasNext() { return entries.hasNext(); } @Override public Pair<String, Node> next() { Map.Entry<String, Object> e = entries.next(); return Pair.of(e.getKey(), NodeFactory.create(e.getValue())); } @Override public void remove() { entries.remove(); } private Iterator<Map.Entry<String, Object>> entries = map.entrySet().iterator(); }; } }; }
From source file:org.orbeon.oxf.util.PooledXPathExpression.java
/** * Evaluate and return an iterator over native Java objects, including underlying wrapped nodes. *//* w w w. j av a 2 s. c om*/ public Iterator iterate() throws XPathException { final Item contextItem = getContextItem(); final SequenceIterator iter = expression.iterate(expression.createDynamicContext(contextItem)); return new Iterator() { private Item currentItem = iter.next(); public boolean hasNext() { return currentItem != null; } public Object next() { final Item itemToReturn = currentItem; // Advance try { currentItem = iter.next(); } catch (XPathException e) { throw new OXFException(e); } // Convert if (itemToReturn instanceof AtomicValue) { try { return Value.convertToJava(itemToReturn); } catch (XPathException e) { throw new OXFException(e); } } else if (itemToReturn instanceof VirtualNode) { return ((VirtualNode) itemToReturn).getUnderlyingNode(); } else { return itemToReturn; } } public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:org.diorite.utils.collections.WeakCollection.java
@Override public Iterator<T> iterator() { return new Iterator<T>() { Iterator<WeakReference<T>> it; Object value;/* w w w . j a v a 2s.c o m*/ { this.it = WeakCollection.this.collection.iterator(); this.value = WeakCollection.NO_VALUE; } @Override public boolean hasNext() { Object value = this.value; if ((value != null) && (!Objects.equals(value, WeakCollection.NO_VALUE))) { return true; } else { final Iterator<WeakReference<T>> it = this.it; while (it.hasNext()) { final WeakReference<T> ref = it.next(); value = ref.get(); if (value != null) { this.value = value; return true; } it.remove(); } return false; } } @Override @SuppressWarnings("unchecked") public T next() throws NoSuchElementException { if (!this.hasNext()) { throw new NoSuchElementException("No more elements"); } else { final Object value = this.value; this.value = WeakCollection.NO_VALUE; return (T) value; } } @Override public void remove() throws IllegalStateException { if (!Objects.equals(this.value, WeakCollection.NO_VALUE)) { throw new IllegalStateException("No last element"); } else { this.value = null; this.it.remove(); } } }; }
From source file:com.github.hateoas.forms.spring.uber.AbstractUberNode.java
/** * Allows iterating over children of this uber node which have a data attribute. *//* w w w. ja va2 s . c om*/ @Override public Iterator<UberNode> iterator() { return new Iterator<UberNode>() { int index = 0; @Override public void remove() { throw new UnsupportedOperationException("removing from uber node is not supported"); } @Override public UberNode next() { index = findNextChildWithData(); return data.get(index++); } @Override public boolean hasNext() { return findNextChildWithData() != -1; } private int findNextChildWithData() { for (int i = index; i < data.size(); i++) { if (!data.get(i).getData().isEmpty()) { return i; } } return -1; } }; }