public abstract class SpringExtensions
extends java.lang.Object
Objects
, Class types
and Spring beans.Class
,
Object
,
Function
,
Stream
,
BeanFactory
,
FactoryBean
,
BeanDefinition
,
RuntimeBeanReference
,
Ordered
,
AnnotationAwareOrderComparator
,
Order
Modifier and Type | Class and Description |
---|---|
static interface |
SpringExtensions.OrderedBeanWrapper<T> |
static interface |
SpringExtensions.ValueReturningThrowableOperation<T> |
static interface |
SpringExtensions.VoidReturningThrowableOperation |
Constructor and Description |
---|
SpringExtensions() |
Modifier and Type | Method and Description |
---|---|
static org.springframework.beans.factory.config.BeanDefinition |
addDependsOn(org.springframework.beans.factory.config.BeanDefinition beanDefinition,
java.lang.String... beanNames)
Adds an array of bean dependencies (by name) to the given
BeanDefinition . |
static boolean |
areNotNull(java.lang.Object... values)
Determines whether all the
Object values in the array are non-null |
static java.lang.String |
defaultIfEmpty(java.lang.String value,
java.lang.String defaultValue) |
static java.lang.String |
defaultIfEmpty(java.lang.String value,
java.util.function.Supplier<java.lang.String> supplier) |
static <T> T |
defaultIfNull(T value,
java.util.function.Supplier<T> supplier) |
static <T> T |
defaultIfNull(T value,
T defaultValue) |
static java.lang.String |
dereferenceBean(java.lang.String beanName) |
static boolean |
equalsIgnoreNull(java.lang.Object obj1,
java.lang.Object obj2) |
static <T> java.util.List<T> |
getBeansOfTypeOrdered(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
java.lang.Class<T> beanType)
Returns a
List of beans by the given type in order. |
static <T> java.util.List<T> |
getBeansOfTypeOrdered(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
java.lang.Class<T> beanType,
boolean includeNonSingletons,
boolean allowEagerInit)
Returns a
List of beans by the given type in order. |
static java.lang.Integer |
getOrder(java.lang.Object target)
Null-safe operation to return the
order of the given Object if it is Ordered
or null if the given Object is not Ordered . |
static <T> java.util.stream.Stream<T> |
getOrderedStreamOfBeansByType(org.springframework.beans.factory.BeanFactory beanFactory,
java.lang.Class<T> beanType)
Returns bean of the given
type in an ordered Stream . |
static java.util.Optional<java.lang.Object> |
getPropertyValue(org.springframework.beans.factory.config.BeanDefinition beanDefinition,
java.lang.String propertyName) |
static boolean |
isMatchingBean(org.springframework.beans.factory.BeanFactory beanFactory,
java.lang.String beanName,
java.lang.Class<?> beanType)
Determines whether a given bean registered in the
Spring container matches by
both name and type . |
static boolean |
nullOrEquals(java.lang.Object obj1,
java.lang.Object obj2) |
static boolean |
nullSafeEquals(java.lang.Object obj1,
java.lang.Object obj2) |
static java.lang.String |
nullSafeName(java.lang.Class<?> type) |
static java.lang.String |
nullSafeSimpleName(java.lang.Class<?> type) |
static java.lang.Class<?> |
nullSafeType(java.lang.Object target) |
static java.lang.Class<?> |
nullSafeType(java.lang.Object target,
java.lang.Class<?> defaultType) |
static <T> T |
requireObject(java.util.function.Supplier<T> objectSupplier,
java.lang.String message) |
static <T> T |
requireObject(T object,
java.lang.String message) |
static boolean |
safeDoOperation(SpringExtensions.VoidReturningThrowableOperation operation) |
static boolean |
safeDoOperation(SpringExtensions.VoidReturningThrowableOperation operation,
java.lang.Runnable backupOperation) |
static <T> T |
safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation) |
static <T> T |
safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation,
java.util.function.Function<java.lang.Throwable,T> exceptionHandler) |
static <T> T |
safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation,
java.util.function.Supplier<T> defaultValueSupplier) |
static <T> T |
safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation,
T defaultValue) |
static void |
safeRunOperation(SpringExtensions.VoidReturningThrowableOperation operation) |
static void |
safeRunOperation(SpringExtensions.VoidReturningThrowableOperation operation,
java.util.function.Function<java.lang.Throwable,java.lang.RuntimeException> exceptionConverter) |
static org.springframework.beans.factory.config.BeanDefinition |
setPropertyReference(org.springframework.beans.factory.config.BeanDefinition beanDefinition,
java.lang.String propertyName,
java.lang.String beanName) |
static org.springframework.beans.factory.config.BeanDefinition |
setPropertyValue(org.springframework.beans.factory.config.BeanDefinition beanDefinition,
java.lang.String propertyName,
java.lang.Object propertyValue) |
public static boolean areNotNull(java.lang.Object... values)
Object
values in the array are non-nullvalues
- array of Objects
to evaluate.Object
values
in the array are non-null.public static boolean isMatchingBean(@NonNull org.springframework.beans.factory.BeanFactory beanFactory, java.lang.String beanName, java.lang.Class<?> beanType)
Spring container
matches by
both name
and type
.beanFactory
- Spring container
in which to resolve the bean;
must not be null.beanName
- name
of the bean.beanType
- type
of the bean.Spring container
contains a bean
matching by both name
and type
.BeanFactory
,
Class
,
String
@NonNull public static org.springframework.beans.factory.config.BeanDefinition addDependsOn(@NonNull org.springframework.beans.factory.config.BeanDefinition beanDefinition, @Nullable java.lang.String... beanNames)
BeanDefinition
.beanDefinition
- BeanDefinition
to add the bean dependencies to; must not be null.beanNames
- String
array containing names of beans for which the BeanDefinition
depends on (or has a dependency).BeanDefinition
.BeanDefinition
@NonNull public static <T> java.util.List<T> getBeansOfTypeOrdered(@NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NonNull java.lang.Class<T> beanType)
List
of beans by the given type
in order.T
- type
of the bean.beanFactory
- Spring container
used to acquire the ordered beans.beanType
- type
of beans to acquire.List
of beans of the given type
in order.getBeansOfTypeOrdered(ConfigurableListableBeanFactory, Class, boolean, boolean)
,
ConfigurableListableBeanFactory
,
Class
,
List
@NonNull public static <T> java.util.List<T> getBeansOfTypeOrdered(@NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NonNull java.lang.Class<T> beanType, boolean includeNonSingletons, boolean allowEagerInit)
List
of beans by the given type
in order.T
- type
of the bean.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 initialize FactoryBeans
.List
of beans of the given type
in order.ConfigurableListableBeanFactory
,
Class
,
List
@Nullable public static java.lang.Integer getOrder(@Nullable java.lang.Object target)
order
of the given Object
if it is Ordered
or null if the given Object
is not Ordered
.target
- Object
to evaluate; may be null.order
of the given Object
if Ordered
,
otherwise return null.Ordered
public static <T> java.util.stream.Stream<T> getOrderedStreamOfBeansByType(@NonNull org.springframework.beans.factory.BeanFactory beanFactory, @NonNull java.lang.Class<T> beanType)
type
in an ordered Stream
.T
- type
of the beans.beanFactory
- BeanFactory
from which to acquire the beans.beanType
- type
of the beans.Stream
of beans from the BeanFactory
of the given type
.BeanFactory
,
Stream
,
Class
public static java.util.Optional<java.lang.Object> getPropertyValue(org.springframework.beans.factory.config.BeanDefinition beanDefinition, java.lang.String propertyName)
public static org.springframework.beans.factory.config.BeanDefinition setPropertyReference(org.springframework.beans.factory.config.BeanDefinition beanDefinition, java.lang.String propertyName, java.lang.String beanName)
public static org.springframework.beans.factory.config.BeanDefinition setPropertyValue(org.springframework.beans.factory.config.BeanDefinition beanDefinition, java.lang.String propertyName, java.lang.Object propertyValue)
public static java.lang.String defaultIfEmpty(java.lang.String value, java.lang.String defaultValue)
public static java.lang.String defaultIfEmpty(java.lang.String value, java.util.function.Supplier<java.lang.String> supplier)
public static <T> T defaultIfNull(T value, T defaultValue)
public static <T> T defaultIfNull(T value, java.util.function.Supplier<T> supplier)
public static java.lang.String dereferenceBean(java.lang.String beanName)
public static boolean equalsIgnoreNull(java.lang.Object obj1, java.lang.Object obj2)
public static boolean nullOrEquals(java.lang.Object obj1, java.lang.Object obj2)
public static boolean nullSafeEquals(java.lang.Object obj1, java.lang.Object obj2)
public static java.lang.String nullSafeName(java.lang.Class<?> type)
public static java.lang.String nullSafeSimpleName(java.lang.Class<?> type)
public static java.lang.Class<?> nullSafeType(java.lang.Object target)
public static java.lang.Class<?> nullSafeType(java.lang.Object target, java.lang.Class<?> defaultType)
public static <T> T requireObject(@Nullable T object, java.lang.String message)
public static <T> T requireObject(@NonNull java.util.function.Supplier<T> objectSupplier, java.lang.String message)
public static boolean safeDoOperation(SpringExtensions.VoidReturningThrowableOperation operation)
public static boolean safeDoOperation(SpringExtensions.VoidReturningThrowableOperation operation, java.lang.Runnable backupOperation)
public static <T> T safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation)
public static <T> T safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation, T defaultValue)
public static <T> T safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation, java.util.function.Supplier<T> defaultValueSupplier)
public static <T> T safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)
public static void safeRunOperation(SpringExtensions.VoidReturningThrowableOperation operation)
public static void safeRunOperation(SpringExtensions.VoidReturningThrowableOperation operation, java.util.function.Function<java.lang.Throwable,java.lang.RuntimeException> exceptionConverter)