Class ConfigUtils
java.lang.Object
ai.timefold.solver.core.config.util.ConfigUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull Stringabbreviate(@Nullable List<@Nullable String> list) static @NonNull Stringabbreviate(@Nullable List<@Nullable String> list, int limit) static voidapplyCustomProperties(@NonNull Object bean, @NonNull String beanClassPropertyName, @Nullable Map<@NonNull String, @NonNull String> customProperties, @NonNull String customPropertiesPropertyName) static intceilDivide(int dividend, int divisor) Divides and ceils the result without using floating point arithmetic.static Class<? extends Annotation>extractAnnotationClass(@NonNull Member member, @NonNull Class<? extends Annotation>... annotationClasses) static List<Class<? extends Annotation>>extractAnnotationClasses(@NonNull Member member, @NonNull Class<? extends Annotation>... annotationClasses) extractGenericTypeParameter(@NonNull String parentClassConcept, @NonNull Class<?> parentClass, @NonNull Class<?> type, @NonNull Type genericType, @Nullable Class<? extends Annotation> annotationClass, @NonNull String memberName) static Class<?>extractGenericTypeParameterOrFail(@NonNull String parentClassConcept, @NonNull Class<?> parentClass, @NonNull Class<?> type, @NonNull Type genericType, @Nullable Class<? extends Annotation> annotationClass, @NonNull String memberName) static <C> @Nullable MemberAccessorfindPlanningIdMemberAccessor(@NonNull Class<C> clazz, @NonNull MemberAccessorFactory memberAccessorFactory, @NonNull DomainAccessType domainAccessType) This method is heavy, and it is effectively a computed constant.getAllAnnotatedLineageClasses(@Nullable Class<?> bottomClass, @NonNull Class<? extends Annotation> annotation) getAllMembers(@NonNull Class<?> baseClass, @NonNull Class<? extends Annotation> annotationClass) getAllParents(@Nullable Class<?> bottomClass) getDeclaredMembers(@NonNull Class<?> baseClass) static <Config_ extends AbstractConfig<Config_>>
@Nullable Config_inheritConfig(@Nullable Config_ original, @Nullable Config_ inherited) inheritMergeableEnumSetProperty(@Nullable Set<E> originalSet, @Nullable Set<E> inheritedSet) static <Config_ extends AbstractConfig<Config_>>
@Nullable List<Config_>inheritMergeableListConfig(@Nullable List<Config_> originalList, @Nullable List<Config_> inheritedList) static <T> @Nullable List<T>inheritMergeableListProperty(@Nullable List<T> originalList, @Nullable List<T> inheritedList) static <K,T> @Nullable Map<K, T> inheritMergeableMapProperty(@Nullable Map<K, T> originalMap, @Nullable Map<K, T> inheritedMap) static <T> @Nullable TinheritOverwritableProperty(@Nullable T original, @Nullable T inherited) static <T> @Nullable List<T>inheritUniqueMergeableListProperty(@Nullable List<T> originalList, @Nullable List<T> inheritedList) static booleanisEmptyCollection(@Nullable Collection<?> collection) static <T> @Nullable TmeldProperty(@Nullable T a, @Nullable T b) A relaxed version ofmergeProperty(Object, Object).static <T> @Nullable TmergeProperty(@Nullable T a, @Nullable T b) static <T> @NonNull TnewInstance(@NonNull Supplier<String> ownerDescriptor, @NonNull String propertyName, @NonNull Class<T> clazz) Create a new instance of clazz from a general source.static <T> @NonNull TnewInstance(@Nullable Object configBean, @NonNull String propertyName, @NonNull Class<T> clazz) Create a new instance of clazz from a config's property.static intresolvePoolSize(@NonNull String propertyName, @NonNull String value, @NonNull String @NonNull ... magicValues)
-
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
configBeanwill be used as the owner ofpropertyName.Intended usage:
selectionFilter = ConfigUtils.newInstance(config, "filterClass", config.getFilterClass());
- Type Parameters:
T- the new instance type- Parameters:
configBean- the bean holding theclazzto be instantiatedpropertyName-configBean's property holdingclazzclazz-Classrepresentation of the typeT- 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
ownerDescriptorwill be used to describe the owner ofpropertyName.- Type Parameters:
T- the new instance type- Parameters:
ownerDescriptor- describes the owner ofpropertyNamepropertyName- property holding theclazzclazz-Classrepresentation of the typeT- Returns:
- new instance of clazz
-
applyCustomProperties
-
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
-
inheritMergeableEnumSetProperty
-
inheritUniqueMergeableListProperty
-
inheritMergeableMapProperty
-
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 ofmergeProperty(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 propertyaandb- Parameters:
a- propertyab- propertyb- Returns:
- sometimes null
- See Also:
-
isEmptyCollection
-
ceilDivide
public static int ceilDivide(int dividend, int divisor) Divides and ceils the result without using floating point arithmetic. For floor division, seeMath.floorDiv(long, long).- Parameters:
dividend- the dividenddivisor- the divisor- Returns:
- dividend / divisor, ceiled
- Throws:
ArithmeticException- ifdivisor == 0
-
resolvePoolSize
-
getAllParents
-
getAllAnnotatedLineageClasses
public static @NonNull List<@NonNull Class<?>> getAllAnnotatedLineageClasses(@Nullable Class<?> bottomClass, @NonNull Class<? extends Annotation> annotation) -
getDeclaredMembers
- 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
-
extractGenericTypeParameter
-
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
-
abbreviate
-