Package ca.team3161.lib.utils
Class Utils
- java.lang.Object
-
- ca.team3161.lib.utils.Utils
-
public class Utils extends java.lang.Object
Pretty printing arrays, rounding doubles, ensuring PWM values fall within the range [-1.0, 1.0], etc.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
between(double a, double val, double b)
static boolean
between(float a, float val, float b)
static boolean
between(int a, int val, int b)
static boolean
between(long a, long val, long b)
static double
normalizePwm(double val)
Normalize a PWM value so it remains in the range [-1.0, 1.0] If a value above 1.0 is given, 1.0 is returned.static float
normalizePwm(float val)
Normalize a PWM value so it remains in the range [-1.0, 1.0] If a value above 1.0 is given, 1.0 is returned.static double
requireNonNegative(double in)
Assert that a double is greater than 0.static float
requireNonNegative(float in)
Assert that a float is greater than 0.static int
requireNonNegative(int in)
Assert that an int is greater than 0.static long
requireNonNegative(long in)
Assert that a long is greater than 0.static void
safeExec(java.lang.String label, java.lang.Runnable runnable)
static <T> java.util.function.Consumer<T>
safeExec(java.lang.String label, java.util.function.Consumer<T> consumer)
static <T> T
safeInit(java.lang.String label, java.util.function.Supplier<T> supplier)
-
-
-
Method Detail
-
normalizePwm
public static double normalizePwm(double val)
Normalize a PWM value so it remains in the range [-1.0, 1.0] If a value above 1.0 is given, 1.0 is returned. If a value below -1.0 is given, -1.0 is returned. For other values, they are simply returned- Parameters:
val
- the value to normalize- Returns:
- the normalized value
-
normalizePwm
public static float normalizePwm(float val)
Normalize a PWM value so it remains in the range [-1.0, 1.0] If a value above 1.0 is given, 1.0 is returned. If a value below -1.0 is given, -1.0 is returned. For other values, they are simply returned- Parameters:
val
- the value to normalize- Returns:
- the normalized value
-
requireNonNegative
public static int requireNonNegative(int in)
Assert that an int is greater than 0.- Parameters:
in
- the argument which must be non-negative- Returns:
- the argument back
- Throws:
java.lang.IllegalArgumentException
- if the argument is less than 0
-
requireNonNegative
public static long requireNonNegative(long in)
Assert that a long is greater than 0.- Parameters:
in
- the argument which must be non-negative- Returns:
- the argument back
- Throws:
java.lang.IllegalArgumentException
- if the argument is less than 0
-
requireNonNegative
public static double requireNonNegative(double in)
Assert that a double is greater than 0.- Parameters:
in
- the argument which must be non-negative- Returns:
- the argument back
- Throws:
java.lang.IllegalArgumentException
- if the argument is less than 0
-
requireNonNegative
public static float requireNonNegative(float in)
Assert that a float is greater than 0.- Parameters:
in
- the argument which must be non-negative- Returns:
- the argument back
- Throws:
java.lang.IllegalArgumentException
- if the argument is less than 0
-
between
public static boolean between(double a, double val, double b)
-
between
public static boolean between(float a, float val, float b)
-
between
public static boolean between(int a, int val, int b)
-
between
public static boolean between(long a, long val, long b)
-
safeInit
public static <T> T safeInit(java.lang.String label, java.util.function.Supplier<T> supplier)
-
safeExec
public static void safeExec(java.lang.String label, java.lang.Runnable runnable)
-
safeExec
public static <T> java.util.function.Consumer<T> safeExec(java.lang.String label, java.util.function.Consumer<T> consumer)
-
-