Configurations Class — spring-boot Architecture
Architecture documentation for the Configurations class in Configurations.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/context/annotation/Configurations.java lines 61–189
public abstract class Configurations {
private static final Comparator<Object> COMPARATOR = OrderComparator.INSTANCE
.thenComparing((other) -> other.getClass().getName());
private final @Nullable UnaryOperator<Collection<Class<?>>> sorter;
private final Set<Class<?>> classes;
private final @Nullable Function<Class<?>, String> beanNameGenerator;
/**
* Create a new {@link Configurations} instance.
* @param classes the configuration classes
*/
protected Configurations(Collection<Class<?>> classes) {
Assert.notNull(classes, "'classes' must not be null");
this.sorter = null;
this.classes = Collections.unmodifiableSet(new LinkedHashSet<>(classes));
this.beanNameGenerator = null;
}
/**
* Create a new {@link Configurations} instance.
* @param sorter a {@link UnaryOperator} used to sort the configurations
* @param classes the configuration classes
* @param beanNameGenerator an optional function used to generate the bean name
* @since 3.4.0
*/
protected Configurations(@Nullable UnaryOperator<Collection<Class<?>>> sorter, Collection<Class<?>> classes,
@Nullable Function<Class<?>, String> beanNameGenerator) {
Assert.notNull(classes, "'classes' must not be null");
this.sorter = (sorter != null) ? sorter : UnaryOperator.identity();
Collection<Class<?>> sorted = this.sorter.apply(classes);
this.classes = Collections.unmodifiableSet(new LinkedHashSet<>(sorted));
this.beanNameGenerator = beanNameGenerator;
}
protected final Set<Class<?>> getClasses() {
return this.classes;
}
/**
* Merge configurations from another source of the same type.
* @param other the other {@link Configurations} (must be of the same type as this
* instance)
* @return a new configurations instance (must be of the same type as this instance)
*/
protected Configurations merge(Configurations other) {
Set<Class<?>> mergedClasses = new LinkedHashSet<>(getClasses());
mergedClasses.addAll(other.getClasses());
if (this.sorter != null) {
mergedClasses = new LinkedHashSet<>(this.sorter.apply(mergedClasses));
}
return merge(mergedClasses);
}
/**
* Merge configurations.
* @param mergedClasses the merged classes
* @return a new configurations instance (must be of the same type as this instance)
*/
protected abstract Configurations merge(Set<Class<?>> mergedClasses);
/**
* Return the bean name that should be used for the given configuration class or
* {@code null} to use the default name.
* @param beanClass the bean class
* @return the bean name
* @since 3.4.0
*/
public @Nullable String getBeanName(Class<?> beanClass) {
return (this.beanNameGenerator != null) ? this.beanNameGenerator.apply(beanClass) : null;
}
/**
* Return the classes from all the specified configurations in the order that they
* would be registered.
* @param configurations the source configuration
* @return configuration classes in registration order
*/
public static Class<?>[] getClasses(Configurations... configurations) {
return getClasses(Arrays.asList(configurations));
}
/**
* Return the classes from all the specified configurations in the order that they
* would be registered.
* @param configurations the source configuration
* @return configuration classes in registration order
*/
public static Class<?>[] getClasses(Collection<Configurations> configurations) {
List<Configurations> collated = collate(configurations);
LinkedHashSet<Class<?>> classes = collated.stream()
.flatMap(Configurations::streamClasses)
.collect(Collectors.toCollection(LinkedHashSet::new));
return ClassUtils.toClassArray(classes);
}
/**
* Collate the given configuration by sorting and merging them.
* @param configurations the source configuration
* @return the collated configurations
* @since 3.4.0
*/
public static List<Configurations> collate(Collection<Configurations> configurations) {
LinkedList<Configurations> collated = new LinkedList<>();
for (Configurations configuration : sortConfigurations(configurations)) {
if (collated.isEmpty() || collated.getLast().getClass() != configuration.getClass()) {
collated.add(configuration);
}
else {
collated.set(collated.size() - 1, collated.getLast().merge(configuration));
}
}
return collated;
}
private static List<Configurations> sortConfigurations(Collection<Configurations> configurations) {
List<Configurations> sorted = new ArrayList<>(configurations);
sorted.sort(COMPARATOR);
return sorted;
}
private static Stream<Class<?>> streamClasses(Configurations configurations) {
return configurations.getClasses().stream();
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free