Class SpringExtensions

java.lang.Object
org.springframework.data.gemfire.util.SpringExtensions
Direct Known Subclasses:
DistributedSystemUtils

public abstract class SpringExtensions extends Object
Abstract utility class encapsulating functionality common to Objects, Class types and Spring beans.
Since:
1.8.0
See Also:
  • Class
  • Object
  • Function
  • Stream
  • BeanFactory
  • FactoryBean
  • BeanDefinition
  • RuntimeBeanReference
  • Ordered
  • AnnotationAwareOrderComparator
  • Order
  • Constructor Details

    • SpringExtensions

      public SpringExtensions()
  • Method Details

    • areNotNull

      public static boolean areNotNull(Object... values)
      Determines whether all the Object values in the array are non-null.
      Parameters:
      values - array of values to evaluate for null.
      Returns:
      a boolean value indicating whether all of the Object values in the array are non-null.
    • isMatchingBean

      public static boolean isMatchingBean(@NonNull org.springframework.beans.factory.BeanFactory beanFactory, @NonNull String beanName, @Nullable Class<?> beanType)
      Determines whether a given bean registered in the Spring BeanFactory matches by name and type.
      Parameters:
      beanFactory - Spring BeanFactory used 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 BeanFactory contains a bean matching by name and type.
      See Also:
    • addDependsOn

      @NonNull public static org.springframework.beans.factory.config.BeanDefinition addDependsOn(@NonNull org.springframework.beans.factory.config.BeanDefinition beanDefinition, String... beanNames)
      Adds an array of bean dependencies (by name) to the given BeanDefinition.
      Parameters:
      beanDefinition - BeanDefinition to add the bean dependencies; must not be null.
      beanNames - array of names of beans for which the BeanDefinition depends on, or will have a dependency.
      Returns:
      the given BeanDefinition.
      See Also:
      • BeanDefinition
    • getBeansOfTypeOrdered

      @NonNull public static <T> List<T> getBeansOfTypeOrdered(@NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NonNull Class<T> beanType)
      Returns a List of beans by the given type in order.
      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 given type in order.
      See Also:
    • getBeansOfTypeOrdered

      @NonNull public static <T> List<T> getBeansOfTypeOrdered(@NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NonNull Class<T> beanType, boolean includeNonSingletons, boolean allowEagerInit)
      Returns a List of beans by the given type in order.
      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 initialize FactoryBeans.
      Returns:
      a List of beans of the given type in order.
      See Also:
    • getOrder

      @Nullable public static Integer getOrder(@Nullable 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.
      Parameters:
      target - Object to evaluate; may be null.
      Returns:
      the order of the given Object if Ordered, otherwise return null.
      See Also:
      • Ordered
    • getOrderedStreamOfBeansByType

      public static <T> Stream<T> getOrderedStreamOfBeansByType(@NonNull org.springframework.beans.factory.BeanFactory beanFactory, @NonNull Class<T> beanType)
      Returns bean of the given type in an ordered Stream.
      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 the BeanFactory of the given type.
      See Also:
    • getPropertyValue

      public static Optional<Object> getPropertyValue(@Nullable org.springframework.beans.factory.config.BeanDefinition beanDefinition, @Nullable String propertyName)
    • setPropertyReference

      public static org.springframework.beans.factory.config.BeanDefinition setPropertyReference(@NonNull org.springframework.beans.factory.config.BeanDefinition beanDefinition, @NonNull String propertyName, @NonNull String beanName)
    • setPropertyValue

      public static org.springframework.beans.factory.config.BeanDefinition setPropertyValue(@NonNull org.springframework.beans.factory.config.BeanDefinition beanDefinition, @NonNull String propertyName, @Nullable Object propertyValue)
    • defaultIfEmpty

      public static String defaultIfEmpty(String value, String defaultValue)
    • defaultIfEmpty

      public static String defaultIfEmpty(String value, Supplier<String> supplier)
    • defaultIfNull

      public static <T> T defaultIfNull(T value, T defaultValue)
    • defaultIfNull

      public static <T> T defaultIfNull(T value, Supplier<T> supplier)
    • dereferenceBean

      public static String dereferenceBean(String beanName)
    • equalsIgnoreNull

      public static boolean equalsIgnoreNull(Object obj1, Object obj2)
    • nullOrEquals

      public static boolean nullOrEquals(Object obj1, Object obj2)
    • nullSafeEquals

      public static boolean nullSafeEquals(Object obj1, Object obj2)
    • nullSafeName

      public static String nullSafeName(Class<?> type)
    • nullSafeSimpleName

      public static String nullSafeSimpleName(Class<?> type)
    • nullSafeType

      public static Class<?> nullSafeType(Object target)
    • nullSafeType

      public static Class<?> nullSafeType(Object target, Class<?> defaultType)
    • requireObject

      public static <T> T requireObject(@Nullable T object, String message)
    • requireObject

      public static <T> T requireObject(@NonNull Supplier<T> objectSupplier, String message)
    • safeDoOperation

      public static boolean safeDoOperation(SpringExtensions.VoidReturningThrowableOperation operation)
    • safeDoOperation

      public static boolean safeDoOperation(SpringExtensions.VoidReturningThrowableOperation operation, Runnable backupOperation)
    • safeGetValue

      public static <T> T safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation)
    • safeGetValue

      public static <T> T safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation, T defaultValue)
    • safeGetValue

      public static <T> T safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation, Supplier<T> defaultValueSupplier)
    • safeGetValue

      public static <T> T safeGetValue(SpringExtensions.ValueReturningThrowableOperation<T> operation, Function<Throwable,T> exceptionHandler)
    • safeRunOperation

      public static void safeRunOperation(SpringExtensions.VoidReturningThrowableOperation operation)
    • safeRunOperation

      public static void safeRunOperation(SpringExtensions.VoidReturningThrowableOperation operation, Function<Throwable,RuntimeException> exceptionConverter)