jsyntaxpane.util
Class Configuration

java.lang.Object
  extended by jsyntaxpane.util.Configuration
All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.String>

public class Configuration
extends java.lang.Object
implements java.util.Map<java.lang.String,java.lang.String>

Wrapper around the Properties class with supprt for Heirarchical confogurations and more functionality. Except for the getXXXX methods, all other Map Interface methods operate on the current (non-parent) collection and do NOT touch the parent.

Author:
Ayman Al-Sairafi

Nested Class Summary
static class Configuration.StringKeyMatcher
          Utility class to hold data for getKeys method.
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
static java.util.regex.Pattern COMMA_SEPARATOR
           
static java.lang.String[] EMPTY_LIST
           
 
Constructor Summary
Configuration(java.lang.Class<?> theClass)
          Creates an empty Configuration
Configuration(java.lang.Class<?> theClass, Configuration parent)
          Creates a new COnfiguration that uses parent as its parent Configuration.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
           
 java.lang.String get(java.lang.Object key)
           
 boolean getBoolean(java.lang.String key, boolean Default)
          Returns a boolean from the configuration
 java.awt.Color getColor(java.lang.String key, java.awt.Color Default)
          return the Color that has the given key or the Default
 int getInteger(java.lang.String key, int Default)
          Gets an integer from the properties.
 java.util.Set<Configuration.StringKeyMatcher> getKeys(java.util.regex.Pattern pattern)
          Obtain a set of all keys (and parent's keys) that match the given pattern.
 java.lang.String[] getPropertyList(java.lang.String key)
          Returns a String[] of the comma separated items in the value.
 java.lang.String getString(java.lang.String key)
          Get a string from this object or one of its parents.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Returns a non-null value either by traversing the current and parent(s) map, or returning the defaultValue
 boolean isEmpty()
           
 java.util.Set<java.lang.String> keySet()
           
 java.lang.String put(java.lang.String key, java.lang.String value)
           
 void putAll(java.util.Map config)
           
 java.lang.String remove(java.lang.Object key)
           
 int size()
           
 java.util.Set<java.lang.String> stringPropertyNames()
          Returns ALL property names from this Configuration's parents and this Configuration.
 java.lang.String toString()
           
 java.util.Collection<java.lang.String> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

EMPTY_LIST

public static final java.lang.String[] EMPTY_LIST

COMMA_SEPARATOR

public static final java.util.regex.Pattern COMMA_SEPARATOR
Constructor Detail

Configuration

public Configuration(java.lang.Class<?> theClass,
                     Configuration parent)
Creates a new COnfiguration that uses parent as its parent Configuration.

Parameters:
theClass -
parent -

Configuration

public Configuration(java.lang.Class<?> theClass)
Creates an empty Configuration

Parameters:
theClass -
Method Detail

getString

public java.lang.String getString(java.lang.String key)
Get a string from this object or one of its parents. If nothing is found, null is returned. If the Regex ${key} is found, then it is replaced by the value of that key within this (or parent's) map. Special COnstructs in ${}:
  • class_path will be replaced by the name of the Configuration (usually ClassName) with "." replaced by "/", and then converted to all lowercase
  • class_simpleName
  • is replaced by class.SimpleName

    Parameters:
    key -
    Returns:

    getString

    public java.lang.String getString(java.lang.String key,
                                      java.lang.String defaultValue)
    Returns a non-null value either by traversing the current and parent(s) map, or returning the defaultValue

    Parameters:
    key -
    defaultValue -
    Returns:
    Throws:
    java.lang.NullPointerException - if defaultValue is null

    getInteger

    public int getInteger(java.lang.String key,
                          int Default)
    Gets an integer from the properties. If number cannot be found or if it cannot be decoded, the default is returned The integer is decoded using Integer.decode(String)

    Parameters:
    key -
    Default -
    Returns:

    getPropertyList

    public java.lang.String[] getPropertyList(java.lang.String key)
    Returns a String[] of the comma separated items in the value. Does NOT return null. If the key is not found, then an empty string array is returned. So the return of this method can always be used directly in a foreach loop

    Parameters:
    key -
    Returns:
    non-null String[]

    getBoolean

    public boolean getBoolean(java.lang.String key,
                              boolean Default)
    Returns a boolean from the configuration

    Parameters:
    key -
    Default -
    Returns:

    getColor

    public java.awt.Color getColor(java.lang.String key,
                                   java.awt.Color Default)
    return the Color that has the given key or the Default

    Parameters:
    key -
    Default -
    Returns:

    putAll

    public void putAll(java.util.Map config)
    Specified by:
    putAll in interface java.util.Map<java.lang.String,java.lang.String>

    stringPropertyNames

    public java.util.Set<java.lang.String> stringPropertyNames()
    Returns ALL property names from this Configuration's parents and this Configuration. As usual, parents are added first so they are overriden by children.

    Returns:
    Set of all String keys in this and parents

    put

    public java.lang.String put(java.lang.String key,
                                java.lang.String value)
    Specified by:
    put in interface java.util.Map<java.lang.String,java.lang.String>

    size

    public int size()
    Specified by:
    size in interface java.util.Map<java.lang.String,java.lang.String>

    isEmpty

    public boolean isEmpty()
    Specified by:
    isEmpty in interface java.util.Map<java.lang.String,java.lang.String>

    containsKey

    public boolean containsKey(java.lang.Object key)
    Specified by:
    containsKey in interface java.util.Map<java.lang.String,java.lang.String>

    containsValue

    public boolean containsValue(java.lang.Object value)
    Specified by:
    containsValue in interface java.util.Map<java.lang.String,java.lang.String>

    get

    public java.lang.String get(java.lang.Object key)
    Specified by:
    get in interface java.util.Map<java.lang.String,java.lang.String>

    remove

    public java.lang.String remove(java.lang.Object key)
    Specified by:
    remove in interface java.util.Map<java.lang.String,java.lang.String>

    clear

    public void clear()
    Specified by:
    clear in interface java.util.Map<java.lang.String,java.lang.String>

    keySet

    public java.util.Set<java.lang.String> keySet()
    Specified by:
    keySet in interface java.util.Map<java.lang.String,java.lang.String>

    values

    public java.util.Collection<java.lang.String> values()
    Specified by:
    values in interface java.util.Map<java.lang.String,java.lang.String>

    entrySet

    public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
    Specified by:
    entrySet in interface java.util.Map<java.lang.String,java.lang.String>

    toString

    public java.lang.String toString()
    Overrides:
    toString in class java.lang.Object

    getKeys

    public java.util.Set<Configuration.StringKeyMatcher> getKeys(java.util.regex.Pattern pattern)
    Obtain a set of all keys (and parent's keys) that match the given pattern. If no keys match, then an empty set is returned. Use this instead of the stringPropertyNames

    Parameters:
    pattern -
    Returns: