Skip to content

Commit

Permalink
ConfigManager wraps commons-configuration classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenbach committed Aug 2, 2011
1 parent 3e7f96a commit 020243f
Show file tree
Hide file tree
Showing 7 changed files with 583 additions and 82 deletions.
17 changes: 0 additions & 17 deletions LICENSE.txt → LICENSE
@@ -1,20 +1,3 @@
PSL software
The copyright holder(s) for each source file is given within the particular file.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this software except in compliance with the License.
A copy of the License is included below. You may also 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.


Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
12 changes: 12 additions & 0 deletions NOTICE
@@ -0,0 +1,12 @@
PSL Software
Copyright 2011 University of Maryland

This product includes software developed by
the University of Maryland.

Apache Commons Configuration
Copyright 2001-2008 The Apache Software Foundation

This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).

321 changes: 313 additions & 8 deletions psl-core/src/main/java/edu/umd/cs/psl/config/ConfigBundle.java
@@ -1,6 +1,7 @@
/*
* This file is part of the PSL software.
* Copyright 2011 University of Maryland
* Copyright 2001-2008 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,18 +14,322 @@
* 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.
*
* The University of Maryland modified the file
* org/apache/commons/configuration/Configuration.java, from the
* commons-configuration distribution, version 1.6, to create this file.
*/
package edu.umd.cs.psl.config;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;

import org.apache.commons.configuration.ConversionException;

/**
* Encapsulates a set of configuration options organized by keys.
* Encapsulates a set of configuration properties organized by keys.
*/
public interface ConfigBundle {
public Boolean getBoolean(String key, Boolean defaultValue);

public Double getDouble(String key, Double defaultValue);

public Enum<?> getEnum(String key, Enum<?> defaultValue);

public String getString(String key, String defaultValue);
/**
* Return a ConfigBundle containing every key from the current
* ConfigBundle that starts with the specified prefix. The prefix is
* removed from the keys in the subset. For example, if the configuration
* contains the following properties:
*
* <pre>
* prefix.number = 1
* prefix.string = Apache
* prefixed.foo = bar
* prefix = Jakarta
* </pre>
*
* the ConfigBundle returned by <code>subset("prefix")</code> will contain
* the properties:
*
* <pre>
* number = 1
* string = Apache
* = Jakarta
* </pre>
*
* (The key for the value "Jakarta" is an empty string)
*
* @param prefix
* The prefix used to select the properties.
* @return a subset configuration bundle
*/
ConfigBundle subset(String prefix);

/**
* Get a boolean associated with the given configuration key. If the key
* doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated boolean.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Boolean.
*/
boolean getBoolean(String key, boolean defaultValue);

/**
* Get a {@link Boolean} associated with the given configuration key.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated boolean if key is found and has valid format,
* default value otherwise.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Boolean.
*/
Boolean getBoolean(String key, Boolean defaultValue);

/**
* Get a byte associated with the given configuration key. If the key
* doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated byte.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Byte.
*/
byte getByte(String key, byte defaultValue);

/**
* Get a {@link Byte} associated with the given configuration key.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated byte if key is found and has valid format, default
* value otherwise.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Byte.
*/
Byte getByte(String key, Byte defaultValue);

/**
* Get a double associated with the given configuration key. If the key
* doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated double.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Double.
*/
double getDouble(String key, double defaultValue);

/**
* Get a {@link Double} associated with the given configuration key.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated double if key is found and has valid format,
* default value otherwise.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Double.
*/
Double getDouble(String key, Double defaultValue);

/**
* Get a float associated with the given configuration key. If the key
* doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated float.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Float.
*/
float getFloat(String key, float defaultValue);

/**
* Get a {@link Float} associated with the given configuration key. If the
* key doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated float if key is found and has valid format,
* default value otherwise.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Float.
*/
Float getFloat(String key, Float defaultValue);

/**
* Get a int associated with the given configuration key. If the key doesn't
* map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated int.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Integer.
*/
int getInt(String key, int defaultValue);

/**
* Get an {@link Integer} associated with the given configuration key. If
* the key doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated int if key is found and has valid format, default
* value otherwise.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Integer.
*/
Integer getInteger(String key, Integer defaultValue);

/**
* Get a long associated with the given configuration key. If the key
* doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated long.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Long.
*/
long getLong(String key, long defaultValue);

/**
* Get a {@link Long} associated with the given configuration key. If the
* key doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated long if key is found and has valid format, default
* value otherwise.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Long.
*/
Long getLong(String key, Long defaultValue);

/**
* Get a short associated with the given configuration key.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated short.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Short.
*/
short getShort(String key, short defaultValue);

/**
* Get a {@link Short} associated with the given configuration key. If the
* key doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated short if key is found and has valid format,
* default value otherwise.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a Short.
*/
Short getShort(String key, Short defaultValue);

/**
* Get a {@link BigDecimal} associated with the given configuration key. If
* the key doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
*
* @return The associated BigDecimal if key is found and has valid format,
* default value otherwise.
*/
BigDecimal getBigDecimal(String key, BigDecimal defaultValue);

/**
* Get a {@link BigInteger} associated with the given configuration key. If
* the key doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
*
* @return The associated BigInteger if key is found and has valid format,
* default value otherwise.
*/
BigInteger getBigInteger(String key, BigInteger defaultValue);

/**
* Get a string associated with the given configuration key. If the key
* doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated string if key is found and has valid format,
* default value otherwise.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a String.
*/
String getString(String key, String defaultValue);

/**
* Get a List of strings associated with the given configuration key. If the
* key doesn't map to an existing object, the default value is returned.
*
* @param key
* The configuration key.
* @param defaultValue
* The default value.
* @return The associated List of strings.
*
* @throws ConversionException
* is thrown if the key maps to an object that is not a List.
*/
List<String> getList(String key, List<String> defaultValue);
}

0 comments on commit 020243f

Please sign in to comment.