java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java
branchv_0
changeset 105 39d8b427e20f
parent 104 245f1b88a3e6
child 106 e9c3583580c8
equal deleted inserted replaced
104:245f1b88a3e6 105:39d8b427e20f
    18 package info.globalcode.sql.dk.configuration;
    18 package info.globalcode.sql.dk.configuration;
    19 
    19 
    20 import java.util.ArrayList;
    20 import java.util.ArrayList;
    21 import javax.xml.bind.annotation.XmlTransient;
    21 import javax.xml.bind.annotation.XmlTransient;
    22 import static info.globalcode.sql.dk.Functions.findByName;
    22 import static info.globalcode.sql.dk.Functions.findByName;
       
    23 import java.util.Collections;
    23 
    24 
    24 /**
    25 /**
    25  * <p>List of configurables.</p>
    26  * <p>List of configurables.</p>
    26  *
    27  *
    27  * <p>Can be backed by defaults – if value for given name is nof found in this instance, we will
    28  * <p>Can be backed by defaults – if value for given name is nof found in this instance, we will
    36  * <li>defaultValue – hardcoded default</li>
    37  * <li>defaultValue – hardcoded default</li>
    37  * </ul>
    38  * </ul>
    38  *
    39  *
    39  * @author Ing. František Kučera (frantovo.cz)
    40  * @author Ing. František Kučera (frantovo.cz)
    40  */
    41  */
    41 public class Properties extends ArrayList<Property> {
    42 public class Properties extends ArrayList<Property> implements Cloneable {
    42 
    43 
    43 	private Properties defaults;
    44 	private Properties defaults;
       
    45 
       
    46 	public Properties() {
       
    47 	}
       
    48 
       
    49 	public Properties(int initialCapacity) {
       
    50 		super(initialCapacity);
       
    51 	}
    44 
    52 
    45 	@XmlTransient
    53 	@XmlTransient
    46 	public Properties getDefaults() {
    54 	public Properties getDefaults() {
    47 		return defaults;
    55 		return defaults;
    48 	}
    56 	}
    71 
    79 
    72 	public int getInteger(String name, int defaultValue) {
    80 	public int getInteger(String name, int defaultValue) {
    73 		Property p = findProperty(name);
    81 		Property p = findProperty(name);
    74 		return p == null ? defaultValue : Integer.valueOf(p.getValue());
    82 		return p == null ? defaultValue : Integer.valueOf(p.getValue());
    75 	}
    83 	}
       
    84 
       
    85 	@Override
       
    86 	public Properties clone() {
       
    87 		Properties clone = new Properties(size());
       
    88 		Collections.copy(clone, this);
       
    89 		return clone;
       
    90 	}
    76 }
    91 }