List of usage examples for java.util Spliterator ORDERED
int ORDERED
To view the source code for java.util Spliterator ORDERED.
Click Source Link
From source file:org.codice.alliance.libs.mpegts.TSStream.java
/** * Create a stream of PESPackets from a byte source. * * @param byteSource must be non-null//from w w w.ja v a 2 s .c o m * @return stream of PESPackets * @throws IOException */ public static Stream<PESPacket> from(ByteSource byteSource) throws IOException { notNull(byteSource, "byteSource must be non-null"); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new PESPacketIterator(byteSource), Spliterator.ORDERED | Spliterator.NONNULL), false); }
From source file:Main.java
/** * Converts an {@link java.util.Iterator} to {@link java.util.stream.Stream}. *///from w w w . ja v a 2 s. c om public static <T> Stream<T> iterate(Iterator<? extends T> iterator) { int characteristics = Spliterator.ORDERED | Spliterator.IMMUTABLE; return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, characteristics), false); }
From source file:objective.taskboard.utils.ZipUtils.java
public static Stream<ZipStreamEntry> stream(InputStream inputStream) { ZipEntryIterator it = new ZipEntryIterator(new ZipInputStream(inputStream)); return StreamSupport .stream(Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED | Spliterator.NONNULL), false); }
From source file:eu.itesla_project.dymola.DymolaAdaptersMatParamsWriter.java
public DymolaAdaptersMatParamsWriter(HierarchicalINIConfiguration configuration) { if (configuration == null) { throw new RuntimeException("null config"); }/* w ww . ja v a2 s . com*/ this.configuration = configuration; //this below will simply log parameters .. for (String section : configuration.getSections()) { SubnodeConfiguration node = configuration.getSection(section); List<String> paramsSummary = StreamSupport .stream(Spliterators.spliteratorUnknownSize(node.getKeys(), Spliterator.ORDERED), false) .map(p -> p + "=" + node.getString(p)).collect(Collectors.<String>toList()); LOGGER.info("index {}: {}", section, paramsSummary); } }
From source file:com.miovision.oss.awsbillingtools.parser.DetailedLineItemParser.java
@Override public Stream<DetailedLineItem> parse(Reader reader) throws IOException { final CSVParser csvParser = CSV_FORMAT.parse(reader); try {//from www .j ava 2 s . com final Iterator<CSVRecord> iterator = csvParser.iterator(); final List<String> tags = readTags(iterator); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false) .map(csvRecord -> createDetailedLineItem(csvRecord, tags)).onClose(() -> { try { csvParser.close(); } catch (IOException e) { throw new RuntimeException(e); } }); } catch (Exception e) { csvParser.close(); throw e; } }
From source file:net.hamnaberg.json.Property.java
public Map<String, Value> getObject() { return unmodifiableMap(Optional.ofNullable(delegate.get("object")).filter(JsonNode::isObject) .map(object -> stream(spliteratorUnknownSize(object.fields(), Spliterator.ORDERED), false).collect( Collectors.toMap(Map.Entry::getKey, entry -> ValueFactory.createValue(entry.getValue())))) .orElse(Collections.<String, Value>emptyMap())); }
From source file:org.apache.solr.client.solrj.io.eval.FindDelayEvaluator.java
@Override public Object doWork(Object first, Object second) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }/*from w ww . j a va 2s . c om*/ if (null == second) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the second value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } // Get first and second lists as arrays, where second is in reverse order double[] firstArray = ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()) .toArray(); double[] secondArray = StreamSupport .stream(Spliterators.spliteratorUnknownSize( ((LinkedList) ((List) second).stream().collect(Collectors.toCollection(LinkedList::new))) .descendingIterator(), Spliterator.ORDERED), false) .mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(); double[] convolution = MathArrays.convolve(firstArray, secondArray); double maxValue = -Double.MAX_VALUE; double indexOfMaxValue = -1; for (int idx = 0; idx < convolution.length; ++idx) { double abs = Math.abs(convolution[idx]); if (abs > maxValue) { maxValue = abs; indexOfMaxValue = idx; } } return (indexOfMaxValue + 1) - secondArray.length; }
From source file:org.hawkular.rest.json.RelationshipJacksonDeserializer.java
@Override public Relationship deserialize(JsonParser jp, DeserializationContext deserializationContext) throws IOException { JsonNode node = jp.getCodec().readTree(jp); String id = node.get(FIELD_ID) != null ? node.get(FIELD_ID).asText() : null; // other fields are not compulsory, e.g. when deleting the relationship {id: foo} is just fine String name = ""; if (node.get(FIELD_NAME) != null) { name = node.get(FIELD_NAME).asText(); }/*ww w . ja v a 2 s . c o m*/ CanonicalPath source = null, target = null; if (node.get(FIELD_SOURCE) != null && !node.get(FIELD_SOURCE).asText().isEmpty()) { String sourcePath = node.get(FIELD_SOURCE).asText(); source = CanonicalPath.fromString(sourcePath); } if (node.get(FIELD_TARGET) != null && !node.get(FIELD_TARGET).asText().isEmpty()) { String targetPath = node.get(FIELD_TARGET).asText(); target = CanonicalPath.fromString(targetPath); } JsonNode properties = node.get(FIELD_PROPERTIES); Map<String, Object> relProperties = null; if (properties != null) { try { Stream<Map.Entry<String, JsonNode>> stream = StreamSupport.stream( Spliterators.spliteratorUnknownSize(properties.fields(), Spliterator.ORDERED), false); relProperties = stream.collect(Collectors.toMap(Map.Entry::getKey, ((Function<Map.Entry<String, JsonNode>, JsonNode>) Map.Entry::getValue) .andThen(x -> (Object) x.asText()))); } catch (Exception e) { throw new IllegalArgumentException("Error during relationship deserialization," + " unable to recognize properties: " + properties); } } return new Relationship(id, name, source, target, relProperties); }
From source file:io.mashin.rich.spark.TestJavaRichRDD.java
@Test public void testHttpRDD() { String serverIP = HttpMockConfig.serverIP(); int serverPort = HttpMockConfig.serverPort(); JavaSparkContext sc = sc("testHttpRDD"); HttpMock mock = new HttpMock(); mock.start();/*from www .j a va 2 s.co m*/ int numPages = 4; JavaRDD<String> rdd = JavaRichRDD .httpRDD(sc, i -> new HttpGet("http://" + serverIP + ":" + serverPort + "/rdd?page=" + (i + 1)), (i, httpResponse) -> { BufferedReader is = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent())); String s = is.readLine(); is.close(); return Arrays.asList(s.split(",")).iterator(); }, numPages) .cache(); assertEquals(numPages, rdd.getNumPartitions()); assertEquals(numPages * HttpMockConfig.perPage(), rdd.count()); boolean isValid = rdd.mapPartitionsWithIndex((i, iter) -> { List<String> list = StreamSupport .stream(Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED), false) .collect(Collectors.toList()); return IntStream.range(0, list.size()).mapToObj(j -> HttpMockConfig.isValidElement(list.get(j), i, j)) .iterator(); }, true).reduce(Boolean::logicalAnd); assertTrue(isValid); sc.stop(); mock.stop(); }
From source file:com.simiacryptus.mindseye.test.data.MNIST.java
private static <T> Stream<T> toIterator(@Nonnull final Iterator<T> iterator) { return StreamSupport.stream(Spliterators.spliterator(iterator, 1, Spliterator.ORDERED), false); }