Package io.hekate.core.internal.util
Class Utils
- java.lang.Object
-
- io.hekate.core.internal.util.Utils
-
public final class Utils extends Object
Common utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAGIC_BYTES
Magic bytes that should be appended to the first packet of a network connection.static String
NL
Shortcut forSystem.lineSeparator()
.static Charset
UTF_8
Charset
for UTF-8.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
byteSizeFormat(long bytes)
static String
camelCase(CharSequence str)
static boolean
isPowerOfTwo(int n)
Returnstrue
if the specified value is a power of two.static int
mod(int hash, int size)
static String
nullOrTrim(String str)
static String
nullOrTrim(String str, String defaultVal)
static <T> List<T>
nullSafeImmutableCopy(List<T> source)
Returns an immutable copy of the specified list by filtering out allnull
elements.static String
numberFormat(String pattern, Number number)
static <T> String
toString(Collection<T> collection, Function<? super T,String> mapper)
Converts the specified collection to a comma-separated string by applying the specified mapper to each element and wrapping the resulting string with{...}
.
-
-
-
Field Detail
-
NL
public static final String NL
Shortcut forSystem.lineSeparator()
.
-
MAGIC_BYTES
public static final int MAGIC_BYTES
Magic bytes that should be appended to the first packet of a network connection.- See Also:
- Constant Field Values
-
-
Method Detail
-
byteSizeFormat
public static String byteSizeFormat(long bytes)
-
mod
public static int mod(int hash, int size)
-
isPowerOfTwo
public static boolean isPowerOfTwo(int n)
Returnstrue
if the specified value is a power of two.- Parameters:
n
- Number to check.- Returns:
true
if the specified value is a power of two.
-
toString
public static <T> String toString(Collection<T> collection, Function<? super T,String> mapper)
Converts the specified collection to a comma-separated string by applying the specified mapper to each element and wrapping the resulting string with{...}
.- Type Parameters:
T
- Collection type.- Parameters:
collection
- Collection.mapper
- Element mapper.- Returns:
- String that has the following format:
{element1, element2, ..., elementN}
-
nullOrTrim
public static String nullOrTrim(String str)
Returnsnull
if the specified string isnull
or is an empty string aftertrimming
; returns atrimmed
string otherwise.- Parameters:
str
- String.- Returns:
null
ortrimmed
string.
-
nullOrTrim
public static String nullOrTrim(String str, String defaultVal)
ReturnsdefaultVal
if the specified string isnull
or is an empty string aftertrimming
; returns atrimmed
string otherwise.- Parameters:
str
- String.defaultVal
- Default value.- Returns:
null
ortrimmed
string.
-
camelCase
public static String camelCase(CharSequence str)
-
nullSafeImmutableCopy
public static <T> List<T> nullSafeImmutableCopy(List<T> source)
Returns an immutable copy of the specified list by filtering out allnull
elements.- Type Parameters:
T
- Element type.- Parameters:
source
- Source list, can benull
(in such case an empty list will be returned by this method).- Returns:
- Immutable copy of the specified list.
-
-