private void removeComponentDefaultProperties()

in src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigurationSerializerWebConsolePlugin.java [361:389]


    private void removeComponentDefaultProperties(
            final Map<String, Set<ComponentDescriptionDTO>> allComponentDescriptions,
            final String pidReferencedFromComponentDescription,
            final Dictionary<String, Object> properties,
            final Dictionary<String, Object> mergedProperties) {
        Set<ComponentDescriptionDTO> componentDescriptions =
                allComponentDescriptions.get(pidReferencedFromComponentDescription);

        final Enumeration<String> e = properties.keys();
        while (e.hasMoreElements()) {
            final String key = e.nextElement();
            final Object newValue = properties.get(key);
            if (componentDescriptions != null) {
                // check all bound component descriptions
                Set<Object> defaultValues = componentDescriptions.stream()
                        .map(dto -> dto.properties.get(key))
                        .filter(Objects::nonNull)
                        .collect(Collectors.toSet());
                if (defaultValues.size() != 1) {
                    // if different components have different values for the same key, we cannot remove it
                    continue;
                }
                Object defaultValue = defaultValues.iterator().next();
                if (ConfigUtil.isSameValue(newValue, defaultValue) && mergedProperties.get(key) == null) {
                    properties.remove(key);
                }
            }
        }
    }