Package ushiosan.jvm

Class UNumber

java.lang.Object
ushiosan.jvm.UNumber

public final class UNumber extends Object
  • Method Details

    • isDecimal

      public static boolean isDecimal(@NotNull @NotNull Number number)
      Determine if a decimal number contains decimals after the floating point.
      Parameters:
      number - the number to evaluate
      Returns:
      true if the number contains decimals or false otherwise
    • parse

      @NotNull public static @NotNull Optional<Number> parse(@NotNull @NotNull CharSequence content)
      Returns a new Number initialized to the value represented by the specified String.
      Parameters:
      content - the string to be parsed
      Returns:
      the Number value represented by the string argument or Optional.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 instance
      start - the start of the range (inclusive)
      end - the end of the range (no inclusive)
      size - total elements in array
      inclusive - if true the end of the range is included within the allowed values false if 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 instance
      start - the start of the range (inclusive)
      end - the end of the range (no inclusive)
      size - total elements in array
      inclusive - if true the end of the range is included within the allowed values false if 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:
      1 if the bit is true or 0 if it is false
    • 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 analyze
      index - the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      mask - the mask to determine the value of the bit
      Returns:
      true if the bit is 1 or false if the bit is 0
      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 analyze
      index - the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      Returns:
      true if the bit is 1 or false if the bit is 0
      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)
      Gets the value of the specific bit from the given number
      Parameters:
      value - the number you want to analyze
      Returns:
      true if the bit is 1 or false if the bit is 0
      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 manipulate
      index - the index of the bit you want to change. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      status - 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, 0 or 1, where 0 is false and 1 is true.
      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 analyze
      index - the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      mask - the mask to determine the value of the bit
      Returns:
      true if the bit is 1 or false if the bit is 0
      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 analyze
      index - the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      Returns:
      true if the bit is 1 or false if the bit is 0
      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)
      Gets the value of the specific bit from the given number
      Parameters:
      value - the number you want to analyze
      Returns:
      true if the bit is 1 or false if the bit is 0
      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 manipulate
      index - the index of the bit you want to change. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      status - 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, 0 or 1, where 0 is false and 1 is true.
      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 analyze
      index - the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      mask - the mask to determine the value of the bit
      Returns:
      true if the bit is 1 or false if the bit is 0
      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 analyze
      index - the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      Returns:
      true if the bit is 1 or false if the bit is 0
      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)
      Gets the value of the specific bit from the given number
      Parameters:
      value - the number you want to analyze
      Returns:
      true if the bit is 1 or false if the bit is 0
      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 manipulate
      index - the index of the bit you want to change. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      status - 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, 0 or 1, where 0 is false and 1 is true.
      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 analyze
      index - the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      mask - the mask to determine the value of the bit
      Returns:
      true if the bit is 1 or false if the bit is 0
      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 analyze
      index - the index of the bit to obtain. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      Returns:
      true if the bit is 1 or false if the bit is 0
      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)
      Gets the value of the specific bit from the given number
      Parameters:
      value - the number you want to analyze
      Returns:
      true if the bit is 1 or false if the bit is 0
      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 manipulate
      index - the index of the bit you want to change. It is necessary to clarify that, like arrays, bit indices begin with the number 0
      status - 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, 0 or 1, where 0 is false and 1 is true.
      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 convert
      separator - every 4 bits add a separator to better visualize the numbers
      Returns:
      binary string representation
      Throws:
      IllegalArgumentException - error if number is null or is a decimal numeric type
    • toBinaryString

      @NotNull public static @NotNull String toBinaryString(@NotNull @NotNull Number number)
      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 flag
      flag - the flag you want to search for
      Returns:
      true if the flag is set or false otherwise
    • asFlags

      public static int asFlags(int @NotNull ... flags)
      converts an array of flags to a single value
      Parameters:
      flags - all elements to convert
      Returns:
      result of conversion to all flags