List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:com.github.rvesse.airline.io.printers.UsagePrinter.java
public UsagePrinter appendLines(Iterable<String> lines, boolean avoidNewlines) { Iterator<String> iter = lines.iterator(); while (iter.hasNext()) { String line = iter.next(); if (line == null || line.isEmpty()) continue; appendWords(arrayToList(line.split("\\s+")), avoidNewlines); if (iter.hasNext()) { this.newline(); }/*from w w w . j a va 2s . c o m*/ } return this; }
From source file:com.github.rvesse.airline.model.ArgumentsMetadata.java
public ArgumentsMetadata(Iterable<ArgumentsMetadata> arguments) { if (arguments == null) throw new NullPointerException("arguments cannot be null"); if (!arguments.iterator().hasNext()) throw new IllegalArgumentException("arguments cannot be empty"); ArgumentsMetadata first = arguments.iterator().next(); this.titles = first.titles; this.description = first.description; this.restrictions = first.restrictions; Set<Accessor> accessors = new HashSet<>(); for (ArgumentsMetadata other : arguments) { if (!first.equals(other)) throw new IllegalArgumentException( String.format("Conflicting arguments definitions: %s, %s", first, other)); accessors.addAll(other.getAccessors()); }//w ww.j a v a 2 s .co m this.accessors = SetUtils.unmodifiableSet(accessors); }
From source file:thingynet.hierarchy.HierarchyTest.java
@Test public void getDescendantsShouldReturnExpectedHierarchies() { Hierarchy parent = hierarchyService.createRoot(PARENT, null); Hierarchy child = hierarchyService.createChild(parent, CHILD, null); Hierarchy sibling = hierarchyService.createChild(parent, SIBLING, null); Hierarchy grandChild = hierarchyService.createChild(child, GRAND_CHILD, null); Hierarchy greatGrandChild = hierarchyService.createChild(grandChild, GREAT_GRAND_CHILD, null); Hierarchy other = hierarchyService.createRoot(OTHER, null); hierarchyService.createChild(other, CHILD, null); HashSet<String> expectedIds = new HashSet<>(); expectedIds.add(child.getPath());/* w w w . j a va 2 s .com*/ expectedIds.add(sibling.getPath()); expectedIds.add(grandChild.getPath()); expectedIds.add(greatGrandChild.getPath()); Iterable<Hierarchy> actual = hierarchyService.getDescendants(parent); while (actual.iterator().hasNext()) { Hierarchy descendant = actual.iterator().next(); assertThat(expectedIds.remove(descendant.getPath()), is(true)); } assertThat(expectedIds.size(), is(0)); }
From source file:org.openbaton.vnfm.core.MediaServerManagement.java
public void deleteByVnfrId(String vnfrId) throws NotFoundException { log.debug("Removing all MediaServers running on VNFR with id: " + vnfrId); Iterable<MediaServer> mediaServersIterable = mediaServerRepository.findAllByVnrfId(vnfrId); if (!mediaServersIterable.iterator().hasNext()) { log.warn("Not found any MediaServer for VNFR with id: " + vnfrId); return;/*from w ww.j a v a2s . com*/ } Iterator<MediaServer> iterator = mediaServersIterable.iterator(); while (iterator.hasNext()) { delete(iterator.next().getId()); } log.info("Removed all MediaServers running on VNFR with id: " + vnfrId); }
From source file:org.cloudfoundry.client.lib.io.DynamicZipInputStream.java
/** * Create a new {@link DynamicZipInputStream} instance. * * @param entries the zip entries that should be written to the stream *///ww w . ja v a2 s. c o m public DynamicZipInputStream(Iterable<Entry> entries) { Assert.notNull(entries, "Entries must not be null"); this.zipStream = new ZipOutputStream(getOutputStream()); this.entries = entries.iterator(); }
From source file:org.jongo.AggregateTest.java
@Test public void canAggregate() throws Exception { Iterable<Article> articles = collection.aggregate("{$match:{}}").as(Article.class); assertThat(articles.iterator().hasNext()).isTrue(); for (Article article : articles) { assertThat(article.title).isIn("Zombie Panic", "Apocalypse Zombie", "World War Z"); }//from ww w .ja va2s . c om }
From source file:com.github.rvesse.airline.Accessor.java
public Accessor(Iterable<Field> path) { this(path.iterator()); }
From source file:org.axonframework.samples.trader.query.orderbook.OrderBookListenerIntegrationTest.java
@Test public void testHandleTradeExecuted() throws Exception { CompanyEntry company = createCompany(); OrderBookEntry orderBook = createOrderBook(company); OrderId sellOrderId = new OrderId(); TransactionId sellTransactionId = new TransactionId(); SellOrderPlacedEvent sellOrderPlacedEvent = new SellOrderPlacedEvent(orderBookId, sellOrderId, sellTransactionId, 400, 100, portfolioId); orderBookListener.handleSellOrderPlaced(sellOrderPlacedEvent); OrderId buyOrderId = new OrderId(); TransactionId buyTransactionId = new TransactionId(); BuyOrderPlacedEvent buyOrderPlacedEvent = new BuyOrderPlacedEvent(orderBookId, buyOrderId, buyTransactionId, 300, 150, portfolioId);/*ww w. j ava2s . c o m*/ orderBookListener.handleBuyOrderPlaced(buyOrderPlacedEvent); Iterable<OrderBookEntry> all = orderBookRepository.findAll(); OrderBookEntry orderBookEntry = all.iterator().next(); assertNotNull("The first item of the iterator for orderbooks should not be null", orderBookEntry); assertEquals("Test Company", orderBookEntry.getCompanyName()); assertEquals(1, orderBookEntry.sellOrders().size()); assertEquals(1, orderBookEntry.buyOrders().size()); TradeExecutedEvent event = new TradeExecutedEvent(orderBookId, 300, 125, buyOrderId, sellOrderId, buyTransactionId, sellTransactionId); orderBookListener.handleTradeExecuted(event); Iterable<TradeExecutedEntry> tradeExecutedEntries = tradeExecutedRepository.findAll(); assertTrue(tradeExecutedEntries.iterator().hasNext()); TradeExecutedEntry tradeExecutedEntry = tradeExecutedEntries.iterator().next(); assertEquals("Test Company", tradeExecutedEntry.getCompanyName()); assertEquals(300, tradeExecutedEntry.getTradeCount()); assertEquals(125, tradeExecutedEntry.getTradePrice()); all = orderBookRepository.findAll(); orderBookEntry = all.iterator().next(); assertNotNull("The first item of the iterator for orderbooks should not be null", orderBookEntry); assertEquals("Test Company", orderBookEntry.getCompanyName()); assertEquals(1, orderBookEntry.sellOrders().size()); assertEquals(0, orderBookEntry.buyOrders().size()); }
From source file:com.gzj.tulip.jade.statement.JdbcStatement.java
@Override public Object execute(Map<String, Object> parameters) { Object result;/*from ww w .j a v a2s. co m*/ if (batchUpdate) { // Iterable<?> iterable = (Iterable<?>) parameters.get(":1"); Iterator<?> iterator = (Iterator<?>) iterable.iterator(); List<StatementRuntime> runtimes = new LinkedList<StatementRuntime>(); int index = 0; while (iterator.hasNext()) { Object arg = iterator.next(); HashMap<String, Object> clone = new HashMap<String, Object>(parameters); // ? clone.put(":1", arg); if (metaData.getSQLParamAt(0) != null) { clone.put(metaData.getSQLParamAt(0).value(), arg); } StatementRuntime runtime = new StatementRuntimeImpl(metaData, clone); for (Interpreter interpreter : interpreters) { interpreter.interpret(runtime); } if (index == 0) { log(parameters, runtime); } runtimes.add(runtime); index++; } result = querier.execute(sqlType, runtimes.toArray(new StatementRuntime[0])); result = afterInvocationCallback.execute(runtimes.get(0), result); } else { StatementRuntime runtime = new StatementRuntimeImpl(metaData, parameters); for (Interpreter interpreter : interpreters) { interpreter.interpret(runtime); } log(parameters, runtime); result = querier.execute(sqlType, runtime); result = afterInvocationCallback.execute(runtime, result); } return result; }
From source file:corner.orm.gae.impl.PaginatedJapEntityService.java
License:asdf
public long count(final Class<?> persistClass, final Object conditions) { return (Long) this.template.execute(new JpaCallback() { @Override/*from w w w. j a v a 2 s . com*/ public Object doInJpa(EntityManager entityManager) throws PersistenceException { Iterable con = typeCoercer.coerce(conditions, Iterable.class); final Iterator it = con == null ? null : con.iterator(); final StringBuffer sb = buildConditionJPQL(persistClass, it); sb.insert(0, "select count(root) "); Query query = entityManager.createQuery(sb.toString()); if (it != null) { int i = 0; while (it.hasNext()) { query.setParameter(i++, it.next()); } } return Long.parseLong(query.getSingleResult().toString()); } }); }