MetadataItemCondition Class — spring-boot Architecture
Architecture documentation for the MetadataItemCondition class in Metadata.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/Metadata.java lines 78–227
public static class MetadataItemCondition extends Condition<ConfigurationMetadata> {
private final ItemType itemType;
private final String name;
private final String type;
private final Class<?> sourceType;
private final String sourceMethod;
private final String description;
private final Object defaultValue;
private final ItemDeprecation deprecation;
public MetadataItemCondition(ItemType itemType, String name) {
this(itemType, name, null, null, null, null, null, null);
}
public MetadataItemCondition(ItemType itemType, String name, String type, Class<?> sourceType,
String sourceMethod, String description, Object defaultValue, ItemDeprecation deprecation) {
this.itemType = itemType;
this.name = name;
this.type = type;
this.sourceType = sourceType;
this.sourceMethod = sourceMethod;
this.description = description;
this.defaultValue = defaultValue;
this.deprecation = deprecation;
describedAs(createDescription());
}
private String createDescription() {
StringBuilder description = new StringBuilder();
description.append("an item named '").append(this.name).append("'");
if (this.type != null) {
description.append(" with dataType:").append(this.type);
}
if (this.sourceType != null) {
description.append(" with sourceType:").append(this.sourceType);
}
if (this.sourceMethod != null) {
description.append(" with sourceMethod:").append(this.sourceMethod);
}
if (this.defaultValue != null) {
description.append(" with defaultValue:").append(this.defaultValue);
}
if (this.description != null) {
description.append(" with description:").append(this.description);
}
if (this.deprecation != null) {
description.append(" with deprecation:").append(this.deprecation);
}
return description.toString();
}
@Override
public boolean matches(ConfigurationMetadata value) {
ItemMetadata itemMetadata = findItem(value, this.name);
if (itemMetadata == null) {
return false;
}
if (this.type != null && !this.type.equals(itemMetadata.getType())) {
return false;
}
if (this.sourceType != null && !this.sourceType.getName().equals(itemMetadata.getSourceType())) {
return false;
}
if (this.sourceMethod != null && !this.sourceMethod.equals(itemMetadata.getSourceMethod())) {
return false;
}
if (this.defaultValue != null
&& !ObjectUtils.nullSafeEquals(this.defaultValue, itemMetadata.getDefaultValue())) {
return false;
}
if (this.defaultValue == null && itemMetadata.getDefaultValue() != null) {
return false;
}
if (this.description != null && !this.description.equals(itemMetadata.getDescription())) {
return false;
}
if (this.deprecation == null && itemMetadata.getDeprecation() != null) {
return false;
}
return this.deprecation == null || this.deprecation.equals(itemMetadata.getDeprecation());
}
public MetadataItemCondition ofType(Class<?> dataType) {
return new MetadataItemCondition(this.itemType, this.name, dataType.getName(), this.sourceType,
this.sourceMethod, this.description, this.defaultValue, this.deprecation);
}
public MetadataItemCondition ofType(String dataType) {
return new MetadataItemCondition(this.itemType, this.name, dataType, this.sourceType, this.sourceMethod,
this.description, this.defaultValue, this.deprecation);
}
public MetadataItemCondition fromSource(Class<?> sourceType) {
return new MetadataItemCondition(this.itemType, this.name, this.type, sourceType, this.sourceMethod,
this.description, this.defaultValue, this.deprecation);
}
public MetadataItemCondition fromSourceMethod(String sourceMethod) {
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, sourceMethod,
this.description, this.defaultValue, this.deprecation);
}
public MetadataItemCondition withDescription(String description) {
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
description, this.defaultValue, this.deprecation);
}
public MetadataItemCondition withDefaultValue(Object defaultValue) {
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
this.description, defaultValue, this.deprecation);
}
public MetadataItemCondition withDeprecation() {
return withDeprecation(null, null, null, null);
}
public MetadataItemCondition withDeprecation(String reason, String replacement, String since) {
return withDeprecation(reason, replacement, since, null);
}
public MetadataItemCondition withDeprecation(String reason, String replacement, String since, String level) {
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
this.description, this.defaultValue, new ItemDeprecation(reason, replacement, since, level));
}
public MetadataItemCondition withNoDeprecation() {
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
this.description, this.defaultValue, null);
}
private ItemMetadata findItem(ConfigurationMetadata metadata, String name) {
List<ItemMetadata> candidates = metadata.getItems()
.stream()
.filter((item) -> item.isOfItemType(this.itemType) && name.equals(item.getName()))
.toList();
if (candidates.size() > 1) {
throw new IllegalStateException("More than one metadata item with name '" + name + "': " + candidates);
}
return (candidates.size() == 1) ? candidates.get(0) : null;
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free