package expression;

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

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

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

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

    @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.setBit(b.intValueExact());
    }

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