Class BaseUInt64Value<T extends UInt64Value<T>>
- Type Parameters:
T- The concrete type of the value.
- All Implemented Interfaces:
Comparable<T>,UInt64Value<T>
UInt64Value.
This class is abstract as it is not meant to be used directly, but it has no abstract methods.
As mentioned in UInt64Value, this is used to create strongly-typed type aliases of UInt64. 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 UInt64Value, but also adds a few operations that take a UInt64 directly, for instance multiply(UInt64). 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
ConstructorsModifierConstructorDescriptionprotectedBaseUInt64Value(long value, Function<UInt64, T> ctor) protectedBaseUInt64Value(BigInteger value, Function<UInt64, T> ctor) protectedBaseUInt64Value(UInt64 value, Function<UInt64, 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 twoUInt64values.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, UInt64 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(UInt64 value, UInt64 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(T value, UInt64 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>64</sup>)Returns a value that is(this<sup>exponent</sup> mod 2<sup>64</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.BytestoBytes()Returns the value as bytes.org.apache.tuweni.bytes.BytesReturns the value as bytes without any leading zero bytes.toString()toUInt64()Convert this value to aUInt64.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.UInt64Value
addExact, addExact, bitLength, fitsInt, fitsLong, intValue, isZero, numberOfLeadingZeros, subtractExact, subtractExact, toBigInteger, toDecimalString, toHexString, toLong, toShortHexString
-
Constructor Details
-
BaseUInt64Value
- Parameters:
value- The value to instantiate thisUInt64Valuewith.ctor- A constructor for the concrete type.
-
BaseUInt64Value
- Parameters:
value- An unsigned value to instantiate thisUInt64Valuewith.ctor- A constructor for the concrete type.
-
BaseUInt64Value
- Parameters:
value- An unsigned value to instantiate thisUInt64Valuewith.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
UInt64.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:UInt64ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt64Value<T extends UInt64Value<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:UInt64ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
addMod
Description copied from interface:UInt64ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt64Value<T extends UInt64Value<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:UInt64ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
addMod
Description copied from interface:UInt64ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
subtract
Description copied from interface:UInt64ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt64Value<T extends UInt64Value<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:UInt64ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
multiply
Description copied from interface:UInt64ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt64Value<T extends UInt64Value<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:UInt64ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiplyMod
Description copied from interface:UInt64ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt64Value<T extends UInt64Value<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:UInt64ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
multiplyMod
Description copied from interface:UInt64ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
divide
Description copied from interface:UInt64ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt64Value<T extends UInt64Value<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:UInt64ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
value- The amount to divide this value by.- Returns:
this / value
-
pow
Description copied from interface:UInt64ValueReturns a value that is(this<sup>exponent</sup> mod 2<sup>64</sup>)This calculates an exponentiation over the modulus of
2^64.Note that
exponentis anUInt64rather than of the typeT.- Specified by:
powin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
exponent- The exponent to which this value is to be raised.- Returns:
this<sup>exponent</sup> mod 2<sup>64</sup>
-
pow
Description copied from interface:UInt64ValueReturns a value that is(this<sup>exponent</sup> mod 2<sup>64</sup>)This calculates an exponentiation over the modulus of
2^64.- Specified by:
powin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
exponent- The exponent to which this value is to be raised.- Returns:
this<sup>exponent</sup> mod 2<sup>64</sup>
-
mod
Description copied from interface:UInt64ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
mod
Description copied from interface:UInt64ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt64Value<T extends UInt64Value<T>>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
compareTo
- Specified by:
compareToin interfaceComparable<T extends UInt64Value<T>>
-
compareTo
Compare twoUInt64values.- 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
-
toUInt64
Description copied from interface:UInt64ValueConvert this value to aUInt64.- Specified by:
toUInt64in interfaceUInt64Value<T extends UInt64Value<T>>- Returns:
- This value as a
UInt64.
-
toBytes
public org.apache.tuweni.bytes.Bytes toBytes()Description copied from interface:UInt64ValueReturns the value as bytes.- Specified by:
toBytesin interfaceUInt64Value<T extends UInt64Value<T>>- Returns:
- The value as bytes.
-
toMinimalBytes
public org.apache.tuweni.bytes.Bytes toMinimalBytes()Description copied from interface:UInt64ValueReturns the value as bytes without any leading zero bytes.- Specified by:
toMinimalBytesin interfaceUInt64Value<T extends UInt64Value<T>>- Returns:
- The value as bytes without any leading zero bytes.
-