Package cambio.simulator.misc
Class Util
java.lang.Object
cambio.simulator.misc.Util
Class that holds static utility methods.
Currently contains only utility methods to check values.
- Author:
- Lion Wagner
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Field[]
getAllFields
(Class<?> clazz) Gets the declared fields of this class and all of its Superclasses.static void
injectField
(String fieldName, @NotNull Object object, Object newValue) Tries to inject a value into the field of an object via reflection.static void
requireGreaterZero
(Number number) Checks whether a number is greater than 0.static void
requireGreaterZero
(Number number, String message) Checks whether a number is greater than 0.static void
requireNonNegative
(Number number) Checks whether a number is smaller than zero.static void
requireNonNegative
(Number number, String message) Checks whether a number is smaller than zero.static void
requirePercentage
(double percentage) Checks whether a parameter is a percentage value.static void
requirePercentage
(double percentage, String message) Checks whether a parameter is a percentage value.static String
timeFormat
(long nanosecs) Formats a nanosecond time into a fixed time span format.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
requireGreaterZero
Checks whether a number is greater than 0.- Parameters:
number
- the value to check- Throws:
IllegalArgumentException
- ifnumber
is NOT >0
-
requireGreaterZero
Checks whether a number is greater than 0.- Parameters:
number
- the value to checkmessage
- The message that should be thrown if the number is not in the correct value range- Throws:
IllegalArgumentException
- ifnumber
is NOT >0
-
requireNonNegative
Checks whether a number is smaller than zero.- Parameters:
number
- the value to check- Throws:
IllegalArgumentException
- ifnumber
is <0
-
requireNonNegative
Checks whether a number is smaller than zero.- Parameters:
number
- the value to checkmessage
- The message that should be thrown if the number is not in the correct value range- Throws:
IllegalArgumentException
- ifnumber
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
- ifpercentage
is not in [0,1]
-
requirePercentage
Checks whether a parameter is a percentage value.- Parameters:
percentage
- the value to checkmessage
- The message that should be thrown if the percentage is not in the correct value range- Throws:
IllegalArgumentException
- ifpercentage
is not in [0,1]
-
timeFormat
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
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 fieldobject
- object that should be modifiednewValue
- value that should be injected
-
getAllFields
Gets the declared fields of this class and all of its Superclasses.
-