Class BaseUInt384Value<T extends UInt384Value<T>>
- Type Parameters:
T- The concrete type of the value.
- All Implemented Interfaces:
Comparable<T>,UInt384Value<T>
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 Summary
ConstructorsModifierConstructorDescriptionprotectedBaseUInt384Value(long value, Function<UInt384, T> ctor) protectedBaseUInt384Value(BigInteger value, Function<UInt384, T> ctor) protectedBaseUInt384Value(UInt384 value, Function<UInt384, T> ctor) -
Method Summary
Modifier and TypeMethodDescriptionadd(long value) Returns a value that is(this + value).Returns a value that is(this + value).Returns a value that is(this + value).addMod(long value, long modulus) Returns a value equivalent to((this + value) mod modulus).Returns a value equivalent to((this + value) mod modulus).Returns a value equivalent to((this + value) mod modulus).Returns a value equivalent to((this + value) mod modulus).intCompare twoUInt384values.intprotected Tcopy()Return a copy of this value, or itself if immutable.divide(long value) Returns a value that is(this / value).Returns a value that is(this / value).Returns a value that is(this / value).booleaninthashCode()mod(long modulus) Returns a value that is(this mod modulus).Returns a value that is(this mod modulus).multiply(long value) Returns a value that is(this * value).Returns a value that is(this * value).Returns a value that is(this * value).multiplyMod(long value, long modulus) Returns a value that is((this * value) mod modulus).multiplyMod(long value, UInt384 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(UInt384 value, UInt384 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(T value, UInt384 modulus) Returns a value that is((this * value) mod modulus).pow(long exponent) Returns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)Returns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)subtract(long value) Returns a value that is(this - value).Returns a value that is(this - value).Returns a value that is(this - value).org.apache.tuweni.bytes.Bytes48toBytes()Returns the value as bytesorg.apache.tuweni.bytes.BytesRetuns the value as bytes without any leading zero bytes.toString()Convert this value to aUInt384.protected Tzero()Return the zero value for this type.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.tuweni.units.bigints.UInt384Value
addExact, addExact, bitLength, fitsInt, fitsLong, intValue, isZero, numberOfLeadingZeros, subtractExact, subtractExact, toBigInteger, toDecimalString, toHexString, toLong, toShortHexString
-
Constructor Details
-
BaseUInt384Value
- Parameters:
value- The value to instantiate thisUInt384Valuewith.ctor- A constructor for the concrete type.
-
BaseUInt384Value
- Parameters:
value- An unsigned value to instantiate thisUInt384Valuewith.ctor- A constructor for the concrete type.
-
BaseUInt384Value
- Parameters:
value- An unsigned value to instantiate thisUInt384Valuewith.ctor- A constructor for the concrete type.
-
-
Method Details
-
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 returnthis.- Returns:
- A copy of this value, or itself if immutable.
-
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
Description copied from interface:UInt384ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
add
Returns a value that is(this + value).- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
add
Description copied from interface:UInt384ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
addMod
Description copied from interface:UInt384ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
addMod
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
Description copied from interface:UInt384ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
addMod
Description copied from interface:UInt384ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
subtract
Description copied from interface:UInt384ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
subtract
Returns a value that is(this - value).- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
subtract
Description copied from interface:UInt384ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
multiply
Description copied from interface:UInt384ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiply
Returns a value that is(this * value).- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiply
Description copied from interface:UInt384ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiplyMod
Description copied from interface:UInt384ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
multiplyMod
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 ormodulus== 0.
-
multiplyMod
Description copied from interface:UInt384ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
multiplyMod
Description copied from interface:UInt384ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
divide
Description copied from interface:UInt384ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to divide this value by.- Returns:
this / value
-
divide
Returns a value that is(this / value).- Parameters:
value- The amount to divide this value by.- Returns:
this / value- Throws:
ArithmeticException-value== 0.
-
divide
Description copied from interface:UInt384ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
value- The amount to divide this value by.- Returns:
this / value
-
pow
Description copied from interface:UInt384ValueReturns 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
exponentis anUInt384rather than of the typeT.- Specified by:
powin interfaceUInt384Value<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
Description copied from interface:UInt384ValueReturns 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:
powin interfaceUInt384Value<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
Description copied from interface:UInt384ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
mod
Description copied from interface:UInt384ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt384Value<T extends UInt384Value<T>>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
compareTo
- Specified by:
compareToin interfaceComparable<T extends UInt384Value<T>>
-
compareTo
Compare twoUInt384values.- 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
-
hashCode
public int hashCode() -
toString
-
toUInt384
Description copied from interface:UInt384ValueConvert this value to aUInt384.- Specified by:
toUInt384in interfaceUInt384Value<T extends UInt384Value<T>>- Returns:
- This value as a
UInt384.
-
toBytes
public org.apache.tuweni.bytes.Bytes48 toBytes()Description copied from interface:UInt384ValueReturns the value as bytes- Specified by:
toBytesin interfaceUInt384Value<T extends UInt384Value<T>>- Returns:
- The value as bytes.
-
toMinimalBytes
public org.apache.tuweni.bytes.Bytes toMinimalBytes()Description copied from interface:UInt384ValueRetuns the value as bytes without any leading zero bytes.- Specified by:
toMinimalBytesin interfaceUInt384Value<T extends UInt384Value<T>>- Returns:
- The value as bytes without any leading zero bytes.
-