Class Integer

java.lang.Object
java.lang.Number
org.episteme.core.mathematics.numbers.integers.Integer
All Implemented Interfaces:
Serializable, Comparable<Integer>, AbelianGroup<Integer>, AbelianMonoid<Integer>, Group<Integer>, Magma<Integer>, Monoid<Integer>, Ring<Integer>, RingElement<Integer>, Semiring<Integer>, Set<Integer>

public abstract class Integer extends Number implements Ring<Integer>, Comparable<Integer>, RingElement<Integer>
Abstract base class for integers (ℤ = {..., -2, -1, 0, 1, 2, ...}).

Integers form a Ring under addition and multiplication. This class provides a smart factory that automatically chooses the most efficient backing implementation:

    Since:
    1.0
    Author:
    Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
    See Also:
    • Field Details

      • ZERO

        public static final Integer ZERO
        The integer 0
      • ONE

        public static final Integer ONE
        The integer 1
      • MINUS_ONE

        public static final Integer MINUS_ONE
        The integer -1
    • Method Details

      • of

        public static Integer of(int value)
        Creates an integer from an int value.
        Parameters:
        value - the value
        Returns:
        the Integer instance
      • of

        public static Integer of(long value)
        Creates an integer from a long value. Automatically selects optimal backing implementation.
        Parameters:
        value - the value
        Returns:
        the Integer instance
      • of

        public static Integer of(BigInteger value)
        Creates an integer from a BigInteger. Automatically selects optimal backing implementation.
        Parameters:
        value - the value
        Returns:
        the Integer instance
        Throws:
        IllegalArgumentException - if value is null
      • valueOf

        public static Integer valueOf(String value)
        Creates an integer from a String representation.
        Parameters:
        value - the string value
        Returns:
        the Integer instance
      • add

        public abstract Integer add(Integer other)
        Adds another integer.
        Specified by:
        add in interface RingElement<Integer>
        Parameters:
        other - the addend
        Returns:
        this + other
      • subtract

        public abstract Integer subtract(Integer other)
        Subtracts another integer.
        Specified by:
        subtract in interface RingElement<Integer>
        Parameters:
        other - the subtrahend
        Returns:
        this - other
      • multiply

        public abstract Integer multiply(Integer other)
        Multiplies by another integer.
        Specified by:
        multiply in interface RingElement<Integer>
        Parameters:
        other - the multiplicand
        Returns:
        this × other
      • divide

        public abstract Integer divide(Integer other)
        Divides by another integer (integer division).
        Parameters:
        other - the divisor
        Returns:
        this / other (truncated towards zero)
        Throws:
        ArithmeticException - if other is zero
      • remainder

        public abstract Integer remainder(Integer other)
        Computes the remainder of division.
        Parameters:
        other - the divisor
        Returns:
        this % other
        Throws:
        ArithmeticException - if other is zero
      • negate

        public abstract Integer negate()
        Returns the negation of this integer.
        Specified by:
        negate in interface RingElement<Integer>
        Returns:
        -this
      • abs

        public abstract Integer abs()
        Returns the absolute value of this integer.
        Returns:
        |this|
      • isZero

        public abstract boolean isZero()
        Returns true if this integer is zero.
        Specified by:
        isZero in interface RingElement<Integer>
        Returns:
        true if this equals zero()
      • isOne

        public abstract boolean isOne()
        Returns true if this integer is one.
        Specified by:
        isOne in interface RingElement<Integer>
        Returns:
        true if this equals one()
      • longValue

        public abstract long longValue()
        Converts this integer to a long.
        Specified by:
        longValue in class Number
        Returns:
        the long value
        Throws:
        ArithmeticException - if the value doesn't fit in a long
      • bigIntegerValue

        public abstract BigInteger bigIntegerValue()
        Converts this integer to a BigInteger.
        Returns:
        the BigInteger value (never null)
      • mod

        public abstract Integer mod(Integer divisor)
        Returns the remainder of the division of this integer by the specified integer.
        Parameters:
        divisor - the divisor
        Returns:
        this % divisor
        Throws:
        ArithmeticException - if divisor is zero
      • equals

        public abstract boolean equals(Object obj)
        Overrides:
        equals in class Object
      • hashCode

        public abstract int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public abstract String toString()
        Overrides:
        toString in class Object
      • compareTo

        public abstract int compareTo(Integer other)
        Specified by:
        compareTo in interface Comparable<Integer>
      • signum

        public int signum()
        Returns the signum function of this integer.
        Returns:
        -1, 0 or 1 as the value of this integer is negative, zero or positive.
      • doubleValue

        public double doubleValue()
        Converts this integer to a double.
        Specified by:
        doubleValue in class Number
        Returns:
        this integer as a double
      • gcd

        public Integer gcd(Integer other)
        Returns the greatest common divisor of absolute value of this integer and absolute value of other integer.
        Parameters:
        other - the other integer
        Returns:
        gcd(|this|, |other|)
      • zero

        public Integer zero()
        Description copied from interface: AbelianMonoid
        Returns the additive identity (zero element).

        Delegates to AbelianMonoid.identity().

        Specified by:
        zero in interface AbelianMonoid<Integer>
        Specified by:
        zero in interface RingElement<Integer>
        Returns:
        the zero element
      • one

        public Integer one()
        Description copied from interface: Semiring
        Returns the multiplicative identity (one element).

        Satisfies: 1 × a = a × 1 = a for all elements a.

        Specified by:
        one in interface RingElement<Integer>
        Specified by:
        one in interface Semiring<Integer>
        Returns:
        the multiplicative identity
      • toRational

        public Rational toRational()
        Returns the rational number equivalent to this integer.
        Returns:
        the rational instance