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

com.noenv.wiremongo.matching.EqualsMatcher Maven / Gradle / Ivy

There is a newer version: 4.5.13
Show newest version
package com.noenv.wiremongo.matching;

import io.vertx.ext.mongo.BulkWriteOptions;
import io.vertx.ext.mongo.IndexOptions;

import java.util.Objects;

public class EqualsMatcher implements Matcher {

  private final T value;

  private EqualsMatcher(T value) {
    this.value = value;
  }

  @Override
  public boolean matches(T other) {

    //TODO: remove with vertx 4.0 (https://github.com/vert-x3/vertx-mongo-client/pull/168)
    if (other instanceof IndexOptions && value instanceof IndexOptions) {
      return Objects.equals(((IndexOptions)value).toJson(), ((IndexOptions)other).toJson());
    }

    //TODO: remove with vertx 4.0 (https://github.com/vert-x3/vertx-mongo-client/pull/169)
    if (other instanceof BulkWriteOptions && value instanceof BulkWriteOptions) {
      return Objects.equals(((BulkWriteOptions)value).toJson(), ((BulkWriteOptions)other).toJson());
    }

    return Objects.equals(value, other);
  }

  public static  EqualsMatcher equalTo(T value) {
    return new EqualsMatcher<>(value);
  }

  public static  Matcher notEqualTo(T value) {
    return o -> !equalTo(value).matches(o);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy