Class Utils

java.lang.Object
org.alfresco.solr.utils.Utils

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

    • Utils

      public Utils()
  • Method Details

    • notNullOrEmpty

      public static <T> Collection<T> notNullOrEmpty(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> List<T> notNullOrEmpty(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 Integer toIntOrNull(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(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(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(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(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 Double doubleOrNull(String value)