package org.reckon.formula.condition;

import static org.reckon.formula.ValuePreparer.getBooleanValue;

/**
 * Used to compare between 2 booleans and return true if the conditions differ.
 * <ul>
 * <li><b><i>{@code true}</i></b> XOR <b><i>{@code true}</i></b> => <b><i>{@code false}</i></b></li>
 * <li><b><i>{@code true}</i></b> XOR <b><i>{@code false}</i></b> => <b><i>{@code true}</i></b></li>
 * <li><b><i>{@code false}</i></b> XOR <b><i>{@code true}</i></b> => <b><i>{@code true}</i></b></li>
 * <li><b><i>{@code false}</i></b> XOR <b><i>{@code false}</i></b> => <b><i>{@code false}</i></b></li>
 * </ul>
 *
 * @author PlaySafe
 */
public class Xor extends LogicGate implements Condition {

    public Xor(String variable1, String variable2) {
        super(variable1, variable2);
    }

    public Xor(String variable1, Condition condition2) {
        super(variable1, condition2);
    }

    public Xor(Condition condition1, String variable2) {
        super(condition1, variable2);
    }

    public Xor(Condition condition1, Condition condition2) {
        super(condition1, condition2);
    }

    @Override
    public boolean matches(Object object) {
        boolean value1 = getBooleanValue(object, getVariable1(), getCondition1());
        boolean value2 = getBooleanValue(object, getVariable2(), getCondition2());
        return value1 ^ value2;
    }
}
