Class BaseUInt32Value<T extends UInt32Value<T>>
- Type Parameters:
T- The concrete type of the value.
- All Implemented Interfaces:
Comparable<T>,UInt32Value<T>
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 Summary
ConstructorsModifierConstructorDescriptionprotectedBaseUInt32Value(int value, Function<UInt32, T> ctor) protectedBaseUInt32Value(BigInteger value, Function<UInt32, T> ctor) protectedBaseUInt32Value(UInt32 value, Function<UInt32, T> ctor) -
Method Summary
Modifier and TypeMethodDescriptionadd(int 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 twoUInt32values.intprotected Tcopy()Return a copy of this value, or itself if immutable.divide(int value) Returns a value that is(this / value).Returns a value that is(this / value).Returns a value that is(this / value).booleaninthashCode()mod(int modulus) Returns a value that is(this mod modulus).Returns a value that is(this mod modulus).multiply(int value) Returns a value that is(this * value).Returns a value that is(this * value).Returns a value that is(this * value).multiplyMod(int value, int modulus) Returns a value that is((this * value) mod modulus).multiplyMod(int value, UInt32 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(UInt32 value, UInt32 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(T value, UInt32 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>32</sup>)Returns a value that is(this<sup>exponent</sup> mod 2<sup>32</sup>)subtract(int 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()Provides the value as bytes.org.apache.tuweni.bytes.BytesProvides the value as bytes without any leading zero bytestoString()toUInt32()Convert this value to aUInt32.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.UInt32Value
addExact, addExact, bitLength, fitsInt, fitsLong, intValue, isZero, numberOfLeadingZeros, subtractExact, subtractExact, toBigInteger, toDecimalString, toHexString, toLong, toShortHexString
-
Constructor Details
-
BaseUInt32Value
- Parameters:
value- The value to instantiate thisUInt32Valuewith.ctor- A constructor for the concrete type.
-
BaseUInt32Value
- Parameters:
value- An unsigned value to instantiate thisUInt32Valuewith.ctor- A constructor for the concrete type.
-
BaseUInt32Value
- Parameters:
value- An unsigned value to instantiate thisUInt32Valuewith.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
UInt32.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:UInt32ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt32Value<T extends UInt32Value<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:UInt32ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
addMod
Description copied from interface:UInt32ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt32Value<T extends UInt32Value<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:UInt32ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
addMod
Description copied from interface:UInt32ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
subtract
Description copied from interface:UInt32ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt32Value<T extends UInt32Value<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:UInt32ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
multiply
Description copied from interface:UInt32ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt32Value<T extends UInt32Value<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:UInt32ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiplyMod
Description copied from interface:UInt32ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt32Value<T extends UInt32Value<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:UInt32ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
multiplyMod
Description copied from interface:UInt32ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
divide
Description copied from interface:UInt32ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt32Value<T extends UInt32Value<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:UInt32ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
value- The amount to divide this value by.- Returns:
this / value
-
pow
Description copied from interface:UInt32ValueReturns 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
exponentis anUInt32rather than of the typeT.- Specified by:
powin interfaceUInt32Value<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
Description copied from interface:UInt32ValueReturns 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:
powin interfaceUInt32Value<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
Description copied from interface:UInt32ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
mod
Description copied from interface:UInt32ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt32Value<T extends UInt32Value<T>>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
compareTo
- Specified by:
compareToin interfaceComparable<T extends UInt32Value<T>>
-
compareTo
Compare twoUInt32values.- 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
-
toUInt32
Description copied from interface:UInt32ValueConvert this value to aUInt32.- Specified by:
toUInt32in interfaceUInt32Value<T extends UInt32Value<T>>- Returns:
- This value as a
UInt32.
-
toBytes
public org.apache.tuweni.bytes.Bytes toBytes()Description copied from interface:UInt32ValueProvides the value as bytes.- Specified by:
toBytesin interfaceUInt32Value<T extends UInt32Value<T>>- Returns:
- The value as bytes.
-
toMinimalBytes
public org.apache.tuweni.bytes.Bytes toMinimalBytes()Description copied from interface:UInt32ValueProvides the value as bytes without any leading zero bytes- Specified by:
toMinimalBytesin interfaceUInt32Value<T extends UInt32Value<T>>- Returns:
- The value as bytes without any leading zero bytes.
-