public abstract class SpringUtils extends 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 |
SpringUtils.OrderedBeanWrapper<T> |
static interface |
SpringUtils.ValueReturningThrowableOperation<T> |
static interface |
SpringUtils.VoidReturningExceptionThrowingOperation
Deprecated.
|
static interface |
SpringUtils.VoidReturningThrowableOperation |
| Constructor and Description |
|---|
SpringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static BeanDefinition |
addDependsOn(BeanDefinition beanDefinition,
String... beanNames)
Adds an array of bean dependencies (by name) to the given
BeanDefinition. |
static boolean |
areNotNull(Object... values)
Determines whether all the
Object values in the array are non-null |
static 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 |
getOrder(Object target)
|
static <T> Stream<T> |
getOrderedStreamOfBeansByType(BeanFactory beanFactory,
Class<T> beanType)
|
static Optional<Object> |
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 |
safeDoOperation(SpringUtils.VoidReturningThrowableOperation operation) |
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 |
safeRunOperation(SpringUtils.VoidReturningThrowableOperation operation) |
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) |
public static boolean areNotNull(Object... values)
Object values in the array are non-nullpublic static boolean isMatchingBean(@NonNull BeanFactory beanFactory, String beanName, Class<?> beanType)
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 BeanDefinition addDependsOn(@NonNull BeanDefinition beanDefinition, @Nullable 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> List<T> getBeansOfTypeOrdered(@NonNull ConfigurableListableBeanFactory beanFactory, @NonNull Class<T> beanType)
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> List<T> getBeansOfTypeOrdered(@NonNull ConfigurableListableBeanFactory beanFactory, @NonNull Class<T> beanType, boolean includeNonSingletons, boolean allowEagerInit)
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,
Listpublic static <T> Stream<T> getOrderedStreamOfBeansByType(@NonNull BeanFactory beanFactory, @NonNull Class<T> beanType)
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,
Classpublic static Optional<Object> getPropertyValue(BeanDefinition beanDefinition, String propertyName)
public static BeanDefinition setPropertyReference(BeanDefinition beanDefinition, String propertyName, String beanName)
public static BeanDefinition setPropertyValue(BeanDefinition beanDefinition, String propertyName, Object propertyValue)
public static <T> T defaultIfNull(T value,
T defaultValue)
public static <T> T defaultIfNull(T value,
Supplier<T> supplier)
public static <T> T requireObject(@NonNull Supplier<T> objectSupplier, String message)
public static boolean safeDoOperation(SpringUtils.VoidReturningThrowableOperation operation)
public static boolean safeDoOperation(SpringUtils.VoidReturningThrowableOperation operation, Runnable backupOperation)
public static <T> T safeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation)
public static <T> T safeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, T defaultValue)
public static <T> T safeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, Supplier<T> defaultValueSupplier)
public static <T> T safeGetValue(SpringUtils.ValueReturningThrowableOperation<T> operation, Function<Throwable,T> exceptionHandler)
public static void safeRunOperation(SpringUtils.VoidReturningThrowableOperation operation)
public static void safeRunOperation(SpringUtils.VoidReturningThrowableOperation operation, Function<Throwable,RuntimeException> exceptionConverter)
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.