Class ArrayUtils
- Since:
- 1.42
- Version:
- 1.2
- Author:
- matt
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]arrayWithLength(T[] array, int count, Class<T> itemClass, org.springframework.beans.factory.ObjectFactory<? extends T> factory) Adjust an array to a specific length, filling in any new elements with newly objects.static String[]filterByEnabledDisabled(String[] list, String[] enabled, String[] disabled) Filter a set of strings based on enabled/disabled patterns.static booleanisOnlyNull(Object[] array) Test if an array has only null elements or is itself null or empty.
-
Method Details
-
arrayWithLength
public static <T> T[] arrayWithLength(T[] array, int count, Class<T> itemClass, org.springframework.beans.factory.ObjectFactory<? extends T> factory) Adjust an array to a specific length, filling in any new elements with newly objects.This method can shorten or lengthen an array of objects. After adjusting the array length, any null element in the array will be initialized to an object returned from
factory, or iffactoryis not provided a new instance ofitemClassviaClass.newInstance(). TheObjectFactory.getObject()method (or class constructor if nofactoryprovided) will be called for each null array index.Note that if a size adjustment is made, a new array instance is returned from this method, with elements copied from
arraywhere appropriate. If no size adjustment is necessary, thenarrayis returned directly.- Type Parameters:
T- the array item type- Parameters:
array- the source array, or nullcount- the desired length of the array; if less than zero will be treated as zeroitemClass- the class of array itemsfactory- a factory to create new array items, or null to createitemClassinstances directly- Returns:
- a copy of
arraywith the adjusted length, orarrayif no adjustment was necessary
-
filterByEnabledDisabled
Filter a set of strings based on enabled/disabled patterns.The
enabledpatterns are applied first, followed bydisabled. Both arguments are optional. The patterns are treated in a case-insensitive manner, usingMatcher.find()to find partial matches.- Parameters:
list- the list to filterenabled- an optional list of regular expressions to limit the result todisabled- an optional list of regular expressions to exclude from the results- Returns:
- the filtered list of protocols
- Since:
- 1.1
-
isOnlyNull
Test if an array has only null elements or is itself null or empty.This method will perform a linear search for the first non-null element.
- Parameters:
array- the array to test- Returns:
- true if
arrayis null, empty, or has only null elements - Since:
- 1.2
-