diff -r 5410b6afc839 -r 245f1b88a3e6 java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java Tue Dec 31 17:35:33 2013 +0100 @@ -0,0 +1,76 @@ +/** + * SQL-DK + * Copyright © 2013 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package info.globalcode.sql.dk.configuration; + +import java.util.ArrayList; +import javax.xml.bind.annotation.XmlTransient; +import static info.globalcode.sql.dk.Functions.findByName; + +/** + *

List of configurables.

+ * + *

Can be backed by defaults – if value for given name is nof found in this instance, we will + * look + * into defaults. Methods also accept defaultValue parameter – is used if property is nof found even + * in default properties.

+ * + *

Typical use:

+ * + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class Properties extends ArrayList { + + private Properties defaults; + + @XmlTransient + public Properties getDefaults() { + return defaults; + } + + public void setDefaults(Properties defaults) { + this.defaults = defaults; + } + + private Property findProperty(String name) { + Property p = findByName(this, name); + if (p == null) { + p = findByName(defaults, name); + } + return p; + } + + public String getString(String name, String defaultValue) { + Property p = findProperty(name); + return p == null ? defaultValue : p.getValue(); + } + + public boolean getBoolean(String name, boolean defaultValue) { + Property p = findProperty(name); + return p == null ? defaultValue : Boolean.valueOf(p.getValue()); + } + + public int getInteger(String name, int defaultValue) { + Property p = findProperty(name); + return p == null ? defaultValue : Integer.valueOf(p.getValue()); + } +}