package expression;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * @author Doschennikov Nikita (me@fymio.us)
 */
public class Clear extends AbstractBinaryOperation {

    public Clear(AbstractExpression l, AbstractExpression r) {
        super(l, r);
    }

    @Override
    protected String getOperator() {
        return "clear";
    }

    @Override
    protected int getPriority() {
        return 0;
    }

    @Override
    protected boolean isRightAssoc() {
        return true;
    }

    @Override
    protected int applyInt(int a, int b) {
        return a & ~(1 << b);
    }

    @Override
    protected BigInteger applyBi(BigInteger a, BigInteger b) {
        return a.clearBit(b.intValueExact());
    }

    @Override
    protected BigDecimal applyBd(BigDecimal a, BigDecimal b) {
        throw new UnsupportedOperationException(
            "clear not supported for BigDecimal"
        );
    }
}
