Class Util

java.lang.Object
cambio.simulator.misc.Util

public final class Util extends Object
Class that holds static utility methods.

Currently contains only utility methods to check values.

Author:
Lion Wagner
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • requireGreaterZero

      public static void requireGreaterZero(Number number)
      Checks whether a number is greater than 0.
      Parameters:
      number - the value to check
      Throws:
      IllegalArgumentException - if number is NOT >0
    • requireGreaterZero

      public static void requireGreaterZero(Number number, String message)
      Checks whether a number is greater than 0.
      Parameters:
      number - the value to check
      message - The message that should be thrown if the number is not in the correct value range
      Throws:
      IllegalArgumentException - if number is NOT >0
    • requireNonNegative

      public static void requireNonNegative(Number number)
      Checks whether a number is smaller than zero.
      Parameters:
      number - the value to check
      Throws:
      IllegalArgumentException - if number is <0
    • requireNonNegative

      public static void requireNonNegative(Number number, String message)
      Checks whether a number is smaller than zero.
      Parameters:
      number - the value to check
      message - The message that should be thrown if the number is not in the correct value range
      Throws:
      IllegalArgumentException - if number is <0
    • requirePercentage

      public static void requirePercentage(double percentage)
      Checks whether a parameter is a percentage value.
      Parameters:
      percentage - the value to check
      Throws:
      IllegalArgumentException - if percentage is not in [0,1]
    • requirePercentage

      public static void requirePercentage(double percentage, String message)
      Checks whether a parameter is a percentage value.
      Parameters:
      percentage - the value to check
      message - The message that should be thrown if the percentage is not in the correct value range
      Throws:
      IllegalArgumentException - if percentage is not in [0,1]
    • timeFormat

      public static String timeFormat(long nanosecs)
      Formats a nanosecond time into a fixed time span format.
      Parameters:
      nanosecs - The amount of nanoseconds that should be parsed
      Returns:
      A String that contains nanosecs value formated to days, hours, min, sec and ms
    • injectField

      public static void injectField(String fieldName, @NotNull @NotNull Object object, Object newValue)
      Tries to inject a value into the field of an object via reflection. Checks declared fields of the objects class and all its superclasses.
      Parameters:
      fieldName - name of the field
      object - object that should be modified
      newValue - value that should be injected
    • getAllFields

      public static Field[] getAllFields(Class<?> clazz)
      Gets the declared fields of this class and all of its Superclasses.
      Parameters:
      clazz - Class which fields should be
      Returns:
      all Fields that are contained within the given Class and its superclasses.