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

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

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

import io.vertx.core.json.JsonObject;

import java.util.function.Function;

@FunctionalInterface
public interface Matcher {

  boolean matches(T o);

  static  Matcher create(JsonObject match) {
    return create(match, i -> (T)i, i -> i);
  }

  static  Matcher create(JsonObject match, Function fromJson, Function toJson) {
    if (match == null) {
      return null;
    }
    for(String k : match.getMap().keySet()) {
      if ("equalTo".equals(k)) {
        return EqualsMatcher.equalTo(fromJson.apply(match.getValue(k)));
      } else if ("equalToJson".equals(k)) {
        return new JsonMatcher<>(match, toJson);
      }
    }
    throw new IllegalArgumentException("no matcher found!");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy