java.lang.Object
com.github.hypfvieh.util.TypeUtil
Class providing a set of methods for converting and/or checking of various data types.
- Author:
- hypfvieh
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>createList(T... _entries) Creates a list from a varargs parameter array.static <T> Map<T,T> createMap(T... _args) Creates a map from the even-sized parameter array.static PropertiescreateProperties(String... _keysAndVals) Factory method forPropertiesfrom an even-sized String array.static PatterncreateRegExPatternIfValid(String _regExStr) Creates a RegEx Pattern object, if given String is a valid regular expression.static intdefaultIfNotInteger(String _possibleInt, int _default) Returns integer converted from string or default if string could not be converted to int.static booleanDeprecated.static booleanDeprecated.static booleanChecks if the given string is a valid double (including negative values).static booleanChecks if the given string is a valid double.static booleanChecks if the given string is a valid double (including negative values) using the given separator.static booleanChecks if the given string is a valid double.static booleanCheck if string is integer (including negative integers).static booleanCheck if string is an either positive or negative integer.static booleanisValidNetworkPort(int _port, boolean _allowWellKnown) Check if the given value is a valid network port (1 - 65535).static booleanisValidNetworkPort(String _str, boolean _allowWellKnown) static booleanisValidRegex(String _regExStr) Checks if given String is a valid regular expression.Split a List into equal parts.splitListToSubLists(List<T> _list, int _listCount) Splits a given list to _listCount subLists.Splits _map to a list of maps where each map has _nbElements.static booleanDeprecated, for removal: This API element is subject to removal in a future version.static voidthrowIfAnyNull(String _errMsg, Object... _objects) Deprecated.
-
Method Details
-
strToBool
Deprecated, for removal: This API element is subject to removal in a future version.Returns true if string matches certain boolean values.- Parameters:
_str- string to validate- Returns:
- true if string represents a true (like 'yes','ja',1) value, false otherwise
-
isDouble
Checks if the given string is a valid double (including negative values). Separator is based on the used locale.- Parameters:
_str- string to check- Returns:
- true if valid double, false otherwise
-
isDouble
Checks if the given string is a valid double (including negative values) using the given separator.- Parameters:
_str- string to check_separator- separator to use- Returns:
- true if valid double, false otherwise
-
isDouble
Checks if the given string is a valid double. The used separator is based on the used system locale- Parameters:
_str- string to validate_allowNegative- set to true if negative double should be allowed- Returns:
- true if given string is double, false otherwise
-
isDouble
Checks if the given string is a valid double.- Parameters:
_str- string to validate_separator- seperator used (e.g. "." (dot) or "," (comma))_allowNegative- set to true if negative double should be allowed- Returns:
- true if given string is double, false otherwise
-
isInteger
Check if string is integer (including negative integers).- Parameters:
_str- string to check- Returns:
- true if integer (positive or negative), false otherwise
-
isInteger
Check if string is an either positive or negative integer.- Parameters:
_str- string to validate_allowNegative- negative integer allowed- Returns:
- true if integer, false otherwise
-
isValidNetworkPort
public static boolean isValidNetworkPort(int _port, boolean _allowWellKnown) Check if the given value is a valid network port (1 - 65535).- Parameters:
_port- 'port' to check_allowWellKnown- allow ports below 1024 (aka reserved well known ports)- Returns:
- true if int is a valid network port, false otherwise
-
isValidNetworkPort
- Parameters:
_str- string to check_allowWellKnown- allow well known port- Returns:
- true if valid port, false otherwise
- See Also:
-
isValidRegex
Checks if given String is a valid regular expression.- Parameters:
_regExStr- regex string to check- Returns:
- true if given string is valid regex, false otherwise
-
createRegExPatternIfValid
Creates a RegEx Pattern object, if given String is a valid regular expression.- Parameters:
_regExStr- regex string to check- Returns:
- Pattern-Object or null if given String is no valid RegEx
-
createList
Creates a list from a varargs parameter array. The generic list is created with the same type as the parameters.- Type Parameters:
T- list type- Parameters:
_entries- list entries- Returns:
- list
-
createMap
Creates a map from the even-sized parameter array.- Type Parameters:
T- map type- Parameters:
_args- parameter array, any type- Returns:
- map of parameter type
-
isAnyNull
Deprecated.Checks if any of the passed in objects is null.- Parameters:
_objects- array of objects, may be null- Returns:
- true if null found, false otherwise
-
throwIfAnyNull
Deprecated.- Parameters:
_errMsg- error message_objects- objects to check- See Also:
-
equalsOne
Deprecated.Returns true if the specified object equals at least one of the specified other objects.- Parameters:
_obj- object_arrObj- array of objects to compare to- Returns:
- true if equal, false otherwise or if either parameter is null
-
splitMap
public static <K,V> List<Map<K,V>> splitMap(Map<K, V> _map, int _nbElements) throws InstantiationException, IllegalAccessExceptionSplits _map to a list of maps where each map has _nbElements. Last map in list maybe shorter if _map.size() is not divideable by _nElements.- Type Parameters:
K- key typeV- value type- Parameters:
_map- map to split_nbElements- elements per map- Returns:
- List of Maps
- Throws:
IllegalAccessException- on errorInstantiationException- on error
-
splitList
Split a List into equal parts. Last list could be shorter than _elements.- Type Parameters:
T- type- Parameters:
_list- list to split_elements- elements per list- Returns:
- list of lists
-
splitListToSubLists
Splits a given list to _listCount subLists. Last list maybe shorter or longer than all previous list (depending on _list size).- Parameters:
_list- list to split_listCount- sublists to create- Returns:
- List of Lists, null if _list was null, empty list if _list was empty
-
createProperties
Factory method forPropertiesfrom an even-sized String array.- Parameters:
_keysAndVals- String array of keys and values, may be null or even-numbered String array- Returns:
- new Properties object
-
defaultIfNotInteger
Returns integer converted from string or default if string could not be converted to int.- Parameters:
_possibleInt- string to convert_default- default to use if string cannot be converted- Returns:
- int
-
CompareUtil.equalsOne(Object, Object...)