Class BaseConfiguration
- java.lang.Object
-
- org.apache.commons.configuration2.event.BaseEventSource
-
- org.apache.commons.configuration2.AbstractConfiguration
-
- org.apache.commons.configuration2.BaseConfiguration
-
- All Implemented Interfaces:
java.lang.Cloneable,Configuration,EventSource,ImmutableConfiguration,SynchronizerSupport
- Direct Known Subclasses:
PropertiesConfiguration,XMLPropertiesConfiguration
public class BaseConfiguration extends AbstractConfiguration implements java.lang.Cloneable
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.
-
-
Constructor Summary
Constructors Constructor Description BaseConfiguration()Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddPropertyDirect(java.lang.String key, java.lang.Object value)Adds a key/value pair to the map.protected voidclearInternal()Clears the whole configuration.protected voidclearPropertyDirect(java.lang.String key)Clear a property in the configuration.java.lang.Objectclone()Creates a copy of this object.protected booleancontainsKeyInternal(java.lang.String key)check if the configuration contains the keyprotected booleancontainsValueInternal(java.lang.Object value)Tests whether this configuration contains one or more matches to this value.protected java.util.Iterator<java.lang.String>getKeysInternal()Gets the list of the keys contained in the configuration repository.protected java.lang.ObjectgetPropertyInternal(java.lang.String key)Reads property from underlying map.protected booleanisEmptyInternal()Check if the configuration is emptyprotected intsizeInternal()Actually calculates the size of this configuration.-
Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, addPropertyInternal, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, contains, containsKey, containsValue, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeys, getKeysInternal, getKeysInternal, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setPropertyInternal, setSynchronizer, setThrowExceptionOnMissing, size, subset, unlock
-
Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
entrySet, forEach, getEnum, getEnum
-
-
-
-
Method Detail
-
addPropertyDirect
protected void addPropertyDirect(java.lang.String key, java.lang.Object value)Adds a key/value pair to the map. This routine does no magic morphing. It ensures the keylist is maintained- Specified by:
addPropertyDirectin classAbstractConfiguration- Parameters:
key- key to use for mappingvalue- object to store
-
clearInternal
protected void clearInternal()
Description copied from class:AbstractConfigurationClears the whole configuration. This method is called byclear()after some preparations have been made. This base implementation uses the iterator provided bygetKeys()to remove every single property. Subclasses should override this method if there is a more efficient way of clearing the configuration.- Overrides:
clearInternalin classAbstractConfiguration
-
clearPropertyDirect
protected void clearPropertyDirect(java.lang.String key)
Clear a property in the configuration.- Specified by:
clearPropertyDirectin classAbstractConfiguration- Parameters:
key- the key to remove along with corresponding value.
-
clone
public java.lang.Object clone()
Creates a copy of this object. This implementation will create a deep clone, i.e. the map that stores the properties is cloned, too. So changes performed at the copy won't affect the original and vice versa.- Overrides:
clonein classBaseEventSource- Returns:
- the copy
- Since:
- 1.3
-
containsKeyInternal
protected boolean containsKeyInternal(java.lang.String key)
check if the configuration contains the key- Specified by:
containsKeyInternalin classAbstractConfiguration- Parameters:
key- the configuration key- Returns:
trueif Configuration contain given key,falseotherwise.
-
containsValueInternal
protected boolean containsValueInternal(java.lang.Object value)
Tests whether this configuration contains one or more matches to this value. This operation stops at first match but may be more expensive than the containsKey method.- Specified by:
containsValueInternalin classAbstractConfiguration- Parameters:
value- the value in question- Returns:
trueif and only if some key maps to thevalueargument in this configuration as determined by theequalsmethod;falseotherwise.- Since:
- 2.11.0
-
getKeysInternal
protected java.util.Iterator<java.lang.String> getKeysInternal()
Gets the list of the keys contained in the configuration repository.- Specified by:
getKeysInternalin classAbstractConfiguration- Returns:
- An Iterator.
-
getPropertyInternal
protected java.lang.Object getPropertyInternal(java.lang.String key)
Reads property from underlying map.- Specified by:
getPropertyInternalin classAbstractConfiguration- Parameters:
key- key to use for mapping- Returns:
- object associated with the given configuration key.
-
isEmptyInternal
protected boolean isEmptyInternal()
Check if the configuration is empty- Specified by:
isEmptyInternalin classAbstractConfiguration- Returns:
trueif Configuration is empty,falseotherwise.
-
sizeInternal
protected int sizeInternal()
Actually calculates the size of this configuration. This method is called bysize()with a read lock held. The base implementation provided here calculates the size based on the iterator returned bygetKeys(). Sub classes which can determine the size in a more efficient way should override this method. This implementation obtains the size directly from the map used as data store. So this is a rather efficient implementation.- Overrides:
sizeInternalin classAbstractConfiguration- Returns:
- the size of this configuration (i.e. the number of keys).
-
-