Class ConfigUtils

java.lang.Object
ai.timefold.solver.core.config.util.ConfigUtils

public class ConfigUtils extends Object
  • Method Details

    • newInstance

      public static <T> @NonNull T newInstance(@Nullable Object configBean, @NonNull String propertyName, @NonNull Class<T> clazz)
      Create a new instance of clazz from a config's property.

      If the instantiation fails, the simple class name of configBean will be used as the owner of propertyName.

      Intended usage:

       selectionFilter = ConfigUtils.newInstance(config, "filterClass", config.getFilterClass());
       
      Type Parameters:
      T - the new instance type
      Parameters:
      configBean - the bean holding the clazz to be instantiated
      propertyName - configBean's property holding clazz
      clazz - Class representation of the type T
      Returns:
      new instance of clazz
    • newInstance

      public static <T> @NonNull T newInstance(@NonNull Supplier<String> ownerDescriptor, @NonNull String propertyName, @NonNull Class<T> clazz)
      Create a new instance of clazz from a general source.

      If the instantiation fails, the result of ownerDescriptor will be used to describe the owner of propertyName.

      Type Parameters:
      T - the new instance type
      Parameters:
      ownerDescriptor - describes the owner of propertyName
      propertyName - property holding the clazz
      clazz - Class representation of the type T
      Returns:
      new instance of clazz
    • applyCustomProperties

      public static void applyCustomProperties(@NonNull Object bean, @NonNull String beanClassPropertyName, @Nullable Map<@NonNull String,@NonNull String> customProperties, @NonNull String customPropertiesPropertyName)
    • inheritConfig

      public static <Config_ extends AbstractConfig<Config_>> @Nullable Config_ inheritConfig(@Nullable Config_ original, @Nullable Config_ inherited)
    • inheritMergeableListConfig

      public static <Config_ extends AbstractConfig<Config_>> @Nullable List<Config_> inheritMergeableListConfig(@Nullable List<Config_> originalList, @Nullable List<Config_> inheritedList)
    • inheritOverwritableProperty

      public static <T> @Nullable T inheritOverwritableProperty(@Nullable T original, @Nullable T inherited)
    • inheritMergeableListProperty

      public static <T> @Nullable List<T> inheritMergeableListProperty(@Nullable List<T> originalList, @Nullable List<T> inheritedList)
    • inheritMergeableEnumSetProperty

      public static <E extends Enum<E>> @Nullable Set<E> inheritMergeableEnumSetProperty(@Nullable Set<E> originalSet, @Nullable Set<E> inheritedSet)
    • inheritUniqueMergeableListProperty

      public static <T> @Nullable List<T> inheritUniqueMergeableListProperty(@Nullable List<T> originalList, @Nullable List<T> inheritedList)
    • inheritMergeableMapProperty

      public static <K, T> @Nullable Map<K,T> inheritMergeableMapProperty(@Nullable Map<K,T> originalMap, @Nullable Map<K,T> inheritedMap)
    • mergeProperty

      public static <T> @Nullable T mergeProperty(@Nullable T a, @Nullable T b)
    • meldProperty

      public static <T> @Nullable T meldProperty(@Nullable T a, @Nullable T b)
      A relaxed version of mergeProperty(Object, Object). Used primarily for merging failed benchmarks, where a property remains the same over benchmark runs (for example: dataset problem size), but the property in the failed benchmark isn't initialized, therefore null. When merging, we can still use the correctly initialized property of the benchmark that didn't fail.

      Null-handling:

      • if both properties are null, returns null
      • if only one of the properties is not null, returns that property
      • if both properties are not null, returns mergeProperty(Object, Object)
      Type Parameters:
      T - the type of property a and b
      Parameters:
      a - property a
      b - property b
      Returns:
      sometimes null
      See Also:
    • isEmptyCollection

      public static boolean isEmptyCollection(@Nullable Collection<?> collection)
    • ceilDivide

      public static int ceilDivide(int dividend, int divisor)
      Divides and ceils the result without using floating point arithmetic. For floor division, see Math.floorDiv(long, long).
      Parameters:
      dividend - the dividend
      divisor - the divisor
      Returns:
      dividend / divisor, ceiled
      Throws:
      ArithmeticException - if divisor == 0
    • resolvePoolSize

      public static int resolvePoolSize(@NonNull String propertyName, @NonNull String value, @NonNull String @NonNull ... magicValues)
    • getAllParents

      public static @NonNull List<@NonNull Class<?>> getAllParents(@Nullable Class<?> bottomClass)
    • getAllAnnotatedLineageClasses

      public static @NonNull List<@NonNull Class<?>> getAllAnnotatedLineageClasses(@Nullable Class<?> bottomClass, @NonNull Class<? extends Annotation> annotation)
    • getDeclaredMembers

      public static @NonNull List<Member> getDeclaredMembers(@NonNull Class<?> baseClass)
      Returns:
      sorted by type (fields before methods), then by AlphabeticMemberComparator.
    • getAllMembers

      public static @NonNull List<Member> getAllMembers(@NonNull Class<?> baseClass, @NonNull Class<? extends Annotation> annotationClass)
      Returns:
      sorted by type (fields before methods), then by AlphabeticMemberComparator.
    • extractAnnotationClass

      @SafeVarargs public static Class<? extends Annotation> extractAnnotationClass(@NonNull Member member, @NonNull Class<? extends Annotation>... annotationClasses)
    • extractAnnotationClasses

      @SafeVarargs public static List<Class<? extends Annotation>> extractAnnotationClasses(@NonNull Member member, @NonNull Class<? extends Annotation>... annotationClasses)
    • extractGenericTypeParameterOrFail

      public static Class<?> extractGenericTypeParameterOrFail(@NonNull String parentClassConcept, @NonNull Class<?> parentClass, @NonNull Class<?> type, @NonNull Type genericType, @Nullable Class<? extends Annotation> annotationClass, @NonNull String memberName)
    • extractGenericTypeParameter

      public static Optional<Class<?>> extractGenericTypeParameter(@NonNull String parentClassConcept, @NonNull Class<?> parentClass, @NonNull Class<?> type, @NonNull Type genericType, @Nullable Class<? extends Annotation> annotationClass, @NonNull String memberName)
    • findPlanningIdMemberAccessor

      public static <C> @Nullable MemberAccessor findPlanningIdMemberAccessor(@NonNull Class<C> clazz, @NonNull MemberAccessorFactory memberAccessorFactory, @NonNull DomainAccessType domainAccessType)
      This method is heavy, and it is effectively a computed constant. It is recommended that its results are cached at call sites.
      Type Parameters:
      C - the class type
      Returns:
      null if no accessor found
    • abbreviate

      public static @NonNull String abbreviate(@Nullable List<@Nullable String> list, int limit)
    • abbreviate

      public static @NonNull String abbreviate(@Nullable List<@Nullable String> list)