List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:org.axonframework.samples.trader.query.orderbook.OrderBookListenerIntegrationTest.java
@Test public void testHandleSellOrderPlaced() throws Exception { CompanyEntry company = createCompany(); OrderBookEntry orderBook = createOrderBook(company); OrderBookId orderBookId = new OrderBookId(orderBook.getIdentifier()); SellOrderPlacedEvent event = new SellOrderPlacedEvent(orderBookId, orderId, transactionId, 300, 100, portfolioId);// w w w .j a va 2 s . co m orderBookListener.handleSellOrderPlaced(event); 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(300, orderBookEntry.sellOrders().get(0).getTradeCount()); }
From source file:com.scaleoutsoftware.soss.hserver.hadoop.ReducerWrapperMapred.java
@Override public void reduce(INKEY key, Iterable<INVALUE> values) throws IOException { reducer.reduce(key, values.iterator(), outputCollector, Reporter.NULL); }
From source file:io.crate.rest.AdminUIHttpIntegrationTest.java
@Before public void setup() throws ExecutionException, InterruptedException, IOException { Iterable<HttpServerTransport> transports = internalCluster().getInstances(HttpServerTransport.class); Iterator<HttpServerTransport> httpTransports = transports.iterator(); address = ((InetSocketTransportAddress) httpTransports.next().boundAddress().publishAddress()).address(); // place index file final Path indexDirectory = internalCluster().getInstance(Environment.class).libFile().resolve("site"); Files.createDirectories(indexDirectory); final Path indexFile = indexDirectory.resolve("index.html"); Files.write(indexFile, Collections.singletonList("<h1>Crate Admin</h1>"), Charset.forName("UTF-8")); }
From source file:eu.fthevenet.binjr.data.codec.CsvDecoder.java
/** * Returns the columns headers of the CSV file. * * @param in an input stream for the CSV file. * @return the columns headers of the CSV file. * @throws IOException in the event of an I/O error. * @throws DecodingDataFromAdapterException if an error occurred while decoding the CSV file. *///from w w w . ja va2 s . c om public List<String> getDataColumnHeaders(InputStream in) throws IOException, DecodingDataFromAdapterException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, encoding))) { CSVFormat csvFormat = CSVFormat.DEFAULT.withAllowMissingColumnNames(false).withDelimiter(delimiter); Iterable<CSVRecord> records = csvFormat.parse(reader); return this.parseColumnHeaders(records.iterator().next()); } }
From source file:io.github.alechenninger.monarch.Main.java
public void run(String[] args) throws ParseException, IOException { try {/* w w w . java2s . c o m*/ CliInputs cliInputs = CliInputs.parse(args); if (cliInputs.helpRequested()) { System.out.print(cliInputs.helpMessage()); return; } MonarchOptions options = getOptionsFromInputsAndConfigFiles(cliInputs, fileSystem, parsers); Path outputDir = options.outputDir().orElseThrow(missingOptionException("output directory")); Path dataDir = options.dataDir().orElseThrow(missingOptionException("data directory")); Hierarchy hierarchy = options.hierarchy().orElseThrow(missingOptionException("hierarchy")); String target = options.target().orElseThrow(missingOptionException("target")); Iterable<Change> changes = options.changes(); Set<String> mergeKeys = options.mergeKeys(); if (!changes.iterator().hasNext()) { System.out.println("No changes provided; formatting target."); } List<String> affectedSources = hierarchy.hierarchyOf(target).orElseThrow( () -> new IllegalArgumentException("Target source not found in hierarchy: " + options.target())) .descendants(); Map<String, Map<String, Object>> currentData = readDataForHierarchy(dataDir, hierarchy); Map<String, Map<String, Object>> result = monarch.generateSources(hierarchy, changes, target, currentData, mergeKeys); for (Map.Entry<String, Map<String, Object>> sourceToData : result.entrySet()) { String source = sourceToData.getKey(); if (!affectedSources.contains(source)) { continue; } Path sourcePath = outputDir.resolve(source); ensureParentDirectories(sourcePath); SortedMap<String, Object> sorted = new TreeMap<>(sourceToData.getValue()); if (sorted.isEmpty()) { Files.write(sourcePath, new byte[] {}); } else { yaml.dump(sorted, Files.newBufferedWriter(sourcePath, UTF_8)); } } } catch (MonarchException | ParseException e) { e.printStackTrace(); System.out.print(CliInputs.parse(new String[0]).helpMessage()); } }
From source file:edu.indiana.d2i.htrc.io.index.solr.SolrRecordReader.java
@Override public boolean nextKeyValue() throws IOException, InterruptedException { if (iditerator.hasNext()) { // normal route // String id = iditerator.next(); // key.set(id); // // String[] idlst = new String[1]; // idlst[0] = id; // Iterable<NamedVector> tfs = client.getTermVectors(idlst); // value.set(tfs.iterator().next()); // only one vector // // count++; // return true; // handle Solr exception do {//from w w w . j av a2 s. c om String id = iditerator.next(); key.set(id); String[] idlst = new String[1]; idlst[0] = id; Iterable<NamedVector> tfs = client.getTermVectors(idlst); if (tfs != null) { // otherwise, skip this book id value.set(tfs.iterator().next()); // only one vector // logger.info("set value for " + ((NamedVector)value.get()).getName()); count++; return true; } } while (iditerator.hasNext()); return false; } else { return false; } }
From source file:thingynet.hierarchy.HierarchyTest.java
@Test public void getChildrenShouldReturnExpectedHierarchies() { Hierarchy parent = hierarchyService.createRoot(PARENT, null); Hierarchy child1 = hierarchyService.createChild(parent, CHILD, null); Hierarchy child2 = hierarchyService.createChild(parent, SIBLING, null); hierarchyService.createRoot(OTHER, null); Iterable<Hierarchy> actual = hierarchyService.getChildren(parent); assertThat(actual.iterator().next().getPath(), is(child1.getPath())); assertThat(actual.iterator().next().getPath(), is(child2.getPath())); assertThat(actual.iterator().hasNext(), is(false)); }
From source file:org.mitre.openid.connect.config.JsonMessageSource.java
/** * Get a value from a single map/*from w w w . jav a2s. c o m*/ * @param code * @param locale * @param lang * @return */ private String getValue(String code, JsonObject lang) { // if there's no language map, nothing to look up if (lang == null) { return null; } JsonElement e = lang; Iterable<String> parts = Splitter.on('.').split(code); Iterator<String> it = parts.iterator(); String value = null; while (it.hasNext()) { String p = it.next(); if (e.isJsonObject()) { JsonObject o = e.getAsJsonObject(); if (o.has(p)) { e = o.get(p); // found the next level if (!it.hasNext()) { // we've reached a leaf, grab it if (e.isJsonPrimitive()) { value = e.getAsString(); } } } else { // didn't find it, stop processing break; } } else { // didn't find it, stop processing break; } } return value; }
From source file:gobblin.data.management.copy.converter.UnGzipConverterTest.java
@Test public void testExtensionStripping() throws DataConversionException, IOException { List<String> helloWorldFiles = ImmutableList.of("helloworld.txt.gzip", "helloworld.txt.gz"); UnGzipConverter converter = new UnGzipConverter(); FileSystem fs = FileSystem.getLocal(new Configuration()); for (String fileName : helloWorldFiles) { String filePath = "unGzipConverterTest/" + fileName; String fullPath = getClass().getClassLoader().getResource(filePath).getFile(); FileAwareInputStream fileAwareInputStream = new FileAwareInputStream( CopyableFileUtils.getTestCopyableFile(filePath, "/tmp/" + fileName, null, null), fs.open(new Path(fullPath))); Iterable<FileAwareInputStream> iterable = converter.convertRecord("outputSchema", fileAwareInputStream, new WorkUnitState()); FileAwareInputStream out = iterable.iterator().next(); Assert.assertEquals(out.getFile().getDestination().getName(), "helloworld.txt"); String contents = IOUtils.toString(out.getInputStream(), StandardCharsets.UTF_8); Assert.assertEquals(contents, "helloworld\n"); }/*from ww w . j a v a 2s. co m*/ }
From source file:thingynet.hierarchy.HierarchyTest.java
@Test public void getDescendantsWithLevelShouldReturnExpectedHierarchies() { Hierarchy parent = hierarchyService.createRoot(PARENT, null); Hierarchy child = hierarchyService.createChild(parent, CHILD, null); hierarchyService.createChild(parent, SIBLING, null); Hierarchy grandChild = hierarchyService.createChild(child, GRAND_CHILD, null); Hierarchy greatGrandChild = hierarchyService.createChild(grandChild, GREAT_GRAND_CHILD, null); hierarchyService.createChild(greatGrandChild, CHILD, null); HashSet<String> expectedIds = new HashSet<>(); expectedIds.add(grandChild.getPath()); expectedIds.add(greatGrandChild.getPath()); Iterable<Hierarchy> actual = hierarchyService.getDescendants(child, 2); while (actual.iterator().hasNext()) { Hierarchy descendant = actual.iterator().next(); assertThat(expectedIds.remove(descendant.getPath()), is(true)); }//from w w w .j a va 2 s .c o m assertThat(expectedIds.size(), is(0)); }