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
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfacestatic interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BeanDefinitionaddDependsOn(BeanDefinition beanDefinition, String... beanNames) Adds an array of bean dependencies (by name) to the givenBeanDefinition.static booleanareNotNull(Object... values) Determines whether all theObjectvalues in the array are non-nullstatic StringdefaultIfEmpty(String value, String defaultValue) static StringdefaultIfEmpty(String value, Supplier<String> supplier) static <T> TdefaultIfNull(T value, Supplier<T> supplier) static <T> TdefaultIfNull(T value, T defaultValue) static StringdereferenceBean(String beanName) static booleanequalsIgnoreNull(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 Integerstatic <T> Stream<T>getOrderedStreamOfBeansByType(BeanFactory beanFactory, Class<T> beanType) getPropertyValue(BeanDefinition beanDefinition, String propertyName) static booleanisMatchingBean(BeanFactory beanFactory, String beanName, Class<?> beanType) static booleannullOrEquals(Object obj1, Object obj2) static booleannullSafeEquals(Object obj1, Object obj2) static StringnullSafeName(Class<?> type) static StringnullSafeSimpleName(Class<?> type) static Class<?>nullSafeType(Object target) static Class<?>nullSafeType(Object target, Class<?> defaultType) static <T> TrequireObject(Supplier<T> objectSupplier, String message) static <T> TrequireObject(T object, String message) static booleanstatic booleansafeDoOperation(SpringUtils.VoidReturningThrowableOperation operation, Runnable backupOperation) static <T> TsafeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation) static <T> TsafeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, Function<Throwable, T> exceptionHandler) static <T> TsafeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, Supplier<T> defaultValueSupplier) static <T> TsafeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, T defaultValue) static voidstatic voidsafeRunOperation(SpringUtils.VoidReturningThrowableOperation operation, Function<Throwable, RuntimeException> exceptionConverter) static BeanDefinitionsetPropertyReference(BeanDefinition beanDefinition, String propertyName, String beanName) static BeanDefinitionsetPropertyValue(BeanDefinition beanDefinition, String propertyName, Object propertyValue)
-
Constructor Details
-
SpringUtils
public SpringUtils()
-
-
Method Details
-
areNotNull
Determines whether all theObjectvalues in the array are non-null -
isMatchingBean
public static boolean isMatchingBean(@NonNull BeanFactory beanFactory, String beanName, Class<?> beanType) - Parameters:
beanFactory-Spring containerin which to resolve the bean; must not be null.beanName-nameof the bean.beanType-typeof the bean.- Returns:
- a boolean value indicating whether the
Spring containercontains a bean matching by bothnameandtype. - 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-BeanDefinitionto add the bean dependencies to; must not be null.beanNames-Stringarray containing names of beans for which theBeanDefinitiondepends 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-typeof the bean.- Parameters:
beanFactory-Spring containerused to acquire the ordered beans.beanType-typeof beans to acquire.- Returns:
- a
Listof beans of the giventypein 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-typeof the bean.- Parameters:
beanFactory-Spring containerused to acquire the ordered beans.beanType-typeof 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
Listof beans of the giventypein order. - See Also:
-
getOrder
-
getOrderedStreamOfBeansByType
public static <T> Stream<T> getOrderedStreamOfBeansByType(@NonNull BeanFactory beanFactory, @NonNull Class<T> beanType) - Type Parameters:
T-typeof the beans.- Parameters:
beanFactory-BeanFactoryfrom which to acquire the beans.beanType-typeof the beans.- Returns:
- an ordered
Streamof beans from theBeanFactoryof 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)
-