package expression.generic;

/**
 * @author Doschennikov Nikita (me@fymio.us)
 */
public class IntUncheckedType implements ArithmeticType<Integer> {

    public static final IntUncheckedType INSTANCE = new IntUncheckedType();

    private IntUncheckedType() {}

    @Override
    public Integer fromInt(int value) {
        return value;
    }

    @Override
    public Integer add(Integer a, Integer b) {
        return a + b;
    }

    @Override
    public Integer subtract(Integer a, Integer b) {
        return a - b;
    }

    @Override
    public Integer multiply(Integer a, Integer b) {
        return a * b;
    }

    @Override
    public Integer divide(Integer a, Integer b) {
        if (b == 0) throw new ArithmeticException("Division by zero");
        return a / b;
    }

    @Override
    public Integer negate(Integer a) {
        return -a;
    }

    @Override
    public Integer count(Integer a) {
        return Integer.bitCount(a);
    }

    @Override
    public Integer min(Integer a, Integer b) {
        return Math.min(a, b);
    }

    @Override
    public Integer max(Integer a, Integer b) {
        return Math.max(a, b);
    }
}
