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

com.noenv.wiremongo.mapping.find.FindOneAndReplaceWithOptions Maven / Gradle / Ivy

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

import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.find.FindOneAndReplaceWithOptionsCommand;
import com.noenv.wiremongo.matching.JsonMatcher;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.mongo.FindOptions;
import io.vertx.ext.mongo.UpdateOptions;

@SuppressWarnings("squid:MaximumInheritanceDepth")
public class FindOneAndReplaceWithOptions extends FindOneAndReplaceBase {

  private Matcher findOptions;
  private Matcher updateOptions;

  public FindOneAndReplaceWithOptions() {
    super("findOneAndReplaceWithOptions");
  }

  public FindOneAndReplaceWithOptions(JsonObject json) {
    super(json);
    this.findOptions = Matcher.create(json.getJsonObject("findOptions"), j -> new FindOptions((JsonObject) j), FindOptions::toJson);
    this.updateOptions = Matcher.create(json.getJsonObject("updateOptions"), j -> new UpdateOptions((JsonObject) j), UpdateOptions::toJson);
  }

  @Override
  public boolean matches(Command cmd) {
    if (!super.matches(cmd)) {
      return false;
    }
    if (!(cmd instanceof FindOneAndReplaceWithOptionsCommand)) {
      return false;
    }
    FindOneAndReplaceWithOptionsCommand c = (FindOneAndReplaceWithOptionsCommand) cmd;
    return (findOptions == null || findOptions.matches(c.getFindOptions()))
      && (updateOptions == null || updateOptions.matches(c.getUpdateOptions()));
  }

  public FindOneAndReplaceWithOptions withFindOptions(FindOptions findOptions) {
    return withFindOptions(JsonMatcher.equalToJson(findOptions.toJson(), FindOptions::toJson));
  }

  public FindOneAndReplaceWithOptions withFindOptions(Matcher findOptions) {
    this.findOptions = findOptions;
    return self();
  }

  public FindOneAndReplaceWithOptions withUpdateOptions(UpdateOptions updateOptions) {
    return withUpdateOptions(JsonMatcher.equalToJson(updateOptions.toJson(), UpdateOptions::toJson));
  }

  public FindOneAndReplaceWithOptions withUpdateOptions(Matcher updateOptions) {
    this.updateOptions = updateOptions;
    return self();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy