Example usage for java.util.stream Stream empty

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

Introduction

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

Prototype

public static <T> Stream<T> empty() 

Source Link

Document

Returns an empty sequential Stream .

Usage

From source file:com.homeadvisor.kafdrop.service.CuratorKafkaMonitor.java

private Map<String, TopicVO> getTopicMetadata(String... topics) {
    if (kafkaVersion.compareTo(new Version(0, 9, 0)) >= 0) {
        return retryTemplate
                .execute(context -> brokerChannel(null).execute(channel -> getTopicMetadata(channel, topics)));
    } else {//  ww w  . j  a v  a2s  . com
        Stream<String> topicStream;
        if (topics == null || topics.length == 0) {
            topicStream = Optional.ofNullable(topicTreeCache.getCurrentChildren(ZkUtils.BrokerTopicsPath()))
                    .map(Map::keySet).map(Collection::stream).orElse(Stream.empty());
        } else {
            topicStream = Stream.of(topics);
        }

        return topicStream.map(this::getTopicZkData).filter(Objects::nonNull)
                .collect(Collectors.toMap(TopicVO::getName, topic -> topic));
    }
}

From source file:org.codice.ddf.configuration.migration.ImportMigrationManagerImplTest.java

@Test
public void testConstructorWhenZipFileNotFound() throws Exception {
    thrown.expect(MigrationException.class);
    thrown.expectCause(Matchers.instanceOf(FileNotFoundException.class));

    new ImportMigrationManagerImpl(report, exportFile, Stream.empty());
}

From source file:org.opensingular.flow.persistence.service.AbstractHibernatePersistenceService.java

@Override
public PROCESS_VERSION saveProcessVersion(PROCESS_VERSION processVersion) {
    SessionWrapper sw = getSession();/*from w w w. j a v a  2s  .  c om*/
    sw.saveOrUpdate(processVersion.getProcessDefinition());
    sw.saveOrUpdate(processVersion);
    sw.saveOrUpdate(processVersion.getVersionTasks().stream().map(tv -> tv.getTaskDefinition()));
    sw.saveOrUpdate(processVersion.getVersionTasks().stream()
            .flatMap(tv -> tv.getTaskDefinition().getRolesTask() != null
                    ? tv.getTaskDefinition().getRolesTask().stream()
                    : Stream.empty()));
    sw.saveOrUpdate(processVersion.getVersionTasks());
    sw.saveOrUpdate(processVersion.getVersionTasks().stream().flatMap(tv -> tv.getTransitions().stream()));

    sw.refresh(processVersion.getProcessDefinition());

    return retrieveProcessVersionByCod(processVersion.getCod());
}

From source file:org.codice.ddf.configuration.migration.ImportMigrationManagerImplTest.java

@Test
public void testConstructorWhenUnableToProcessMetadata() throws Exception {
    final IOException ioe = new IOException("testing");

    Mockito.doThrow(ioe).when(zip).getInputStream(zipEntry);

    thrown.expect(MigrationException.class);
    thrown.expectCause(Matchers.sameInstance(ioe));

    new ImportMigrationManagerImpl(report, exportFile, Stream.empty(), zip);
}

From source file:org.springframework.cloud.dataflow.server.stream.AppDeployerStreamDeployer.java

@Override
public Page<AppStatus> getAppStatuses(Pageable pageable) throws ExecutionException, InterruptedException {

    Iterable<StreamDefinition> streamDefinitions = this.streamDefinitionRepository.findAll();
    Iterable<StreamDeployment> streamDeployments = this.streamDeploymentRepository.findAll();

    List<String> appDeployerStreams = new ArrayList<>();
    for (StreamDeployment streamDeployment : streamDeployments) {
        appDeployerStreams.add(streamDeployment.getStreamName());

    }/*w  w w .j ava2 s .c  om*/

    List<StreamDefinition> appDeployerStreamDefinitions = new ArrayList<>();
    for (StreamDefinition streamDefinition : streamDefinitions) {
        if (appDeployerStreams.contains(streamDefinition.getName())) {
            appDeployerStreamDefinitions.add(streamDefinition);
        }
    }

    // First build a sorted list of deployment id's so that we have a predictable paging order.
    List<String> deploymentIds = appDeployerStreamDefinitions.stream()
            .flatMap(sd -> sd.getAppDefinitions().stream()).flatMap(sad -> {
                String key = DeploymentKey.forStreamAppDefinition(sad);
                String id = this.deploymentIdRepository.findOne(key);
                return id != null ? Stream.of(id) : Stream.empty();
            }).sorted(String::compareTo).collect(Collectors.toList());

    // Running this this inside the FJP will make sure it is used by the parallel stream
    // Skip first items depending on page size, then take page and discard rest.
    List<AppStatus> content = this.forkJoinPool.submit(() -> deploymentIds.stream()
            .skip(pageable.getPageNumber() * pageable.getPageSize()).limit(pageable.getPageSize()).parallel()
            .map(appDeployer::status).collect(Collectors.toList())).get();
    return new PageImpl<>(content, pageable, deploymentIds.size());
}

From source file:org.codice.ddf.configuration.migration.ImportMigrationManagerImplTest.java

@Test
public void testConstructorWhenZipIsOfInvalidVersion() throws Exception {
    zipEntry = getMetadataZipEntry(zip, Optional.of(VERSION), Optional.of(PRODUCT_VERSION));

    thrown.expect(MigrationException.class);
    thrown.expectMessage("unsupported exported version");

    new ImportMigrationManagerImpl(report, exportFile, Stream.empty(), zip);
}

From source file:org.icgc.dcc.portal.pql.convert.FiltersConverter.java

private static <T> Stream<T> tail(@NonNull List<T> list) {
    val size = list.size();

    return (size < 2) ? Stream.empty() : IntStream.range(1, size).boxed().map(i -> list.get(i));
}

From source file:com.uber.hoodie.common.util.TestCompactionUtils.java

private Map<String, Pair<String, HoodieCompactionOperation>> generateExpectedCompactionOperations(
        List<HoodieCompactionPlan> plans) {
    return plans.stream().flatMap(plan -> {
        if (plan.getOperations() != null) {
            return plan.getOperations().stream()
                    .map(op -> Pair.of(op.getFileId(), Pair.of(op.getBaseInstantTime(), op)));
        }/*from  ww  w . ja  v a2 s .  co  m*/
        return Stream.empty();
    }).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
}

From source file:org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph.java

@Override
public Iterator<Edge> edges(final Object... edgeIds) {
    this.tx().readWrite();
    final Predicate<Neo4jRelationship> relationshipPredicate = this.trait.getRelationshipPredicate();
    if (0 == edgeIds.length) {
        return IteratorUtils.stream(this.getBaseGraph().allRelationships()).filter(relationshipPredicate)
                .map(relationship -> (Edge) new Neo4jEdge(relationship, this)).iterator();
    } else {/*from   ww w.j a  v  a 2 s  .c om*/
        ElementHelper.validateMixedElementIds(Edge.class, edgeIds);
        return Stream.of(edgeIds).map(id -> {
            if (id instanceof Number)
                return ((Number) id).longValue();
            else if (id instanceof String)
                return Long.valueOf(id.toString());
            else if (id instanceof Edge) {
                return (Long) ((Edge) id).id();
            } else
                throw new IllegalArgumentException("Unknown edge id type: " + id);
        }).flatMap(id -> {
            try {
                return Stream.of(this.baseGraph.getRelationshipById(id));
            } catch (final RuntimeException e) {
                if (Neo4jHelper.isNotFound(e))
                    return Stream.empty();
                throw e;
            }
        }).filter(relationshipPredicate).map(relationship -> (Edge) new Neo4jEdge(relationship, this))
                .iterator();
    }
}

From source file:com.cloudera.oryx.app.serving.als.model.ALSServingModel.java

public Stream<Pair<String, Double>> topN(CosineDistanceSensitiveFunction scoreFn,
        ObjDoubleToDoubleFunction<String> rescoreFn, int howMany, Predicate<String> allowedPredicate) {

    int[] candidateIndices = lsh.getCandidateIndices(scoreFn.getTargetVector());
    List<Callable<Stream<Pair<String, Double>>>> tasks = new ArrayList<>(candidateIndices.length);
    for (int partition : candidateIndices) {
        if (Y[partition].size() > 0) {
            tasks.add(LoggingCallable.log(() -> {
                TopNConsumer consumer = new TopNConsumer(howMany, scoreFn, rescoreFn, allowedPredicate);
                Y[partition].forEach(consumer);
                return consumer.getTopN();
            }));//from  w w w .  j a  v  a2  s .  co  m
        }
    }

    int numTasks = tasks.size();
    if (numTasks == 0) {
        return Stream.empty();
    }

    Stream<Pair<String, Double>> stream;
    if (numTasks == 1) {
        try {
            stream = tasks.get(0).call();
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    } else {
        try {
            stream = executor.invokeAll(tasks).stream().map(future -> {
                try {
                    return future.get();
                } catch (InterruptedException e) {
                    throw new IllegalStateException(e);
                } catch (ExecutionException e) {
                    throw new IllegalStateException(e.getCause());
                }
            }).reduce(Stream::concat).get();
        } catch (InterruptedException e) {
            throw new IllegalStateException(e);
        }
    }
    return stream.sorted(Pairs.orderBySecond(Pairs.SortOrder.DESCENDING)).limit(howMany);
}