Package jsyntaxpane.util
Class Configuration
- java.lang.Object
-
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Configuration.StringKeyMatcher
Utility class to hold data forgetKeys(java.util.regex.Pattern)
method.
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
COMMA_SEPARATOR
static java.lang.String[]
EMPTY_LIST
-
Constructor Summary
Constructors Constructor Description Configuration(java.lang.Class theClass)
Creates an empty ConfigurationConfiguration(java.lang.Class theClass, Configuration parent)
Creates a new COnfiguration that uses parent as its parent Configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 configurationjava.awt.Color
getColor(java.lang.String key, java.awt.Color Default)
return the Color that has the given key or the Defaultint
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 defaultValueboolean
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()
-
-
-
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 is replaced by class.SimpleNameclass_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 {@link 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 interfacejava.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 interfacejava.util.Map<java.lang.String,java.lang.String>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Map<java.lang.String,java.lang.String>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Map<java.lang.String,java.lang.String>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKey
in interfacejava.util.Map<java.lang.String,java.lang.String>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValue
in interfacejava.util.Map<java.lang.String,java.lang.String>
-
get
public java.lang.String get(java.lang.Object key)
- Specified by:
get
in interfacejava.util.Map<java.lang.String,java.lang.String>
-
remove
public java.lang.String remove(java.lang.Object key)
- Specified by:
remove
in interfacejava.util.Map<java.lang.String,java.lang.String>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map<java.lang.String,java.lang.String>
-
keySet
public java.util.Set<java.lang.String> keySet()
- Specified by:
keySet
in interfacejava.util.Map<java.lang.String,java.lang.String>
-
values
public java.util.Collection<java.lang.String> values()
- Specified by:
values
in interfacejava.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 interfacejava.util.Map<java.lang.String,java.lang.String>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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 thestringPropertyNames()
- Parameters:
pattern
-- Returns:
-
-