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

com.noenv.wiremongo.mapping.aggregate.AggregateWithOptions Maven / Gradle / Ivy

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

import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.aggregate.AggregateWithOptionsCommand;
import com.noenv.wiremongo.matching.JsonMatcher;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.mongo.AggregateOptions;

@SuppressWarnings("squid:MaximumInheritanceDepth")
public class AggregateWithOptions extends AggregateBase {

  private Matcher options;

  public AggregateWithOptions() {
    super("aggregateWithOptions");
  }

  public AggregateWithOptions(JsonObject json) {
    super(json);
    options = Matcher.create(json.getJsonObject("options"), j -> new AggregateOptions((JsonObject) j), AggregateOptions::toJson);
  }

  @Override
  public boolean matches(Command cmd) {
    if (!super.matches(cmd)) {
      return false;
    }
    if (!(cmd instanceof AggregateWithOptionsCommand)) {
      return false;
    }
    AggregateWithOptionsCommand c = (AggregateWithOptionsCommand) cmd;
    return options == null || options.matches(c.getOptions());
  }

  public AggregateWithOptions withOptions(AggregateOptions options) {
    return withOptions(JsonMatcher.equalToJson(options.toJson(), AggregateOptions::toJson));
  }

  public AggregateWithOptions withOptions(Matcher options) {
    this.options = options;
    return self();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy