org.artoflife.util
Class Configuration

java.lang.Object
  |
  +--org.artoflife.util.Configuration

public final class Configuration
extends java.lang.Object

Allows access to typed configuration properties. Properties are defined:

  1. in custom properties if set with loadConfiguration(java.lang.String)
  2. in default.properties resource
  3. in System properties

A custom resource name can be specified with loadConfiguration(java.lang.String) although the default "configuration.properties" resource is always loaded from the classpath if it can be found.

This could be replaced with the config stuff in Jakarta Avalon if it gets unwieldy in real life.

Author:
Steve Meyfroidt

Method Summary
 char getChar(java.lang.String key, char defaultValue)
           
 java.lang.Class getClass(java.lang.String key, java.lang.Class defaultValue)
           
 java.util.List getClasses(java.lang.String keyPrefix)
          Of form some.prefix.0=foo, some.prefix.1=bar.
 java.util.List getDoubles(java.lang.String keyPrefix)
          Of form some.prefix.0=foo, some.prefix.1=bar.
 float getFloat(java.lang.String key, float defaultValue)
           
static Configuration getInstance()
          Singleton.
 java.util.SortedMap getInstancesProbabilities(java.lang.String propertyPrefix)
          Create a sorted map of probability (Float) against an instance of some class: 0.1 an instance with 10% probability 0.2 a different instance with 10% probability 1.0 an instance with 80% probability The implementation ensures that the final entry always has a probability of exactly 1.0.
 int getInt(java.lang.String key, int defaultValue)
           
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
           
 java.util.List getStrings(java.lang.String keyPrefix)
          Of form some.prefix.0=foo, some.prefix.1=bar.
 void loadConfiguration(java.lang.String resourceName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Configuration getInstance()
Singleton.


loadConfiguration

public void loadConfiguration(java.lang.String resourceName)
                       throws java.io.IOException
java.io.IOException

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)

getChar

public char getChar(java.lang.String key,
                    char defaultValue)

getClass

public java.lang.Class getClass(java.lang.String key,
                                java.lang.Class defaultValue)

getInt

public int getInt(java.lang.String key,
                  int defaultValue)

getFloat

public float getFloat(java.lang.String key,
                      float defaultValue)

getStrings

public java.util.List getStrings(java.lang.String keyPrefix)
Of form some.prefix.0=foo, some.prefix.1=bar.

Returns:
list of Strings or empty list

getClasses

public java.util.List getClasses(java.lang.String keyPrefix)
Of form some.prefix.0=foo, some.prefix.1=bar.

Returns:
list of Classes or empty list

getDoubles

public java.util.List getDoubles(java.lang.String keyPrefix)
Of form some.prefix.0=foo, some.prefix.1=bar.

Returns:
list of Doubles or empty list

getInstancesProbabilities

public java.util.SortedMap getInstancesProbabilities(java.lang.String propertyPrefix)
Create a sorted map of probability (Float) against an instance of some class:
0.1
an instance with 10% probability
0.2
a different instance with 10% probability
1.0
an instance with 80% probability
The implementation ensures that the final entry always has a probability of exactly 1.0.

Load from configuration properties: [prefix].class.0 and optionally [prefix].probability.0


artoflife pre0.1.0-dev

Copyright © 2002 the Art Of Life team. All Rights Reserved.