Class Util
java.lang.Object
br.net.dd.netherwingcore.common.utilities.Util
Utility class providing various helper methods for commonly used operations.
This class includes methods for string manipulation, byte conversion, time formatting,
and several other utility functions relevant to most Java applications.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbeep()Produces a system beep sound.static StringbyteArrayToHexStr(byte[] bytes, boolean reverse) Converts a byte array to a hexadecimal string with optional reversal of the byte order.static StringbytesToHex(byte[] bytes) Converts a byte array to a hexadecimal string.static floatdegToRad(float degrees) Converts an angle from degrees to radians.static StringRetrieves the location of the JAR file of the current application.static longgetPID()Retrieves the current process ID (PID) of the running application.static byte[]hexStrToByteArray(String str, boolean reverse) Converts a hexadecimal string to a byte array with optional reversal of the byte order.static booleanisIPAddress(String ipAddress) Checks if a given string is a valid IP address.static introundingFloatValue(float val) Rounds a float value based on a threshold of 0.44444445.static StringsecsToTimeString(long timeInSecs, boolean shortText, boolean hoursOnly) Converts seconds into a human-readable time string.static booleanstringEqualI(String a, String b) Compares two strings for equality, ignoring case considerations.static booleanstringToBool(String str) Converts a string to a boolean value, interpreting common representations of "true".static voidRemoves invisible characters (e.g., spaces, tabs, etc.) from a StringBuilder, leaving one space as a separator.static StringtimeToTimestampStr(long t) Converts a UNIX timestamp to a formatted timestamp string.Tokenizes a string based on a given separator and keeps empty tokens if specified.static intutf8Length(String utf8str) Calculates the number of UTF-8 code points in a given string.static voidutf8Truncate(StringBuilder str, int len) Truncates a StringBuilder to a specified number of UTF-8 code points.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
getJarLocation
Retrieves the location of the JAR file of the current application.- Returns:
- The directory where the JAR file resides.
- Throws:
RuntimeException- If the URI syntax is invalid.
-
beep
public static void beep()Produces a system beep sound. -
bytesToHex
Converts a byte array to a hexadecimal string.- Parameters:
bytes- The byte array to convert.- Returns:
- The hexadecimal representation of the byte array.
-
tokenize
Tokenizes a string based on a given separator and keeps empty tokens if specified.- Parameters:
str- The string to tokenize.sep- The separator character.keepEmpty- Whether to include empty tokens in the result.- Returns:
- A list of tokens extracted from the input string.
-
stringEqualI
-
stripLineInvisibleChars
Removes invisible characters (e.g., spaces, tabs, etc.) from a StringBuilder, leaving one space as a separator.- Parameters:
str- The StringBuilder to process.
-
roundingFloatValue
public static int roundingFloatValue(float val) Rounds a float value based on a threshold of 0.44444445.- Parameters:
val- The float value to round.- Returns:
- The rounded integer value.
-
secsToTimeString
Converts seconds into a human-readable time string.- Parameters:
timeInSecs- The time in seconds.shortText- Whether to use short text format (e.g., "d", "h").hoursOnly- Whether to display hours only.- Returns:
- A formatted time string.
-
timeToTimestampStr
Converts a UNIX timestamp to a formatted timestamp string.- Parameters:
t- The UNIX timestamp (in seconds).- Returns:
- The formatted timestamp string.
-
isIPAddress
Checks if a given string is a valid IP address.- Parameters:
ipAddress- The string to validate.- Returns:
trueif the string is a valid IP address,falseotherwise.
-
getPID
public static long getPID()Retrieves the current process ID (PID) of the running application.- Returns:
- The process ID.
-
utf8Length
Calculates the number of UTF-8 code points in a given string.- Parameters:
utf8str- The input string.- Returns:
- The number of code points in the string.
-
utf8Truncate
Truncates a StringBuilder to a specified number of UTF-8 code points.- Parameters:
str- The StringBuilder to truncate.len- The maximum number of UTF-8 code points to retain.
-
degToRad
public static float degToRad(float degrees) Converts an angle from degrees to radians.- Parameters:
degrees- The angle in degrees.- Returns:
- The angle in radians.
-
byteArrayToHexStr
Converts a byte array to a hexadecimal string with optional reversal of the byte order.- Parameters:
bytes- The byte array to convert.reverse- Whether to reverse the byte order.- Returns:
- The hexadecimal string.
-
hexStrToByteArray
Converts a hexadecimal string to a byte array with optional reversal of the byte order.- Parameters:
str- The hexadecimal string to convert.reverse- Whether to reverse the byte order.- Returns:
- The resulting byte array.
- Throws:
IllegalArgumentException- If the string has an odd number of characters.
-
stringToBool
Converts a string to a boolean value, interpreting common representations of "true".- Parameters:
str- The string to convert (e.g., "1", "true", "yes").- Returns:
trueif the string represents a true value,falseotherwise.
-