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

com.github.dakusui.crest.matcherbuilders.ObjectMatcherBuilder Maven / Gradle / Ivy

package com.github.dakusui.crest.matcherbuilders;

import com.github.dakusui.crest.core.Matcher;
import com.github.dakusui.crest.functions.TransformingPredicate;
import com.github.dakusui.faultsource.printable.Predicates;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;

public abstract class ObjectMatcherBuilder> implements MatcherBuilder {
  private final Function function;
  private final List>        predicates;

  public ObjectMatcherBuilder(Function function) {
    this.function = function;
    this.predicates = new LinkedList<>();
  }

  @SuppressWarnings("unchecked")
  @Override
  public SELF check(Predicate predicate) {
    this.predicates.add(predicate);
    return (SELF) this;
  }

  @Override
  public 

SELF check(Function function, Predicate predicate) { return this.check(new TransformingPredicate(predicate, function)); } public SELF isNull() { return this.check(Predicates.isNull()); } public SELF isNotNull() { return this.check(Predicates.isNotNull()); } public SELF isSameAs(OUT value) { return this.check(Predicates.isSameAs(value)); } public SELF isInstanceOf(Class value) { return this.check(Predicates.isInstanceOf(value)); } @Override public Matcher all() { return matcher(Op.AND); } @Override public Matcher any() { return matcher(Op.OR); } private Matcher matcher(Op op) { return (predicates.size() == 1) ? Matcher.Leaf.create(predicates.get(0), this.function) : Objects.requireNonNull(op).create(predicates, this.function); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy