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 voidinjectField(String fieldName, @NotNull Object object, Object newValue) Tries to inject a value into the field of an object via reflection.static voidrequireGreaterZero(Number number) Checks whether a number is greater than 0.static voidrequireGreaterZero(Number number, String message) Checks whether a number is greater than 0.static voidrequireNonNegative(Number number) Checks whether a number is smaller than zero.static voidrequireNonNegative(Number number, String message) Checks whether a number is smaller than zero.static voidrequirePercentage(double percentage) Checks whether a parameter is a percentage value.static voidrequirePercentage(double percentage, String message) Checks whether a parameter is a percentage value.static StringtimeFormat(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- ifnumberis 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- ifnumberis NOT >0
-
requireNonNegative
Checks whether a number is smaller than zero.- Parameters:
number- the value to check- Throws:
IllegalArgumentException- ifnumberis <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- ifnumberis <0
-
requirePercentage
public static void requirePercentage(double percentage) Checks whether a parameter is a percentage value.- Parameters:
percentage- the value to check- Throws:
IllegalArgumentException- ifpercentageis 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- ifpercentageis 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.
-