Package org.alfresco.solr.utils
Class Utils
java.lang.Object
org.alfresco.solr.utils.Utils
SearchServices Booch utilities.
- Author:
- Andrea Gazzarini
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DoubledoubleOrNull(String value) static booleanisNotNullAndNotEmpty(String value) Returns true if the input string is not null and it is not empty.static booleanisNullOrEmpty(String value) Returns true if the input string is null or is empty.static <T> Collection<T>notNullOrEmpty(Collection<T> values) Returns the same input collection if that is not null, otherwise a new empty collection.static <T> List<T>notNullOrEmpty(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 voidsilentyClose(Closeable resource) Silently closes the givenCloseableresource without raising any exception.static booleanstartsWithLanguageMarker(String value) Returns true if the first character of the input string is the locale marker character.static IntegertoIntOrNull(String value) Converts the given input in an Integer, otherwise it returns null.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
notNullOrEmpty
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
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
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
Silently closes the givenCloseableresource 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 anIOExceptionthe 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- theCloseableresource we want to silently close.
-
isNullOrEmpty
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
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
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
-