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

com.noenv.wiremongo.mapping.distinct.DistinctBatchWithQuery Maven / Gradle / Ivy

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

import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.distinct.DistinctBatchWithQueryCommand;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;

import static com.noenv.wiremongo.matching.EqualsMatcher.equalTo;

@SuppressWarnings("squid:MaximumInheritanceDepth")
public class DistinctBatchWithQuery extends DistinctBatchBase {

  private Matcher query;
  private Matcher batchSize;

  public DistinctBatchWithQuery() {
    super("distinctBatchWithQuery");
  }

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

  public DistinctBatchWithQuery(JsonObject json) {
    super(json);
    this.query = Matcher.create(json.getJsonObject("query"));
    this.batchSize = Matcher.create(json.getJsonObject("batchSize"));
  }

  @Override
  public boolean matches(Command cmd) {
    if (!super.matches(cmd)) {
      return false;
    }
    if (!(cmd instanceof DistinctBatchWithQueryCommand)) {
      return false;
    }
    DistinctBatchWithQueryCommand c = (DistinctBatchWithQueryCommand) cmd;
    return (query == null || query.matches(c.getQuery()))
      && (batchSize == null || batchSize.matches(c.getBatchSize()));
  }

  public DistinctBatchWithQuery withQuery(JsonObject query) {
    return withQuery(equalTo(query));
  }

  public DistinctBatchWithQuery withQuery(Matcher query) {
    this.query = query;
    return self();
  }

  public DistinctBatchWithQuery withBatchSize(Integer batchSize) {
    return withBatchSize(equalTo(batchSize));
  }

  public DistinctBatchWithQuery withBatchSize(Matcher batchSize) {
    this.batchSize = batchSize;
    return self();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy