Class Utils

java.lang.Object
valorless.valorlessutils.utils.Utils

public class Utils extends Object
Utility class consisting of various functions.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Utility class for converting between Boolean and Integer values.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Boolean
    Chance(double percent)
    Determines if an event occurs based on a given percentage chance.
    static <T extends Comparable<T>>
    T
    Clamp(T value, T min, T max)
    Clamps a value between a minimum and maximum value.
    static double
    Clamp01(double value)
    Clamps a double value between 0 and 1.
    static float
    Clamp01(float value)
    Clamps a float value between 0 and 1.
    static long
    Clamp01(long value)
    Clamps a long value between 0 and 1.
    static Integer
    Clamps an Integer value between 0 and 1.
    static boolean
    Checks if a given string is null or empty, considering various conditions including whitespace and length.
    static double
    Percent(double current, double max)
    Calculates the percentage of a given value relative to a maximum value.
    static float
    Percent(float current, float max)
    Calculates the percentage of a given float value relative to a maximum float value.
    static double
    RandomRange(double min, double max)
    Generates a random double within the specified range (inclusive).
    static int
    RandomRange(int min, int max)
    Generates a random integer within the specified range (inclusive).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • IsStringNullOrEmpty

      public static boolean IsStringNullOrEmpty(String string)
      Checks if a given string is null or empty, considering various conditions including whitespace and length.
      Parameters:
      string - The input string to be checked.
      Returns:
      true if the string is null or empty, false otherwise.
    • Percent

      public static double Percent(double current, double max)
      Calculates the percentage of a given value relative to a maximum value.
      Parameters:
      current - The current value.
      max - The maximum value.
      Returns:
      The percentage value.
    • Percent

      public static float Percent(float current, float max)
      Calculates the percentage of a given float value relative to a maximum float value.
      Parameters:
      current - The current float value.
      max - The maximum float value.
      Returns:
      The percentage value.
    • Chance

      public static Boolean Chance(double percent)
      Determines if an event occurs based on a given percentage chance.
      Parameters:
      percent - The percentage chance of the event occurring.
      Returns:
      true if the event occurs, false otherwise. The decision is made randomly.
    • RandomRange

      public static int RandomRange(int min, int max)
      Generates a random integer within the specified range (inclusive).
      Parameters:
      min - The minimum value of the range.
      max - The maximum value of the range.
      Returns:
      A randomly generated integer within the specified range.
      Throws:
      IllegalArgumentException - if min > max
    • RandomRange

      public static double RandomRange(double min, double max)
      Generates a random double within the specified range (inclusive).
      Parameters:
      min - The minimum value of the range.
      max - The maximum value of the range.
      Returns:
      A randomly generated double within the specified range.
    • Clamp

      public static <T extends Comparable<T>> T Clamp(T value, T min, T max)
      Clamps a value between a minimum and maximum value.
      Type Parameters:
      T - The type of the value (must implement Comparable).
      Parameters:
      value - The value to clamp.
      min - The minimum allowed value.
      max - The maximum allowed value.
      Returns:
      The clamped value between min and max.
    • Clamp01

      public static Integer Clamp01(Integer value)
      Clamps an Integer value between 0 and 1.
      Parameters:
      value - The Integer value to clamp.
      Returns:
      The clamped Integer value between 0 and 1.
    • Clamp01

      public static long Clamp01(long value)
      Clamps a long value between 0 and 1.
      Parameters:
      value - The long value to clamp.
      Returns:
      The clamped long value between 0 and 1.
    • Clamp01

      public static double Clamp01(double value)
      Clamps a double value between 0 and 1.
      Parameters:
      value - The double value to clamp.
      Returns:
      The clamped double value between 0 and 1.
    • Clamp01

      public static float Clamp01(float value)
      Clamps a float value between 0 and 1.
      Parameters:
      value - The float value to clamp.
      Returns:
      The clamped float value between 0 and 1.