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

com.noenv.wiremongo.mapping.replace.WithReplace Maven / Gradle / Ivy

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

import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.replace.WithReplaceCommand;
import com.noenv.wiremongo.mapping.WithQuery;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;

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

public abstract class WithReplace> extends WithQuery {

  private Matcher replace;

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

  public WithReplace(JsonObject json) {
    super(json);
    replace = Matcher.create(json.getJsonObject("replace"));
  }

  @Override
  public boolean matches(Command cmd) {
    if (!super.matches(cmd)) {
      return false;
    }
    if (!(cmd instanceof WithReplaceCommand)) {
      return false;
    }
    WithReplaceCommand c = (WithReplaceCommand) cmd;
    return replace == null || replace.matches(c.getReplace());
  }

  public C withReplace(JsonObject replace) {
    return withReplace(equalTo(replace));
  }

  public C withReplace(Matcher replace) {
    this.replace = replace;
    return self();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy