java.lang.Object
ushiosan.jvm.UNumber
-
Method Summary
Modifier and TypeMethodDescriptionstatic intconverts an array of flags to a single valuestatic intgetBitValue(boolean status) Gets the value of the bit in numeric formatstatic booleangetByteBit(@NotNull Number value) Gets the value of the specific bit from the given numberstatic booleangetByteBit(@NotNull Number value, int index) Gets the value of the specific bit from the given numberstatic intgetByteBit(@NotNull Number value, int index, byte mask) Gets the value of the specific bit from the given numberstatic booleanGets the value of the specific bit from the given numberstatic booleanGets the value of the specific bit from the given numberstatic intGets the value of the specific bit from the given numberstatic booleangetLongBit(@NotNull Number value) Gets the value of the specific bit from the given numberstatic booleangetLongBit(@NotNull Number value, int index) Gets the value of the specific bit from the given numberstatic longgetLongBit(@NotNull Number value, int index, long mask) Gets the value of the specific bit from the given numberstatic booleangetShortBit(@NotNull Number value) Gets the value of the specific bit from the given numberstatic booleangetShortBit(@NotNull Number value, int index) Gets the value of the specific bit from the given numberstatic intgetShortBit(@NotNull Number value, int index, short mask) Gets the value of the specific bit from the given numberstatic booleanhasFlag(int content, int flag) Identifies if a flag is already within the specified valuestatic booleanDetermine if a decimal number contains decimals after the floating point.parse(@NotNull CharSequence content) Returns a newNumberinitialized to the value represented by the specifiedString.static int[]randomRange(@NotNull Random random, int start, int end, int size, boolean inclusive) Generate an array of pseudorandom numbers within a specified rangestatic long[]randomRange(@NotNull Random random, long start, long end, int size, boolean inclusive) Generate an array of pseudorandom numbers within a specified rangestatic bytesetByteBit(@NotNull Number value, int index, boolean status) Method used to change a specific bit from the given numberstatic intMethod used to change a specific bit from the given numberstatic longsetLongBit(@NotNull Number value, int index, boolean status) Method used to change a specific bit from the given numberstatic shortsetShortBit(@NotNull Number value, int index, boolean status) Method used to change a specific bit from the given numbertoBinaryString(@NotNull Number number) Converts a binary number to a bit-text representationtoBinaryString(@NotNull Number number, boolean separator) Converts a binary number to a bit-text representationstatic inttoUnsignedByte(byte data) Converts a signed byte to an unsigned byte.
-
Method Details
-
isDecimal
Determine if a decimal number contains decimals after the floating point.- Parameters:
number- the number to evaluate- Returns:
trueif the number contains decimals orfalseotherwise
-
parse
Returns a newNumberinitialized to the value represented by the specifiedString.- Parameters:
content- the string to be parsed- Returns:
- the
Numbervalue represented by the string argument orOptional.empty()if content is not valid number
-
randomRange
public static int[] randomRange(@NotNull @NotNull Random random, int start, int end, int size, boolean inclusive) Generate an array of pseudorandom numbers within a specified range- Parameters:
random- thr random content generator instancestart- the start of the range (inclusive)end- the end of the range (no inclusive)size- total elements in arrayinclusive- iftruethe end of the range is included within the allowed valuesfalseif the end of the range is excluded from the allowed values- Returns:
- an array of pseudorandom numbers
-
randomRange
public static long[] randomRange(@NotNull @NotNull Random random, long start, long end, int size, boolean inclusive) Generate an array of pseudorandom numbers within a specified range- Parameters:
random- thr random content generator instancestart- the start of the range (inclusive)end- the end of the range (no inclusive)size- total elements in arrayinclusive- iftruethe end of the range is included within the allowed valuesfalseif the end of the range is excluded from the allowed values- Returns:
- an array of pseudorandom numbers
-
toUnsignedByte
public static int toUnsignedByte(byte data) Converts a signed byte to an unsigned byte. Since bytes can only be signed, then the type is changed to an integer that can hold the value of an unsigned byte if an overflow occurs.- Parameters:
data- the byte you want to change- Returns:
- returns the unsigned byte
-
getBitValue
public static int getBitValue(boolean status) Gets the value of the bit in numeric format- Parameters:
status- the state of the bit you want to get- Returns:
1if the bit istrueor0if it isfalse
-
getByteBit
public static int getByteBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L}) int index, byte mask) Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyzeindex- the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number0mask- the mask to determine the value of the bit- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getByteBit
public static boolean getByteBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L}) int index) Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyzeindex- the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number0- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getByteBit
Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyze- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
setByteBit
public static byte setByteBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L}) int index, boolean status) Method used to change a specific bit from the given number- Parameters:
value- the value you want to manipulateindex- the index of the bit you want to change. It is necessary to clarify that, like arrays, bit indices begin with the number0status- the new value of the specified bit. The new value of the specified bit. Let's remember that a bit is the smallest unit in computing and can only have 2 values,0or1, where0isfalseand1istrue.- Returns:
- the new value with the bit changed
- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getShortBit
public static int getShortBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L}) int index, short mask) Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyzeindex- the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number0mask- the mask to determine the value of the bit- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getShortBit
public static boolean getShortBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L}) int index) Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyzeindex- the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number0- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getShortBit
Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyze- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
setShortBit
public static short setShortBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L}) int index, boolean status) Method used to change a specific bit from the given number- Parameters:
value- the value you want to manipulateindex- the index of the bit you want to change. It is necessary to clarify that, like arrays, bit indices begin with the number0status- the new value of the specified bit. The new value of the specified bit. Let's remember that a bit is the smallest unit in computing and can only have 2 values,0or1, where0isfalseand1istrue.- Returns:
- the new value with the bit changed
- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getIntBit
public static int getIntBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,24L,25L,26L,27L,28L,29L,30L,31L}) int index, int mask) Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyzeindex- the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number0mask- the mask to determine the value of the bit- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getIntBit
public static boolean getIntBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,24L,25L,26L,27L,28L,29L,30L,31L}) int index) Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyzeindex- the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number0- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getIntBit
Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyze- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
setIntBit
public static int setIntBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,24L,25L,26L,27L,28L,29L,30L,31L}) int index, boolean status) Method used to change a specific bit from the given number- Parameters:
value- the value you want to manipulateindex- the index of the bit you want to change. It is necessary to clarify that, like arrays, bit indices begin with the number0status- the new value of the specified bit. The new value of the specified bit. Let's remember that a bit is the smallest unit in computing and can only have 2 values,0or1, where0isfalseand1istrue.- Returns:
- the new value with the bit changed
- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getLongBit
public static long getLongBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,24L,25L,26L,27L,28L,29L,30L,31L,32L,33L,34L,35L,36L,37L,38L,39L,40L,41L,42L,43L,44L,45L,46L,47L,48L,49L,50L,51L,52L,53L,54L,55L,56L,57L,58L,59L,60L,61L,62L,63L}) int index, long mask) Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyzeindex- the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number0mask- the mask to determine the value of the bit- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getLongBit
public static boolean getLongBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,24L,25L,26L,27L,28L,29L,30L,31L,32L,33L,34L,35L,36L,37L,38L,39L,40L,41L,42L,43L,44L,45L,46L,47L,48L,49L,50L,51L,52L,53L,54L,55L,56L,57L,58L,59L,60L,61L,62L,63L}) int index) Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyzeindex- the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number0- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
getLongBit
Gets the value of the specific bit from the given number- Parameters:
value- the number you want to analyze- Returns:
trueif the bit is1orfalseif the bit is0- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
setLongBit
public static long setLongBit(@NotNull @NotNull Number value, @MagicConstant(intValues={0L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,24L,25L,26L,27L,28L,29L,30L,31L,32L,33L,34L,35L,36L,37L,38L,39L,40L,41L,42L,43L,44L,45L,46L,47L,48L,49L,50L,51L,52L,53L,54L,55L,56L,57L,58L,59L,60L,61L,62L,63L}) int index, boolean status) Method used to change a specific bit from the given number- Parameters:
value- the value you want to manipulateindex- the index of the bit you want to change. It is necessary to clarify that, like arrays, bit indices begin with the number0status- the new value of the specified bit. The new value of the specified bit. Let's remember that a bit is the smallest unit in computing and can only have 2 values,0or1, where0isfalseand1istrue.- Returns:
- the new value with the bit changed
- Throws:
IndexOutOfBoundsException- error when the index is larger or smaller than the size allowed by the data type
-
toBinaryString
@NotNull public static @NotNull String toBinaryString(@NotNull @NotNull Number number, boolean separator) Converts a binary number to a bit-text representation- Parameters:
number- the number to convertseparator- every 4 bits add a separator to better visualize the numbers- Returns:
- binary string representation
- Throws:
IllegalArgumentException- error ifnumberisnullor is a decimal numeric type
-
toBinaryString
Converts a binary number to a bit-text representation- Parameters:
number- the number to convert- Returns:
- binary string representation
- See Also:
-
hasFlag
public static boolean hasFlag(int content, int flag) Identifies if a flag is already within the specified value- Parameters:
content- value where you want to search for the flagflag- the flag you want to search for- Returns:
trueif the flag is set orfalseotherwise
-
asFlags
converts an array of flags to a single value- Parameters:
flags- all elements to convert- Returns:
- result of conversion to all flags
-