PropertiesFilterUtil.java

  1. /*
  2.  * #%L
  3.  * wcm.io
  4.  * %%
  5.  * Copyright (C) 2017 wcm.io
  6.  * %%
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *      http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  * #L%
  19.  */
  20. package io.wcm.caconfig.extensions.persistence.impl;

  21. import java.util.HashSet;
  22. import java.util.Map;
  23. import java.util.Set;

  24. import org.apache.sling.caconfig.management.ConfigurationManagementSettings;

  25. /**
  26.  * Filter internal properties from ConfigManager API output.
  27.  */
  28. final class PropertiesFilterUtil {

  29.   private PropertiesFilterUtil() {
  30.     // static methods only
  31.   }

  32.   public static void removeIgnoredProperties(Set<String> propertyNames, ConfigurationManagementSettings settings) {
  33.     Set<String> ignoredProperties = settings.getIgnoredPropertyNames(propertyNames);
  34.     propertyNames.removeAll(ignoredProperties);
  35.   }

  36.   public static void removeIgnoredProperties(Map<String, Object> properties, ConfigurationManagementSettings settings) {
  37.     Set<String> propertyNames = new HashSet<>(properties.keySet());
  38.     removeIgnoredProperties(propertyNames, settings);
  39.     properties.keySet().retainAll(propertyNames);
  40.   }

  41. }