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

com.noenv.wiremongo.mapping.WithQuery Maven / Gradle / Ivy

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

import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.WithQueryCommand;
import com.noenv.wiremongo.mapping.collection.WithCollection;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;

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

public abstract class WithQuery> extends WithCollection {

  private Matcher query;

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

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

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy