Example usage for java.util.stream Stream flatMap

List of usage examples for java.util.stream Stream flatMap

Introduction

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

Prototype

<R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper);

Source Link

Document

Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.

Usage

From source file:org.apache.hadoop.hbase.master.assignment.AssignmentManagerUtil.java

static void removeNonDefaultReplicas(MasterProcedureEnv env, Stream<RegionInfo> regions,
        int regionReplication) {
    // Remove from in-memory states
    regions.flatMap(hri -> IntStream.range(1, regionReplication)
            .mapToObj(i -> RegionReplicaUtil.getRegionInfoForReplica(hri, i))).forEach(hri -> {
                env.getAssignmentManager().getRegionStates().deleteRegion(hri);
                env.getMasterServices().getServerManager().removeRegion(hri);
                FavoredNodesManager fnm = env.getMasterServices().getFavoredNodesManager();
                if (fnm != null) {
                    fnm.deleteFavoredNodesForRegions(Collections.singletonList(hri));
                }/*ww  w  .j  ava 2 s  .c  o m*/
            });
}

From source file:org.kitodo.production.services.data.TaskService.java

/**
 * Drops all folders to generate if they are their own source folder.
 *
 * @param projects/*from  w  w w .  jav a 2  s.c o  m*/
 *            projects whose folders allowed to be generated are to be
 *            determined
 * @return a stream of folders that are allowed to be generated
 */
private static Stream<Folder> dropOwnSourceFolders(Stream<Project> projects) {
    Stream<Pair<Folder, Folder>> withSources = projects.flatMap(project -> project.getFolders().stream()
            .map(folder -> Pair.of(folder, project.getGeneratorSource())));
    Stream<Pair<Folder, Folder>> filteredWithSources = withSources.filter(
            destinationAndSource -> !destinationAndSource.getLeft().equals(destinationAndSource.getRight()));
    return filteredWithSources.map(Pair::getLeft);
}

From source file:org.lightjason.agentspeak.language.CCommon.java

/**
 * recursive stream of term values/*from w  w  w . ja  v a  2 s  . c  om*/
 *
 * @param p_input term stream
 * @return term stream
 */
public static Stream<ITerm> recursiveterm(final Stream<ITerm> p_input) {
    return p_input.flatMap(
            i -> i instanceof ILiteral ? recursiveterm((i.<ILiteral>raw()).orderedvalues()) : Stream.of(i));
}

From source file:org.lightjason.agentspeak.language.CCommon.java

/**
 * recursive stream of literal values//from  w w  w  . j  a va  2s . co m
 *
 * @param p_input term stream
 * @return term stream
 *
 * @note annotations cannot use annotation within
 */
public static Stream<ITerm> recursiveliteral(final Stream<ILiteral> p_input) {
    return p_input.flatMap(i -> recursiveterm(i.orderedvalues()));
}