org.apache.commons.configuration2.BaseConfiguration 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
/*
* 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.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.configuration2.ex.ConfigurationRuntimeException;
/**
* Basic configuration class. Stores the configuration data but does not
* provide any load or save functions. If you want to load your Configuration
* from a file use PropertiesConfiguration or XmlConfiguration.
*
* This class extends normal Java properties by adding the possibility
* to use the same key many times concatenating the value strings
* instead of overwriting them.
*
* @author Stefano Mazzocchi
* @author Jon S. Stevens
* @author Dave Bryson
* @author Geir Magnusson Jr.
* @author Leon Messerschmidt
* @author Kent Johnson
* @author Daniel Rall
* @author Ilkka Priha
* @author Jason van Zyl
* @author Martin Poeschl
* @author Henning P. Schmiedehausen
* @author Konstantin Shaposhnikov
* @version $Id: BaseConfiguration.java 1842194 2018-09-27 22:24:23Z ggregory $
*/
public class BaseConfiguration extends AbstractConfiguration implements Cloneable
{
/** stores the configuration key-value pairs */
private Map store = new LinkedHashMap<>();
/**
* Adds a key/value pair to the map. This routine does no magic morphing.
* It ensures the keylist is maintained
*
* @param key key to use for mapping
* @param value object to store
*/
@Override
protected void addPropertyDirect(final String key, final Object value)
{
final Object previousValue = getPropertyInternal(key);
if (previousValue == null)
{
store.put(key, value);
}
else if (previousValue instanceof List)
{
// safe to case because we have created the lists ourselves
@SuppressWarnings("unchecked")
final
List