Class SpringUtils
java.lang.Object
org.springframework.data.gemfire.util.SpringUtils
- Direct Known Subclasses:
DistributedSystemUtils
Abstract utility class encapsulating functionality common to
Objects
, Class types
and Spring beans.- Since:
- 1.8.0
- Author:
- John Blum
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic BeanDefinition
addDependsOn
(BeanDefinition beanDefinition, String... beanNames) Adds an array of bean dependencies (by name) to the givenBeanDefinition
.static boolean
areNotNull
(Object... values) Determines whether all theObject
values in the array are non-nullstatic String
defaultIfEmpty
(String value, String defaultValue) static String
defaultIfEmpty
(String value, Supplier<String> supplier) static <T> T
defaultIfNull
(T value, Supplier<T> supplier) static <T> T
defaultIfNull
(T value, T defaultValue) static String
dereferenceBean
(String beanName) static boolean
equalsIgnoreNull
(Object obj1, Object obj2) static <T> List<T>
getBeansOfTypeOrdered
(ConfigurableListableBeanFactory beanFactory, Class<T> beanType) static <T> List<T>
getBeansOfTypeOrdered
(ConfigurableListableBeanFactory beanFactory, Class<T> beanType, boolean includeNonSingletons, boolean allowEagerInit) static Integer
static <T> Stream<T>
getOrderedStreamOfBeansByType
(BeanFactory beanFactory, Class<T> beanType) getPropertyValue
(BeanDefinition beanDefinition, String propertyName) static boolean
isMatchingBean
(BeanFactory beanFactory, String beanName, Class<?> beanType) static boolean
nullOrEquals
(Object obj1, Object obj2) static boolean
nullSafeEquals
(Object obj1, Object obj2) static String
nullSafeName
(Class<?> type) static String
nullSafeSimpleName
(Class<?> type) static Class<?>
nullSafeType
(Object target) static Class<?>
nullSafeType
(Object target, Class<?> defaultType) static <T> T
requireObject
(Supplier<T> objectSupplier, String message) static <T> T
requireObject
(T object, String message) static boolean
static boolean
safeDoOperation
(SpringUtils.VoidReturningThrowableOperation operation, Runnable backupOperation) static <T> T
safeGetValue
(SpringUtils.ValueReturningThrowableOperation<T> operation) static <T> T
safeGetValue
(SpringUtils.ValueReturningThrowableOperation<T> operation, Function<Throwable, T> exceptionHandler) static <T> T
safeGetValue
(SpringUtils.ValueReturningThrowableOperation<T> operation, Supplier<T> defaultValueSupplier) static <T> T
safeGetValue
(SpringUtils.ValueReturningThrowableOperation<T> operation, T defaultValue) static void
static void
safeRunOperation
(SpringUtils.VoidReturningThrowableOperation operation, Function<Throwable, RuntimeException> exceptionConverter) static BeanDefinition
setPropertyReference
(BeanDefinition beanDefinition, String propertyName, String beanName) static BeanDefinition
setPropertyValue
(BeanDefinition beanDefinition, String propertyName, Object propertyValue)
-
Constructor Details
-
SpringUtils
public SpringUtils()
-
-
Method Details
-
areNotNull
Determines whether all theObject
values in the array are non-null -
isMatchingBean
public static boolean isMatchingBean(@NonNull BeanFactory beanFactory, String beanName, Class<?> beanType) - Parameters:
beanFactory
-Spring container
in which to resolve the bean; must not be null.beanName
-name
of the bean.beanType
-type
of the bean.- Returns:
- a boolean value indicating whether the
Spring container
contains a bean matching by bothname
andtype
. - See Also:
-
addDependsOn
@NonNull public static BeanDefinition addDependsOn(@NonNull BeanDefinition beanDefinition, @Nullable String... beanNames) Adds an array of bean dependencies (by name) to the givenBeanDefinition
.- Parameters:
beanDefinition
-BeanDefinition
to add the bean dependencies to; must not be null.beanNames
-String
array containing names of beans for which theBeanDefinition
depends on (or has a dependency).- Returns:
- the given
BeanDefinition
. - See Also:
-
getBeansOfTypeOrdered
@NonNull public static <T> List<T> getBeansOfTypeOrdered(@NonNull ConfigurableListableBeanFactory beanFactory, @NonNull Class<T> beanType) - Type Parameters:
T
-type
of the bean.- Parameters:
beanFactory
-Spring container
used to acquire the ordered beans.beanType
-type
of beans to acquire.- Returns:
- a
List
of beans of the giventype
in order. - See Also:
-
getBeansOfTypeOrdered
@NonNull public static <T> List<T> getBeansOfTypeOrdered(@NonNull ConfigurableListableBeanFactory beanFactory, @NonNull Class<T> beanType, boolean includeNonSingletons, boolean allowEagerInit) - Type Parameters:
T
-type
of the bean.- Parameters:
beanFactory
-Spring container
used to acquire the ordered beans.beanType
-type
of beans to acquire.includeNonSingletons
- boolean indicating whether to include non-Singleton beans from the Spring container.allowEagerInit
- boolean indicating whether to eagerly initializeFactoryBeans
.- Returns:
- a
List
of beans of the giventype
in order. - See Also:
-
getOrder
-
getOrderedStreamOfBeansByType
public static <T> Stream<T> getOrderedStreamOfBeansByType(@NonNull BeanFactory beanFactory, @NonNull Class<T> beanType) - Type Parameters:
T
-type
of the beans.- Parameters:
beanFactory
-BeanFactory
from which to acquire the beans.beanType
-type
of the beans.- Returns:
- an ordered
Stream
of beans from theBeanFactory
of the giventype
. - See Also:
-
getPropertyValue
-
setPropertyReference
public static BeanDefinition setPropertyReference(BeanDefinition beanDefinition, String propertyName, String beanName) -
setPropertyValue
public static BeanDefinition setPropertyValue(BeanDefinition beanDefinition, String propertyName, Object propertyValue) -
defaultIfEmpty
-
defaultIfEmpty
-
defaultIfNull
public static <T> T defaultIfNull(T value, T defaultValue) -
defaultIfNull
-
dereferenceBean
-
equalsIgnoreNull
-
nullOrEquals
-
nullSafeEquals
-
nullSafeName
-
nullSafeSimpleName
-
nullSafeType
-
nullSafeType
-
requireObject
-
requireObject
-
safeDoOperation
-
safeDoOperation
public static boolean safeDoOperation(SpringUtils.VoidReturningThrowableOperation operation, Runnable backupOperation) -
safeGetValue
-
safeGetValue
public static <T> T safeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, T defaultValue) -
safeGetValue
public static <T> T safeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, Supplier<T> defaultValueSupplier) -
safeGetValue
public static <T> T safeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, Function<Throwable, T> exceptionHandler) -
safeRunOperation
-
safeRunOperation
public static void safeRunOperation(SpringUtils.VoidReturningThrowableOperation operation, Function<Throwable, RuntimeException> exceptionConverter)
-