Class Utils


  • public abstract class Utils
    extends java.lang.Object
    SearchServices Booch utilities.
    Author:
    Andrea Gazzarini
    • Constructor Summary

      Constructors 
      Constructor Description
      Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Double doubleOrNull​(java.lang.String value)  
      static boolean isNotNullAndNotEmpty​(java.lang.String value)
      Returns true if the input string is not null and it is not empty.
      static boolean isNullOrEmpty​(java.lang.String value)
      Returns true if the input string is null or is empty.
      static <T> java.util.Collection<T> notNullOrEmpty​(java.util.Collection<T> values)
      Returns the same input collection if that is not null, otherwise a new empty collection.
      static <T> java.util.List<T> notNullOrEmpty​(java.util.List<T> values)
      Returns the same input list if that is not null, otherwise a new empty list.
      static <T> T[] notNullOrEmpty​(T[] values)
      Makes sure we are not dealing with a null array.
      static void silentyClose​(java.io.Closeable resource)
      Silently closes the given Closeable resource without raising any exception.
      static boolean startsWithLanguageMarker​(java.lang.String value)
      Returns true if the first character of the input string is the locale marker character.
      static java.lang.Integer toIntOrNull​(java.lang.String value)
      Converts the given input in an Integer, otherwise it returns null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • notNullOrEmpty

        public static <T> java.util.Collection<T> notNullOrEmpty​(java.util.Collection<T> values)
        Returns the same input collection if that is not null, otherwise a new empty collection. Provides a safe way for iterating over a returned collection (which could be null).
        Type Parameters:
        T - the collection type.
        Parameters:
        values - the collection.
        Returns:
        the same input collection if that is not null, otherwise a new empty collection.
      • notNullOrEmpty

        public static <T> java.util.List<T> notNullOrEmpty​(java.util.List<T> values)
        Returns the same input list if that is not null, otherwise a new empty list. Provides a safe way for iterating over a returned list (which could be null).
        Type Parameters:
        T - the list elements type.
        Parameters:
        values - the input list.
        Returns:
        the same input list if that is not null, otherwise a new empty list.
      • notNullOrEmpty

        public static <T> T[] notNullOrEmpty​(T[] values)
        Makes sure we are not dealing with a null array.
        Type Parameters:
        T - the array type.
        Parameters:
        values - the input array.
        Returns:
        the input array if it is not null, an empty array otherwise.
      • toIntOrNull

        public static java.lang.Integer toIntOrNull​(java.lang.String value)
        Converts the given input in an Integer, otherwise it returns null.
        Parameters:
        value - the numeric string.
        Returns:
        the corresponding Integer or null in case the input is NaN.
      • silentyClose

        public static void silentyClose​(java.io.Closeable resource)
        Silently closes the given Closeable resource without raising any exception. This utility method is specifically useful when we have to close a resource in a lamba statement: since the close() method could throw an IOException the compiler requires an enclosing try / catch block which makes the code less readable.

        try { if (resource != null) resource.close } catch (IOException exception) { ... }


        In these contexts a call to this method reduces the amount of code needed:

        silentlyClose(resource);

        Parameters:
        resource - the Closeable resource we want to silently close.
      • isNullOrEmpty

        public static boolean isNullOrEmpty​(java.lang.String value)
        Returns true if the input string is null or is empty. Note whitespaces are not considered, so if a string contains only whitespaces, it is considered empty.
        Parameters:
        value - the input string.
        Returns:
        true if the input string is null or is empty.
      • isNotNullAndNotEmpty

        public static boolean isNotNullAndNotEmpty​(java.lang.String value)
        Returns true if the input string is not null and it is not empty. Note whitespaces are not considered, so if a string contains only whitespaces, it is considered empty.
        Parameters:
        value - the input string.
        Returns:
        true if the input string is not null and it is not empty.
      • startsWithLanguageMarker

        public static boolean startsWithLanguageMarker​(java.lang.String value)
        Returns true if the first character of the input string is the locale marker character.
        Parameters:
        value - the input string.
        Returns:
        true true if the first character of the input string is the locale marker character.
      • doubleOrNull

        public static java.lang.Double doubleOrNull​(java.lang.String value)