    001    package calhoun.util;
    002
    003    import java.util.Properties;
    004
    005    import org.apache.commons.lang.StringUtils;
    006
    007    public class TypedProperties extends Properties {
    008            private static final long serialVersionUID = 8275327757663063251L;
    009
    010            public TypedProperties() {
    011            }
    012
    013            public TypedProperties(Properties props) {
    014                    super(props);
    015            }
    016
    017            public int getIntProperty(String name, int defValue) {
    018                    String val = getProperty(name);
    019                    return (val == null) ? defValue : Integer.parseInt(val);
    020            }
    021
    022            public double getDoubleProperty(String name, double defValue) {
    023                    String val = getProperty(name);
    024                    return (val == null) ? defValue : Double.parseDouble(val);
    025            }
    026
    027            public double[] getDoubleArrayProperty(String name, double[] defValue) {
    028                    String val = getProperty(name);
    029                    if(val == null) {
    030                            return defValue;
    031                    }
    032                    String[] vals = StringUtils.split(val, ',');
    033                    double[] ret = new double[vals.length];
    034                    for(int i = 0; i<vals.length; ++i) {
    035                            ret[i] = Double.parseDouble(vals[i]);
    036                    }
    037                    return ret;
    038            }
    039
    040            public int[] getIntArrayProperty(String name, int[] defValue) {
    041                    String val = getProperty(name);
    042                    if(val == null) {
    043                            return defValue;
    044                    }
    045                    String[] vals = val.split(",");
    046                    int[] ret = new int[vals.length];
    047                    for(int i = 0; i<vals.length; ++i) {
    048                            ret[i] = Integer.parseInt(vals[i]);
    049                    }
    050                    return ret;
    051            }
    052
    053            public short[] getShortArrayProperty(String name, short[] defValue) {
    054                    String val = getProperty(name);
    055                    if(val == null) {
    056                            return defValue;
    057                    }
    058                    String[] vals = val.split(",");
    059                    short[] ret = new short[vals.length];
    060                    for(int i = 0; i<vals.length; ++i) {
    061                            ret[i] = Short.parseShort(vals[i]);
    062                    }
    063                    return ret;
    064            }
    065
    066            public boolean  getBooleanProperty(String name, boolean defValue) {
    067                    String val = getProperty(name);
    068                    return (val == null) ? defValue : Boolean.parseBoolean(val);
    069            }
    070
    071    }