Class BaseUInt384Value<T extends UInt384Value<T>>

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

public abstract class BaseUInt384Value<T extends UInt384Value<T>> extends Object implements UInt384Value<T>
Base class for UInt384Value.

This class is abstract as it is not meant to be used directly, but it has no abstract methods. As mentioned in UInt384Value, this is used to create strongly-typed type aliases of UInt384. 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 UInt384Value, but also adds a few operations that take a UInt384 directly, for instance multiply(UInt384). 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

    • BaseUInt384Value

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

      protected BaseUInt384Value(long value, Function<UInt384,T> ctor)
      Parameters:
      value - An unsigned value to instantiate this UInt384Value with.
      ctor - A constructor for the concrete type.
    • BaseUInt384Value

      protected BaseUInt384Value(BigInteger value, Function<UInt384,T> ctor)
      Parameters:
      value - An unsigned value to instantiate this UInt384Value 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 Bytes48.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: UInt384Value
      Returns a value that is (this + value).
      Specified by:
      add in interface UInt384Value<T extends UInt384Value<T>>
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • add

      public T add(UInt384 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(long value)
      Description copied from interface: UInt384Value
      Returns a value that is (this + value).
      Specified by:
      add in interface UInt384Value<T extends UInt384Value<T>>
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • addMod

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

      public T addMod(UInt384 value, UInt384 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, UInt384 modulus)
      Description copied from interface: UInt384Value
      Returns a value equivalent to ((this + value) mod modulus).
      Specified by:
      addMod in interface UInt384Value<T extends UInt384Value<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: UInt384Value
      Returns a value equivalent to ((this + value) mod modulus).
      Specified by:
      addMod in interface UInt384Value<T extends UInt384Value<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: UInt384Value
      Returns a value that is (this - value).
      Specified by:
      subtract in interface UInt384Value<T extends UInt384Value<T>>
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • subtract

      public T subtract(UInt384 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(long value)
      Description copied from interface: UInt384Value
      Returns a value that is (this - value).
      Specified by:
      subtract in interface UInt384Value<T extends UInt384Value<T>>
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • multiply

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

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

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

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

      public T multiplyMod(UInt384 value, UInt384 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(long value, UInt384 modulus)
      Description copied from interface: UInt384Value
      Returns a value that is ((this * value) mod modulus).
      Specified by:
      multiplyMod in interface UInt384Value<T extends UInt384Value<T>>
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
    • multiplyMod

      public T multiplyMod(long value, long modulus)
      Description copied from interface: UInt384Value
      Returns a value that is ((this * value) mod modulus).
      Specified by:
      multiplyMod in interface UInt384Value<T extends UInt384Value<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: UInt384Value
      Returns a value that is (this / value).
      Specified by:
      divide in interface UInt384Value<T extends UInt384Value<T>>
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
    • divide

      public T divide(UInt384 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(long value)
      Description copied from interface: UInt384Value
      Returns a value that is (this / value).
      Specified by:
      divide in interface UInt384Value<T extends UInt384Value<T>>
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
    • pow

      public T pow(UInt384 exponent)
      Description copied from interface: UInt384Value
      Returns a value that is (this<sup>exponent</sup> mod 2<sup>384</sup>)

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

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

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

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

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

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

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

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

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

      public int compareTo(UInt384 other)
      Compare two UInt384 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
    • toUInt384

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

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

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