org.apache.commons.configuration2.AbstractYAMLBasedConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-configuration2 Show documentation
Show all versions of commons-configuration2 Show documentation
Tools to assist in the reading of configuration/preferences files in
various formats
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.configuration2;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.io.ConfigurationLogger;
import org.apache.commons.configuration2.tree.ImmutableNode;
/**
*
* A base class for configuration implementations based on YAML structures.
*
*
* This base class offers functionality related to YAML-like data structures based on maps. Such a map has strings as
* keys and arbitrary objects as values. The class offers methods to transform such a map into a hierarchy of
* {@link ImmutableNode} objects and vice versa.
*
*
* @since 2.2
*/
public class AbstractYAMLBasedConfiguration extends BaseHierarchicalConfiguration {
/**
* Adds a key value pair to a map, taking list structures into account. If a key is added which is already present in
* the map, this method ensures that a list is created.
*
* @param map the map
* @param key the key
* @param value the value
*/
private static void addEntry(final Map map, final String key, final Object value) {
final Object oldValue = map.get(key);
if (oldValue == null) {
map.put(key, value);
} else if (oldValue instanceof Collection) {
// safe case because the collection was created by ourselves
@SuppressWarnings("unchecked")
final Collection