Home / Class/ MetadataHintCondition Class — spring-boot Architecture

MetadataHintCondition Class — spring-boot Architecture

Architecture documentation for the MetadataHintCondition 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 229–315

	public static class MetadataHintCondition extends Condition<ConfigurationMetadata> {

		private final String name;

		private final List<ItemHintValueCondition> valueConditions;

		private final List<ItemHintProviderCondition> providerConditions;

		public MetadataHintCondition(String name) {
			this.name = name;
			this.valueConditions = Collections.emptyList();
			this.providerConditions = Collections.emptyList();
		}

		public MetadataHintCondition(String name, List<ItemHintValueCondition> valueConditions,
				List<ItemHintProviderCondition> providerConditions) {
			this.name = name;
			this.valueConditions = valueConditions;
			this.providerConditions = providerConditions;
			describedAs(createDescription());
		}

		private String createDescription() {
			StringBuilder description = new StringBuilder();
			description.append("a hints name '").append(this.name).append("'");
			if (!this.valueConditions.isEmpty()) {
				description.append(" with values:").append(this.valueConditions);
			}
			if (!this.providerConditions.isEmpty()) {
				description.append(" with providers:").append(this.providerConditions);
			}
			return description.toString();
		}

		@Override
		public boolean matches(ConfigurationMetadata metadata) {
			ItemHint itemHint = getFirstHintWithName(metadata, this.name);
			if (itemHint == null) {
				return false;
			}
			return matches(itemHint, this.valueConditions) && matches(itemHint, this.providerConditions);
		}

		private boolean matches(ItemHint itemHint, List<? extends Condition<ItemHint>> conditions) {
			for (Condition<ItemHint> condition : conditions) {
				if (!condition.matches(itemHint)) {
					return false;
				}
			}
			return true;
		}

		private ItemHint getFirstHintWithName(ConfigurationMetadata metadata, String name) {
			for (ItemHint hint : metadata.getHints()) {
				if (name.equals(hint.getName())) {
					return hint;
				}
			}
			return null;
		}

		public MetadataHintCondition withValue(int index, Object value, String description) {
			return new MetadataHintCondition(this.name,
					add(this.valueConditions, new ItemHintValueCondition(index, value, description)),
					this.providerConditions);
		}

		public MetadataHintCondition withProvider(String provider) {
			return withProvider(this.providerConditions.size(), provider, null);
		}

		public MetadataHintCondition withProvider(String provider, String key, Object value) {
			return withProvider(this.providerConditions.size(), provider, Collections.singletonMap(key, value));
		}

		public MetadataHintCondition withProvider(int index, String provider, Map<String, Object> parameters) {
			return new MetadataHintCondition(this.name, this.valueConditions,
					add(this.providerConditions, new ItemHintProviderCondition(index, provider, parameters)));
		}

		private <T> List<T> add(List<T> items, T item) {
			List<T> result = new ArrayList<>(items);
			result.add(item);
			return result;
		}

	}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free