Example usage for java.util Spliterator ORDERED

List of usage examples for java.util Spliterator ORDERED

Introduction

In this page you can find the example usage for java.util Spliterator ORDERED.

Prototype

int ORDERED

To view the source code for java.util Spliterator ORDERED.

Click Source Link

Document

Characteristic value signifying that an encounter order is defined for elements.

Usage

From source file:com.joyent.manta.client.MantaClient.java

/**
 * Return a stream of the contents of a directory in Manta.
 *
 * @param path The fully qualified path of the directory.
 * @return A {@link Stream} of {@link MantaObjectResponse} listing the contents of the directory.
 * @throws IOException thrown when there is a problem getting the listing over the network
 *///from  ww w.  j av  a 2  s.  c om
public Stream<MantaObject> listObjects(final String path) throws IOException {
    final MantaDirectoryListingIterator itr = streamingIterator(path);

    /* We preemptively check the iterator for a next value because that will
     * trigger an error if the path doesn't exist or is otherwise inaccessible.
     * This error typically takes the form of an UncheckedIOException, so we
     * unwind that exception if the cause is a MantaClientHttpResponseException
     * and rethrow another MantaClientHttpResponseException, so that the
     * stacktrace will point to this running method.
     */
    try {
        if (!itr.hasNext()) {
            itr.close();
            return Stream.empty();
        }
    } catch (UncheckedIOException e) {
        if (e.getCause() instanceof MantaClientHttpResponseException) {
            throw e.getCause();
        } else {
            throw e;
        }
    }

    final int additionalCharacteristics = Spliterator.CONCURRENT | Spliterator.ORDERED | Spliterator.NONNULL
            | Spliterator.DISTINCT;

    Stream<Map<String, Object>> backingStream = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(itr, additionalCharacteristics), false);

    Stream<MantaObject> stream = backingStream.map(MantaObjectConversionFunction.INSTANCE).onClose(itr::close);

    danglingStreams.add(stream);

    return stream;
}

From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.ElasticsearchIndexUtils.java

/** Utility function to handle fields
 * TODO (ALEPH-14): need to be able to specify different options for different fields via columnar settings
 * @param mutable_mapping/*w  w  w . jav a  2 s  .  com*/
 * @param fielddata_info
 * @param mapper
 */
protected static void handleMappingFields(final ObjectNode mutable_mapping,
        final Optional<Tuple3<JsonNode, JsonNode, Boolean>> fielddata_info, final ObjectMapper mapper,
        final String index_type) {
    Optional.ofNullable(mutable_mapping.get("fields")).filter(j -> !j.isNull() && j.isObject()).ifPresent(j -> {
        StreamSupport.stream(Spliterators.spliteratorUnknownSize(j.fields(), Spliterator.ORDERED), false)
                .forEach(Lambdas.wrap_consumer_u(kv -> {
                    final ObjectNode mutable_o = (ObjectNode) kv.getValue();
                    setMapping(mutable_o, fielddata_info, mapper, index_type);
                }));
    });
}

From source file:org.kie.workbench.common.dmn.backend.DMNMarshallerTest.java

@Test
public void test_function_java_WB_model() throws IOException {
    final DMNMarshaller m = getDMNMarshaller();

    @SuppressWarnings("unchecked")
    final Graph<?, Node<?, ?>> g = m.unmarshall(null, this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));

    final Stream<Node<?, ?>> stream = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(g.nodes().iterator(), Spliterator.ORDERED), false);
    final Optional<Decision> wbDecision = stream.filter(n -> n.getContent() instanceof ViewImpl)
            .map(n -> (ViewImpl) n.getContent()).filter(n -> n.getDefinition() instanceof Decision)
            .map(n -> (Decision) n.getDefinition()).findFirst();

    wbDecision.ifPresent(d -> {/*from   ww w. j  a  v a  2  s.  com*/
        assertTrue(d.getExpression() instanceof FunctionDefinition);
        final FunctionDefinition wbFunction = (FunctionDefinition) d.getExpression();

        //This is what the WB expects
        assertEquals(FunctionDefinition.Kind.JAVA, wbFunction.getKind());
    });

    final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(
            this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
    final DMNModel dmnModel = runtime.getModels().get(0);

    final BusinessKnowledgeModelNode bkmNode = dmnModel.getBusinessKnowledgeModels().iterator().next();
    final org.kie.dmn.model.api.FunctionDefinition dmnFunction = bkmNode.getBusinessKnowledModel()
            .getEncapsulatedLogic();
    assertEquals(FunctionKind.JAVA, dmnFunction.getKind());
}

From source file:com.joyent.manta.client.MantaClient.java

/**
 * Gets all of the Manta jobs' IDs as a real-time {@link Stream} from
 * the Manta API. <strong>Make sure to close this stream when you are done with
 * otherwise the HTTP socket will remain open.</strong>
 *
 * @return a stream with all of the job IDs (actually all that Manta will give us)
 *///from  w w w  .j av  a2  s  .com
public Stream<UUID> getAllJobIds() {
    final String path = String.format("%s/jobs", config.getMantaHomeDirectory());

    final MantaDirectoryListingIterator itr = new MantaDirectoryListingIterator(path, httpHelper, MAX_RESULTS);

    danglingStreams.add(itr);

    Stream<Map<String, Object>> backingStream = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(itr, Spliterator.ORDERED | Spliterator.NONNULL), false);

    return backingStream.map(item -> {
        final String id = Objects.toString(item.get("name"));
        return UUID.fromString(id);
    });
}