Package de.srsoftware.localconfig
Class Configuration
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.TreeMap<String,String>
-
- de.srsoftware.localconfig.Configuration
-
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,String>,NavigableMap<String,String>,SortedMap<String,String>
public class Configuration extends TreeMap<String,String>
This class provides means to save program configuration- Author:
- Stephan Richter
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description Configuration(File f)Load configuration from fileConfiguration(Path filename)Load configuration from file
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcopy(Configuration source, String field)static Pathdir(String programName)returns the directory path, where config files should be stored.Filefile()static ConfigurationforApplication(String appName)BooleangetBool(String key)will evaluate 1 or "true" (ignoring case) as true, every other value as falseDoublegetDouble(String key)IntegergetInt(String key)booleangetOrAdd(String key, boolean defaultValue)doublegetOrAdd(String key, double defaultValue)intgetOrAdd(String key, int defaultValue)StringgetOrAdd(String key, String defaultValue)static AbstractMap.SimpleEntry<String,String>keyValue(String line)Stringput(String key, boolean value)Stringput(String key, Number value)Stringput(String key, String value)voidsave()voidsaveAs(File file)StringtoString()static Stringuncomment(String line)-
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, putAll, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, values
-
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove
-
-
-
-
Method Detail
-
copy
public void copy(Configuration source, String field)
-
dir
public static Path dir(String programName)
returns the directory path, where config files should be stored.- Parameters:
programName- the name of the program, for which the configuration is managed.- Returns:
-
file
public File file()
-
forApplication
public static Configuration forApplication(String appName) throws FileNotFoundException
- Throws:
FileNotFoundException
-
getOrAdd
public String getOrAdd(String key, String defaultValue) throws IOException
- Throws:
IOException
-
getOrAdd
public boolean getOrAdd(String key, boolean defaultValue) throws IOException
- Throws:
IOException
-
getOrAdd
public double getOrAdd(String key, double defaultValue) throws IOException
- Throws:
IOException
-
getOrAdd
public int getOrAdd(String key, int defaultValue) throws IOException
- Throws:
IOException
-
getBool
public Boolean getBool(String key)
will evaluate 1 or "true" (ignoring case) as true, every other value as false- Parameters:
key-- Returns:
-
keyValue
public static AbstractMap.SimpleEntry<String,String> keyValue(String line) throws UnexpectedException
- Throws:
UnexpectedException
-
save
public void save() throws IOException- Throws:
IOException
-
saveAs
public void saveAs(File file) throws IOException
- Throws:
IOException
-
toString
public String toString()
- Overrides:
toStringin classAbstractMap<String,String>
-
-