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

org.fluentlenium.core.conditions.AbstractObjectConditions Maven / Gradle / Ivy

package org.fluentlenium.core.conditions;

import java.util.function.Predicate;

/**
 * Abstract implementation supported negation and instantiation.
 *
 * @param  type of condition
 */
public abstract class AbstractObjectConditions implements Conditions, ConditionsObject {
    protected final T object;
    protected boolean negation;

    /**
     * Initialize the conditions with given object.
     *
     * @param object underlying object
     */
    public AbstractObjectConditions(T object) {
        this.object = object;
    }

    /**
     * Initialize the conditions with given object
     *
     * @param object   underlying object
     * @param negation negation value
     */
    public AbstractObjectConditions(T object, boolean negation) {
        this.object = object;
        this.negation = negation;
    }

    @Override
    public boolean verify(Predicate predicate) {
        boolean predicateResult = predicate.test(object);
        if (negation) {
            predicateResult = !predicateResult;
        }
        return predicateResult;
    }

    @Override
    public T getActualObject() {
        return object;
    }

    /**
     * Creates a new instance of this condition.
     *
     * @param negationValue negation value
     * @return new instance of this condition
     */
    protected abstract AbstractObjectConditions newInstance(boolean negationValue);

    @Override
    @Negation
    public AbstractObjectConditions not() {
        return newInstance(!negation);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy