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

io.split.engine.matchers.BooleanMatcher Maven / Gradle / Ivy

There is a newer version: 4.13.0
Show newest version
package io.split.engine.matchers;

import io.split.engine.evaluator.Evaluator;

import java.util.Map;

import static io.split.engine.matchers.Transformers.asBoolean;

public class BooleanMatcher implements Matcher {
    private boolean _booleanValue;

    public BooleanMatcher(boolean booleanValue) {
        _booleanValue = booleanValue;
    }

    @Override
    public boolean match(Object matchValue, String bucketingKey, Map attributes, Evaluator evaluator) {
        if (matchValue == null) {
            return false;
        }

        Boolean valueAsBoolean = asBoolean(matchValue);

        return valueAsBoolean != null && valueAsBoolean == _booleanValue;
    }

    @Override
    public String toString() {
        return "is " + _booleanValue;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BooleanMatcher that = (BooleanMatcher) o;

        return _booleanValue == that._booleanValue;
    }

    @Override
    public int hashCode() {
        return (_booleanValue ? 1 : 0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy