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

io.github.olib963.javatest.matchers.MatchResult Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package io.github.olib963.javatest.matchers;

import java.util.Optional;
import java.util.function.Function;

public final class MatchResult {
    public final boolean matches;
    public final Optional mismatch;
    private MatchResult(boolean matches, Optional mismatch) {
        this.matches = matches;
        this.mismatch = mismatch;
    }

    public static MatchResult of(boolean matches) {
        return of(matches, Optional.empty());
    }

    public static MatchResult of(boolean matches, Optional mismatch) {
        return new MatchResult(matches, mismatch);
    }

    public static MatchResult match() {
        return new MatchResult(true, Optional.empty());
    }

    public static MatchResult mismatch(){
        return new MatchResult(false, Optional.empty());
    }

    public static MatchResult mismatch(String mismatch){
        return new MatchResult(false, Optional.of(mismatch));
    }

    public MatchResult mapMismatch(Function mismatchFunction) {
        return new MatchResult(matches, mismatch.map(mismatchFunction));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy