Example usage for java.util.stream StreamSupport stream

List of usage examples for java.util.stream StreamSupport stream

Introduction

In this page you can find the example usage for java.util.stream StreamSupport stream.

Prototype

public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel) 

Source Link

Document

Creates a new sequential or parallel Stream from a Spliterator .

Usage

From source file:net.dv8tion.jda.core.utils.cache.impl.AbstractCacheView.java

@Override
public Stream<T> parallelStream() {
    return StreamSupport.stream(spliterator(), true);
}

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();
    }/*from   w ww . j  a  v  a2 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:org.mskcc.shenkers.data.interval.GIntervalTreeMap.java

public Stream<IntervalFeature<T>> streamOverlaps(String chr, int start, int end) {
    boolean parallel = false;
    int characteristics = 0;
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(query(chr, start, end), characteristics),
            parallel);//from  w ww.j a  va2s.c  om
}

From source file:org.jboss.forge.addon.springboot.commands.jpa.SpringBootJPASetupWizard.java

private void initProviders() {
    jpaProvider.setItemLabelConverter(PersistenceProvider::getName);

    // select Hibernate provider as the default one
    final PersistenceProvider hibernate = StreamSupport
            .stream(jpaProvider.getValueChoices().spliterator(), false)
            .filter(provider -> provider.getName().toLowerCase().contains("hibernate")).findFirst()
            .orElseThrow(() -> new IllegalStateException("Hibernate Persistence Provider is not available"));

    jpaProvider.setDefaultValue(hibernate);
}

From source file:com.github.rutledgepaulv.qbuilders.structures.FieldPath.java

private static <T> Stream<T> streamIter(Iterable<T> iterable) {
    return StreamSupport.stream(iterable.spliterator(), false);
}

From source file:fi.vrk.xroad.catalog.persistence.CatalogServiceImpl.java

@Override
public void saveAllMembersAndSubsystems(Collection<Member> members) {
    LocalDateTime now = LocalDateTime.now();
    // process members
    Map<MemberId, Member> unprocessedOldMembers = new HashMap<>();
    StreamSupport.stream(memberRepository.findAll().spliterator(), false)
            .forEach(member -> unprocessedOldMembers.put(member.createKey(), member));

    for (Member member : members) {
        Member oldMember = unprocessedOldMembers.get(member.createKey());
        if (oldMember == null) {
            // brand new item
            member.getStatusInfo().setTimestampsForNew(now);
            for (Subsystem subsystem : member.getAllSubsystems()) {
                subsystem.getStatusInfo().setTimestampsForNew(now);
                subsystem.setMember(member);
            }/*w ww .ja va 2  s  .  c o m*/
            member = memberRepository.save(member);
        } else {
            handleOldMember(now, member, oldMember);

            member = memberRepository.save(oldMember);
        }
        unprocessedOldMembers.remove(member.createKey());
    }
    // now unprocessedOldMembers should all be removed (either already removed, or will be now)
    removeUnprocessedOldMembers(now, unprocessedOldMembers);
}

From source file:org.mskcc.shenkers.data.interval.GIntervalTree.java

public Stream<Node> streamOverlapNodes(String chr, int start, int end, Strand strand) {
    boolean parallel = false;
    int characteristics = 0;
    return StreamSupport.stream(
            Spliterators.spliteratorUnknownSize(queryNodes(chr, start, end, strand), characteristics),
            parallel);//w  w w . j  a va2 s  .  com
}

From source file:com.linecorp.armeria.server.docs.DocService.java

/**
 * Creates a new instance, prepopulating debug forms with the provided {@code sampleRequests}.
 * {@code sampleRequests} should be a list of Thrift argument objects for methods that should be
 * prepopulated (e.g., a populated hello_args object for the hello method on HelloService).
 *///w  w  w . j  av  a  2 s. co  m
public DocService(Iterable<? extends TBase<?, ?>> sampleRequests) {
    super(ofExact("/specification.json", HttpFileService.forVfs(new DocServiceVfs())),
            ofCatchAll(HttpFileService.forClassPath(DocService.class.getClassLoader(),
                    "com/linecorp/armeria/server/docs")));
    requireNonNull(sampleRequests, "sampleRequests");
    this.sampleRequests = StreamSupport.stream(sampleRequests.spliterator(), false)
            .collect(Collectors.toMap(Object::getClass, Function.identity()));
}

From source file:org.eclipse.sw360.licenseinfo.parsers.AbstractCLIParser.java

private Stream<Node> streamFromNodeList(NodeList nodes) {
    Iterator<Node> iter = new NodeListIterator(nodes);
    Iterable<Node> iterable = () -> iter;
    return StreamSupport.stream(iterable.spliterator(), false);
}

From source file:com.github.steveash.guavate.Guavate.java

/**
 * Creates a stream that wraps a stream with the index.
 * <p>/*from w  w  w.  ja  v  a 2 s .  com*/
 * Each input object is decorated with an {@link ObjIntPair}.
 * The {@code int} is the index of the element in the stream.
 * @param <T> the type of the stream
 * @param stream the stream to index
 * @return a stream of pairs, containing the element and index
 */
public static <T> Stream<ObjIntPair<T>> zipWithIndex(Stream<T> stream) {
    Spliterator<T> split1 = stream.spliterator();
    Iterator<T> it1 = Spliterators.iterator(split1);
    Iterator<ObjIntPair<T>> it = new Iterator<ObjIntPair<T>>() {
        int index = 0;

        @Override
        public boolean hasNext() {
            return it1.hasNext();
        }

        @Override
        public ObjIntPair<T> next() {
            return ObjIntPair.of(it1.next(), index++);
        }
    };
    Spliterator<ObjIntPair<T>> split = Spliterators.spliterator(it, split1.getExactSizeIfKnown(),
            split1.characteristics());
    return StreamSupport.stream(split, false);
}