Class BaseUInt32Value<T extends UInt32Value<T>>

java.lang.Object
org.apache.tuweni.units.bigints.BaseUInt32Value<T>
Type Parameters:
T - The concrete type of the value.
All Implemented Interfaces:
Comparable<T>, UInt32Value<T>

public abstract class BaseUInt32Value<T extends UInt32Value<T>> extends Object implements UInt32Value<T>
Base class for UInt32Value.

This class is abstract as it is not meant to be used directly, but it has no abstract methods. As mentioned in UInt32Value, this is used to create strongly-typed type aliases of UInt32. In other words, this allow to "tag" numbers with the unit of what they represent for the type-system, which can help clarity, but also forbid mixing numbers that are mean to be of different units (the strongly-typed part).

This class implements UInt32Value, but also adds a few operations that take a UInt32 directly, for instance multiply(UInt32). The rational is that multiplying a given quantity of something by a "raw" number is always meaningful, and return a new quantity of the same thing.

  • Constructor Details

    • BaseUInt32Value

      protected BaseUInt32Value(UInt32 value, Function<UInt32,T> ctor)
      Parameters:
      value - The value to instantiate this UInt32Value with.
      ctor - A constructor for the concrete type.
    • BaseUInt32Value

      protected BaseUInt32Value(int value, Function<UInt32,T> ctor)
      Parameters:
      value - An unsigned value to instantiate this UInt32Value with.
      ctor - A constructor for the concrete type.
    • BaseUInt32Value

      protected BaseUInt32Value(BigInteger value, Function<UInt32,T> ctor)
      Parameters:
      value - An unsigned value to instantiate this UInt32Value with.
      ctor - A constructor for the concrete type.
  • Method Details

    • copy

      protected T copy()
      Return a copy of this value, or itself if immutable.

      The default implementation of this method returns a copy using the constructor for the concrete type and the bytes returned from toBytes(). Most implementations will want to override this method to instead return this.

      Returns:
      A copy of this value, or itself if immutable.
    • zero

      protected T zero()
      Return the zero value for this type.

      The default implementation of this method returns a value obtained from calling the concrete type constructor with an argument of UInt32.ZERO. Most implementations will want to override this method to instead return a static constant.

      Returns:
      The zero value for this type.
    • add

      public T add(T value)
      Description copied from interface: UInt32Value
      Returns a value that is (this + value).
      Specified by:
      add in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • add

      public T add(UInt32 value)
      Returns a value that is (this + value).
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • add

      public T add(int value)
      Description copied from interface: UInt32Value
      Returns a value that is (this + value).
      Specified by:
      add in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • addMod

      public T addMod(T value, UInt32 modulus)
      Description copied from interface: UInt32Value
      Returns a value equivalent to ((this + value) mod modulus).
      Specified by:
      addMod in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
    • addMod

      public T addMod(UInt32 value, UInt32 modulus)
      Returns a value equivalent to ((this + value) mod modulus).
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
      Throws:
      ArithmeticException - modulus == 0.
    • addMod

      public T addMod(long value, UInt32 modulus)
      Description copied from interface: UInt32Value
      Returns a value equivalent to ((this + value) mod modulus).
      Specified by:
      addMod in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
    • addMod

      public T addMod(long value, long modulus)
      Description copied from interface: UInt32Value
      Returns a value equivalent to ((this + value) mod modulus).
      Specified by:
      addMod in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
    • subtract

      public T subtract(T value)
      Description copied from interface: UInt32Value
      Returns a value that is (this - value).
      Specified by:
      subtract in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • subtract

      public T subtract(UInt32 value)
      Returns a value that is (this - value).
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • subtract

      public T subtract(int value)
      Description copied from interface: UInt32Value
      Returns a value that is (this - value).
      Specified by:
      subtract in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • multiply

      public T multiply(T value)
      Description copied from interface: UInt32Value
      Returns a value that is (this * value).
      Specified by:
      multiply in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to multiply this value by.
      Returns:
      this * value
    • multiply

      public T multiply(UInt32 value)
      Returns a value that is (this * value).
      Parameters:
      value - The amount to multiply this value by.
      Returns:
      this * value
    • multiply

      public T multiply(int value)
      Description copied from interface: UInt32Value
      Returns a value that is (this * value).
      Specified by:
      multiply in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to multiply this value by.
      Returns:
      this * value
    • multiplyMod

      public T multiplyMod(T value, UInt32 modulus)
      Description copied from interface: UInt32Value
      Returns a value that is ((this * value) mod modulus).
      Specified by:
      multiplyMod in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
    • multiplyMod

      public T multiplyMod(UInt32 value, UInt32 modulus)
      Returns a value that is ((this * value) mod modulus).
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
      Throws:
      ArithmeticException - value < 0 or modulus == 0.
    • multiplyMod

      public T multiplyMod(int value, UInt32 modulus)
      Description copied from interface: UInt32Value
      Returns a value that is ((this * value) mod modulus).
      Specified by:
      multiplyMod in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
    • multiplyMod

      public T multiplyMod(int value, int modulus)
      Description copied from interface: UInt32Value
      Returns a value that is ((this * value) mod modulus).
      Specified by:
      multiplyMod in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
    • divide

      public T divide(T value)
      Description copied from interface: UInt32Value
      Returns a value that is (this / value).
      Specified by:
      divide in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
    • divide

      public T divide(UInt32 value)
      Returns a value that is (this / value).
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
      Throws:
      ArithmeticException - value == 0.
    • divide

      public T divide(int value)
      Description copied from interface: UInt32Value
      Returns a value that is (this / value).
      Specified by:
      divide in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
    • pow

      public T pow(UInt32 exponent)
      Description copied from interface: UInt32Value
      Returns a value that is (this<sup>exponent</sup> mod 2<sup>32</sup>)

      This calculates an exponentiation over the modulus of 2^32.

      Note that exponent is an UInt32 rather than of the type T.

      Specified by:
      pow in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      exponent - The exponent to which this value is to be raised.
      Returns:
      this<sup>exponent</sup> mod 2<sup>32</sup>
    • pow

      public T pow(long exponent)
      Description copied from interface: UInt32Value
      Returns a value that is (this<sup>exponent</sup> mod 2<sup>32</sup>)

      This calculates an exponentiation over the modulus of 2^32.

      Specified by:
      pow in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      exponent - The exponent to which this value is to be raised.
      Returns:
      this<sup>exponent</sup> mod 2<sup>32</sup>
    • mod

      public T mod(UInt32 modulus)
      Description copied from interface: UInt32Value
      Returns a value that is (this mod modulus).
      Specified by:
      mod in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      modulus - The modulus.
      Returns:
      this mod modulus.
    • mod

      public T mod(int modulus)
      Description copied from interface: UInt32Value
      Returns a value that is (this mod modulus).
      Specified by:
      mod in interface UInt32Value<T extends UInt32Value<T>>
      Parameters:
      modulus - The modulus.
      Returns:
      this mod modulus.
    • compareTo

      public int compareTo(T other)
      Specified by:
      compareTo in interface Comparable<T extends UInt32Value<T>>
    • compareTo

      public int compareTo(UInt32 other)
      Compare two UInt32 values.
      Parameters:
      other - The value to compare to.
      Returns:
      A negative integer, zero, or a positive integer as this value is less than, equal to, or greater than the specified value.
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object
    • toUInt32

      public UInt32 toUInt32()
      Description copied from interface: UInt32Value
      Convert this value to a UInt32.
      Specified by:
      toUInt32 in interface UInt32Value<T extends UInt32Value<T>>
      Returns:
      This value as a UInt32.
    • toBytes

      public org.apache.tuweni.bytes.Bytes toBytes()
      Description copied from interface: UInt32Value
      Provides the value as bytes.
      Specified by:
      toBytes in interface UInt32Value<T extends UInt32Value<T>>
      Returns:
      The value as bytes.
    • toMinimalBytes

      public org.apache.tuweni.bytes.Bytes toMinimalBytes()
      Description copied from interface: UInt32Value
      Provides the value as bytes without any leading zero bytes
      Specified by:
      toMinimalBytes in interface UInt32Value<T extends UInt32Value<T>>
      Returns:
      The value as bytes without any leading zero bytes.