All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.noenv.wiremongo.mapping.stream.WithStream Maven / Gradle / Ivy

There is a newer version: 4.5.10
Show newest version
package com.noenv.wiremongo.mapping.stream;

import com.noenv.wiremongo.MemoryStream;
import com.noenv.wiremongo.command.stream.WithStreamCommand;
import com.noenv.wiremongo.mapping.collection.WithCollection;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.streams.ReadStream;

import java.util.stream.Collectors;

public abstract class WithStream> extends WithCollection, U, C> {

  public WithStream(String method) {
    super(method);
  }

  public WithStream(JsonObject json) {
    super(json);
  }

  @Override
  public C returns(final ReadStream response) {
    return super.stub(c -> response instanceof MemoryStream ? ((MemoryStream) response).copy(JsonObject::copy) : response);
  }

  @Override
  protected ReadStream parseResponse(Object jsonValue) {
    return MemoryStream.fromList(((JsonArray) jsonValue).stream()
      .map(o -> (JsonObject) o)
      .collect(Collectors.toList()));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy