java.lang.Object
com.github.hypfvieh.util.TypeUtil

public final class TypeUtil extends Object
Class providing a set of methods for converting and/or checking of various data types.
Autor:
hypfvieh
  • Methodendetails

    • strToBool

      @Deprecated(forRemoval=true, since="2022-01-28") public static boolean strToBool(String _str)
      Veraltet, zur Entfernung: Dieses API-Element wird in einer zukünftigen Version entfernt.
      Returns true if string matches certain boolean values.
      Parameter:
      _str - string to validate
      Gibt zurück:
      true if string represents a true (like 'yes','ja',1) value, false otherwise
    • isDouble

      public static boolean isDouble(String _str)
      Checks if the given string is a valid double (including negative values). Separator is based on the used locale.
      Parameter:
      _str - string to check
      Gibt zurück:
      true if valid double, false otherwise
    • isDouble

      public static boolean isDouble(String _str, char _separator)
      Checks if the given string is a valid double (including negative values) using the given separator.
      Parameter:
      _str - string to check
      _separator - separator to use
      Gibt zurück:
      true if valid double, false otherwise
    • isDouble

      public static boolean isDouble(String _str, boolean _allowNegative)
      Checks if the given string is a valid double. The used separator is based on the used system locale
      Parameter:
      _str - string to validate
      _allowNegative - set to true if negative double should be allowed
      Gibt zurück:
      true if given string is double, false otherwise
    • isDouble

      public static boolean isDouble(String _str, char _separator, boolean _allowNegative)
      Checks if the given string is a valid double.
      Parameter:
      _str - string to validate
      _separator - seperator used (e.g. "." (dot) or "," (comma))
      _allowNegative - set to true if negative double should be allowed
      Gibt zurück:
      true if given string is double, false otherwise
    • isInteger

      public static boolean isInteger(String _str)
      Check if string is integer (including negative integers).
      Parameter:
      _str - string to check
      Gibt zurück:
      true if integer (positive or negative), false otherwise
    • isInteger

      public static boolean isInteger(String _str, boolean _allowNegative)
      Check if string is an either positive or negative integer.
      Parameter:
      _str - string to validate
      _allowNegative - negative integer allowed
      Gibt zurück:
      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).
      Parameter:
      _port - 'port' to check
      _allowWellKnown - allow ports below 1024 (aka reserved well known ports)
      Gibt zurück:
      true if int is a valid network port, false otherwise
    • isValidNetworkPort

      public static boolean isValidNetworkPort(String _str, boolean _allowWellKnown)
      Parameter:
      _str - string to check
      _allowWellKnown - allow well known port
      Gibt zurück:
      true if valid port, false otherwise
      Siehe auch:
    • isValidRegex

      public static boolean isValidRegex(String _regExStr)
      Checks if given String is a valid regular expression.
      Parameter:
      _regExStr - regex string to check
      Gibt zurück:
      true if given string is valid regex, false otherwise
    • createRegExPatternIfValid

      public static Pattern createRegExPatternIfValid(String _regExStr)
      Creates a RegEx Pattern object, if given String is a valid regular expression.
      Parameter:
      _regExStr - regex string to check
      Gibt zurück:
      Pattern-Object or null if given String is no valid RegEx
    • createList

      @SafeVarargs public static <T> List<T> createList(T... _entries)
      Creates a list from a varargs parameter array. The generic list is created with the same type as the parameters.
      Typparameter:
      T - list type
      Parameter:
      _entries - list entries
      Gibt zurück:
      list
    • createMap

      @SafeVarargs public static <T> Map<T,T> createMap(T... _args)
      Creates a map from the even-sized parameter array.
      Typparameter:
      T - map type
      Parameter:
      _args - parameter array, any type
      Gibt zurück:
      map of parameter type
    • isAnyNull

      @Deprecated public static boolean isAnyNull(Object... _objects)
      Checks if any of the passed in objects is null.
      Parameter:
      _objects - array of objects, may be null
      Gibt zurück:
      true if null found, false otherwise
    • throwIfAnyNull

      @Deprecated public static void throwIfAnyNull(String _errMsg, Object... _objects)
      Parameter:
      _errMsg - error message
      _objects - objects to check
      Siehe auch:
    • equalsOne

      @Deprecated public static boolean equalsOne(Object _obj, Object... _arrObj)
      Returns true if the specified object equals at least one of the specified other objects.
      Parameter:
      _obj - object
      _arrObj - array of objects to compare to
      Gibt zurück:
      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, IllegalAccessException
      Splits _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.
      Typparameter:
      K - key type
      V - value type
      Parameter:
      _map - map to split
      _nbElements - elements per map
      Gibt zurück:
      List of Maps
      Löst aus:
      IllegalAccessException - on error
      InstantiationException - on error
    • splitList

      public static <T> List<List<T>> splitList(List<T> _list, int _elements)
      Split a List into equal parts. Last list could be shorter than _elements.
      Typparameter:
      T - type
      Parameter:
      _list - list to split
      _elements - elements per list
      Gibt zurück:
      list of lists
    • splitListToSubLists

      public static <T> List<List<T>> splitListToSubLists(List<T> _list, int _listCount)
      Splits a given list to _listCount subLists. Last list maybe shorter or longer than all previous list (depending on _list size).
      Parameter:
      _list - list to split
      _listCount - sublists to create
      Gibt zurück:
      List of Lists, null if _list was null, empty list if _list was empty
    • createProperties

      public static Properties createProperties(String... _keysAndVals)
      Factory method for Properties from an even-sized String array.
      Parameter:
      _keysAndVals - String array of keys and values, may be null or even-numbered String array
      Gibt zurück:
      new Properties object
    • defaultIfNotInteger

      public static int defaultIfNotInteger(String _possibleInt, int _default)
      Returns integer converted from string or default if string could not be converted to int.
      Parameter:
      _possibleInt - string to convert
      _default - default to use if string cannot be converted
      Gibt zurück:
      int
    • defaultIfNull

      public static <T> T defaultIfNull(T _val, T _default)
      Returns the default if value is null or value if value is not null.
      Typparameter:
      T - type to check/return
      Parameter:
      _val - value to check for null
      _default - default to use when value is null
      Gibt zurück:
      value or default
      Seit:
      1.2.1 - 2022-05-19
    • indexOfByteArray

      public static int indexOfByteArray(byte[] _heyStackArray, byte[] _needleArray)
      Retrieves the position of a byte array in another byte array.
      Parameter:
      _heyStackArray - array to search
      _needleArray - array to find
      Gibt zurück:
      position of found array or -1 if not found
      Seit:
      1.2.1 - 2024-03-21