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

org.checkerframework.common.value.util.ByteMath Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java's type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.42.0-eisop4
Show newest version
package org.checkerframework.common.value.util;

import org.checkerframework.checker.nullness.qual.Nullable;

public class ByteMath extends NumberMath {
    byte number;

    public ByteMath(byte i) {
        number = i;
    }

    @Override
    public Number plus(Number right) {
        if (right instanceof Byte) {
            return number + right.byteValue();
        }
        if (right instanceof Double) {
            return number + right.doubleValue();
        }
        if (right instanceof Float) {
            return number + right.floatValue();
        }
        if (right instanceof Integer) {
            return number + right.intValue();
        }
        if (right instanceof Long) {
            return number + right.longValue();
        }
        if (right instanceof Short) {
            return number + right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number minus(Number right) {
        if (right instanceof Byte) {
            return number - right.byteValue();
        }
        if (right instanceof Double) {
            return number - right.doubleValue();
        }
        if (right instanceof Float) {
            return number - right.floatValue();
        }
        if (right instanceof Integer) {
            return number - right.intValue();
        }
        if (right instanceof Long) {
            return number - right.longValue();
        }
        if (right instanceof Short) {
            return number - right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number times(Number right) {
        if (right instanceof Byte) {
            return number * right.byteValue();
        }
        if (right instanceof Double) {
            return number * right.doubleValue();
        }
        if (right instanceof Float) {
            return number * right.floatValue();
        }
        if (right instanceof Integer) {
            return number * right.intValue();
        }
        if (right instanceof Long) {
            return number * right.longValue();
        }
        if (right instanceof Short) {
            return number * right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public @Nullable Number divide(Number right) {
        if (isIntegralZero(right)) {
            return null;
        }
        if (right instanceof Byte) {
            return number / right.byteValue();
        }
        if (right instanceof Double) {
            return number / right.doubleValue();
        }
        if (right instanceof Float) {
            return number / right.floatValue();
        }
        if (right instanceof Integer) {
            return number / right.intValue();
        }
        if (right instanceof Long) {
            return number / right.longValue();
        }
        if (right instanceof Short) {
            return number / right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public @Nullable Number remainder(Number right) {
        if (isIntegralZero(right)) {
            return null;
        }
        if (right instanceof Byte) {
            return number % right.byteValue();
        }
        if (right instanceof Double) {
            return number % right.doubleValue();
        }
        if (right instanceof Float) {
            return number % right.floatValue();
        }
        if (right instanceof Integer) {
            return number % right.intValue();
        }
        if (right instanceof Long) {
            return number % right.longValue();
        }
        if (right instanceof Short) {
            return number % right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number shiftLeft(Number right) {
        if (right instanceof Byte) {
            return number << right.byteValue();
        }
        if (right instanceof Integer) {
            return number << right.intValue();
        }
        if (right instanceof Long) {
            return number << right.longValue();
        }
        if (right instanceof Short) {
            return number << right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number signedShiftRight(Number right) {
        if (right instanceof Byte) {
            return number >> right.byteValue();
        }
        if (right instanceof Integer) {
            return number >> right.intValue();
        }
        if (right instanceof Long) {
            return number >> right.longValue();
        }
        if (right instanceof Short) {
            return number >> right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number unsignedShiftRight(Number right) {
        if (right instanceof Byte) {
            return number >>> right.byteValue();
        }
        if (right instanceof Integer) {
            return number >>> right.intValue();
        }
        if (right instanceof Long) {
            return number >>> right.longValue();
        }
        if (right instanceof Short) {
            return number >>> right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number bitwiseAnd(Number right) {
        if (right instanceof Byte) {
            return number & right.byteValue();
        }
        if (right instanceof Integer) {
            return number & right.intValue();
        }
        if (right instanceof Long) {
            return number & right.longValue();
        }
        if (right instanceof Short) {
            return number & right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number bitwiseXor(Number right) {
        if (right instanceof Byte) {
            return number ^ right.byteValue();
        }
        if (right instanceof Integer) {
            return number ^ right.intValue();
        }
        if (right instanceof Long) {
            return number ^ right.longValue();
        }
        if (right instanceof Short) {
            return number ^ right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number bitwiseOr(Number right) {
        if (right instanceof Byte) {
            return number | right.byteValue();
        }
        if (right instanceof Integer) {
            return number | right.intValue();
        }
        if (right instanceof Long) {
            return number | right.longValue();
        }
        if (right instanceof Short) {
            return number | right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Number unaryPlus() {
        return +number;
    }

    @Override
    public Number unaryMinus() {
        return -number;
    }

    @Override
    public Number bitwiseComplement() {
        return ~number;
    }

    @Override
    public Boolean equalTo(Number right) {
        if (right instanceof Byte) {
            return number == right.byteValue();
        }
        if (right instanceof Double) {
            return number == right.doubleValue();
        }
        if (right instanceof Float) {
            return number == right.floatValue();
        }
        if (right instanceof Integer) {
            return number == right.intValue();
        }
        if (right instanceof Long) {
            return number == right.longValue();
        }
        if (right instanceof Short) {
            return number == right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Boolean notEqualTo(Number right) {
        if (right instanceof Byte) {
            return number != right.byteValue();
        }
        if (right instanceof Double) {
            return number != right.doubleValue();
        }
        if (right instanceof Float) {
            return number != right.floatValue();
        }
        if (right instanceof Integer) {
            return number != right.intValue();
        }
        if (right instanceof Long) {
            return number != right.longValue();
        }
        if (right instanceof Short) {
            return number != right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Boolean greaterThan(Number right) {
        if (right instanceof Byte) {
            return number > right.byteValue();
        }
        if (right instanceof Double) {
            return number > right.doubleValue();
        }
        if (right instanceof Float) {
            return number > right.floatValue();
        }
        if (right instanceof Integer) {
            return number > right.intValue();
        }
        if (right instanceof Long) {
            return number > right.longValue();
        }
        if (right instanceof Short) {
            return number > right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Boolean greaterThanEq(Number right) {
        if (right instanceof Byte) {
            return number >= right.byteValue();
        }
        if (right instanceof Double) {
            return number >= right.doubleValue();
        }
        if (right instanceof Float) {
            return number >= right.floatValue();
        }
        if (right instanceof Integer) {
            return number >= right.intValue();
        }
        if (right instanceof Long) {
            return number >= right.longValue();
        }
        if (right instanceof Short) {
            return number >= right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Boolean lessThan(Number right) {
        if (right instanceof Byte) {
            return number < right.byteValue();
        }
        if (right instanceof Double) {
            return number < right.doubleValue();
        }
        if (right instanceof Float) {
            return number < right.floatValue();
        }
        if (right instanceof Integer) {
            return number < right.intValue();
        }
        if (right instanceof Long) {
            return number < right.longValue();
        }
        if (right instanceof Short) {
            return number < right.shortValue();
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public Boolean lessThanEq(Number right) {
        if (right instanceof Byte) {
            return number <= right.byteValue();
        }
        if (right instanceof Double) {
            return number <= right.doubleValue();
        }
        if (right instanceof Float) {
            return number <= right.floatValue();
        }
        if (right instanceof Integer) {
            return number <= right.intValue();
        }
        if (right instanceof Long) {
            return number <= right.longValue();
        }
        if (right instanceof Short) {
            return number <= right.shortValue();
        }
        throw new UnsupportedOperationException();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy