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.ikanow.aleph2.data_model.utils.CrudUtils.java

protected static Stream<Tuple2<String, Object>> recursiveQueryBuilder_init(final Object bean,
        final boolean denest) {
    if (null == bean) { // (for handling JSON, where you don't have a bean)
        return Stream.of();
    }/*from   ww  w.  ja v a2 s . c o m*/
    //TODO (ALEPH-22) sometimes you need to nest the functionality and sometimes you don't... (eg updates normally not? queries normally
    // but actually the behavior is different .. to test this desnest==false, need to bring mongojack into the test context
    // so can test it for MongoDB

    return Arrays.stream(bean.getClass().getDeclaredFields()).filter(f -> !Modifier.isStatic(f.getModifiers())) // (ignore static fields)
            .flatMap(field_accessor -> {
                try {
                    field_accessor.setAccessible(true);
                    Object val = field_accessor.get(bean);

                    return Patterns.match(val).<Stream<Tuple2<String, Object>>>andReturn()
                            .when(v -> null == v, v -> Stream.empty())
                            .when(String.class, v -> Stream.of(Tuples._2T(field_accessor.getName(), v)))
                            .when(Number.class, v -> Stream.of(Tuples._2T(field_accessor.getName(), v)))
                            .when(Boolean.class, v -> Stream.of(Tuples._2T(field_accessor.getName(), v)))
                            .when(Collection.class, l -> Stream.of(Tuples._2T(field_accessor.getName(), l))) // (note can't denest objects/bean templates, that will exception out)
                            .when(Map.class, v -> Stream.of(Tuples._2T(field_accessor.getName(), v)))
                            .when(Multimap.class, v -> Stream.of(Tuples._2T(field_accessor.getName(), v)))
                            // OK if it's none of these supported types that we recognize, then assume it's a bean and recursively de-nest it
                            .when(BeanTemplate.class, v -> denest,
                                    v -> recursiveQueryBuilder_recurse(field_accessor.getName(), v))
                            .when(BeanTemplate.class, v -> Stream.of(Tuples._2T(field_accessor.getName(), v)))
                            .when(v -> denest,
                                    v -> recursiveQueryBuilder_recurse(field_accessor.getName(),
                                            BeanTemplate.of(v)))
                            .otherwise(
                                    v -> Stream.of(Tuples._2T(field_accessor.getName(), BeanTemplate.of(v))));
                } catch (Exception e) {
                    return null;
                }
            });
}

From source file:org.trellisldp.http.AbstractTrellisHttpResourceTest.java

@Test
public void testDeleteNoChildren1() {
    when(mockVersionedResource.getInteractionModel()).thenReturn(LDP.BasicContainer);
    when(mockVersionedResource.stream(eq(LDP.PreferContainment))).thenAnswer(inv -> Stream.empty());

    final Response res = target(RESOURCE_PATH).request().delete();

    assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!");
}

From source file:org.trellisldp.http.AbstractTrellisHttpResourceTest.java

@Test
public void testDeleteNoChildren2() {
    when(mockVersionedResource.getInteractionModel()).thenReturn(LDP.Container);
    when(mockVersionedResource.stream(eq(LDP.PreferContainment))).thenAnswer(inv -> Stream.empty());

    final Response res = target(RESOURCE_PATH).request().delete();

    assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!");
}

From source file:com.ikanow.aleph2.data_import_manager.analytics.actors.DataBucketAnalyticsChangeActor.java

/** Combine the analytic thread level results and the per-job results into a single reply
 * @param top_level//from  w  ww . j  a  va 2  s .c o m
 * @param per_job
 * @param source
 * @return
 */
protected final static CompletableFuture<BucketActionReplyMessage> combineResults(
        final CompletableFuture<BasicMessageBean> top_level,
        final List<CompletableFuture<BasicMessageBean>> per_job, final String source) {
    if (per_job.isEmpty()) {
        return top_level.thenApply(reply -> new BucketActionHandlerMessage(source, reply));
    } else { // slightly more complex:

        // First off wait for them all to complete:
        final CompletableFuture<?>[] futures = per_job.toArray(new CompletableFuture<?>[0]);

        return top_level.thenCombine(CompletableFuture.allOf(futures), (thread, __) -> {
            List<BasicMessageBean> replies = Stream.concat(Lambdas.get(() -> {
                if (thread.success() && ((null == thread.message()) || thread.message().isEmpty())) {
                    // Ignore top level, it's not very interesting
                    return Stream.empty();
                } else
                    return Stream.of(thread);
            }), per_job.stream().map(cf -> cf.join())

            ).collect(Collectors.toList());

            return (BucketActionReplyMessage) new BucketActionCollectedRepliesMessage(source, replies,
                    Collections.emptySet(), Collections.emptySet());
        }).exceptionally(t -> {
            return (BucketActionReplyMessage) new BucketActionHandlerMessage(source,
                    ErrorUtils.buildErrorMessage(DataBucketAnalyticsChangeActor.class.getSimpleName(), source,
                            ErrorUtils.getLongForm("{0}", t)));
        });
    }
}

From source file:com.ikanow.aleph2.data_import_manager.analytics.actors.DataBucketAnalyticsChangeActor.java

/** Creates a query component to get all the shared library beans i need
 * @param bucket/*from  w  w w . java  2 s.c o m*/
 * @param cache_tech_jar_only
 * @return
 */
protected static QueryComponent<SharedLibraryBean> getQuery(final DataBucketBean bucket,
        final boolean cache_tech_jar_only) {
    final String technology = getAnalyticsTechnologyName(bucket).get(); //(non-empty by construction)
    final SingleQueryComponent<SharedLibraryBean> tech_query = CrudUtils.anyOf(SharedLibraryBean.class)
            .when(SharedLibraryBean::_id, technology).when(SharedLibraryBean::path_name, technology);

    final Stream<SingleQueryComponent<SharedLibraryBean>> other_libs = cache_tech_jar_only ? Stream.empty()
            : Optionals.ofNullable(bucket.analytic_thread().jobs()).stream()
                    .flatMap(a_job -> Stream.concat(
                            Optional.ofNullable(a_job.module_name_or_id()).map(Stream::of)
                                    .orElse(Stream.empty()),
                            Optionals.ofNullable(a_job.library_names_or_ids()).stream()))
                    .map(name -> {
                        return CrudUtils.anyOf(SharedLibraryBean.class).when(SharedLibraryBean::_id, name)
                                .when(SharedLibraryBean::path_name, name);
                    });

    return CrudUtils.<SharedLibraryBean>anyOf(Stream.concat(Stream.of(tech_query), other_libs));
}

From source file:org.trellisldp.http.AbstractLdpResourceTest.java

@Test
public void testDeleteNoChildren1() {
    when(mockVersionedResource.getInteractionModel()).thenReturn(LDP.BasicContainer);
    when(mockVersionedResource.stream(eq(LDP.PreferContainment))).thenAnswer(inv -> Stream.empty());

    final Response res = target(RESOURCE_PATH).request().delete();

    assertEquals(NO_CONTENT, res.getStatusInfo());
}

From source file:org.trellisldp.http.AbstractLdpResourceTest.java

@Test
public void testDeleteNoChildren2() {
    when(mockVersionedResource.getInteractionModel()).thenReturn(LDP.Container);
    when(mockVersionedResource.stream(eq(LDP.PreferContainment))).thenAnswer(inv -> Stream.empty());

    final Response res = target(RESOURCE_PATH).request().delete();

    assertEquals(NO_CONTENT, res.getStatusInfo());
}