001: package org.acm.seguin.pmd;
002:
003: import org.acm.seguin.pmd.swingui.Constants;
004:
005: import java.util.Enumeration;
006: import java.util.Properties;
007:
008: /**
009: *
010: * @author Donald A. Leckie
011: * @since October 1, 2002
012: * @version $Revision: 1.2 $, $Date: 2003/09/11 15:58:54 $
013: */
014: public class RuleProperties implements Constants {
015: private Properties properties = new Properties();
016:
017: // Constants
018: private static final String SEPARATOR = "&PS;";
019:
020: public boolean containsKey(String name) {
021: return properties.containsKey(name);
022: }
023:
024: public Enumeration keys() {
025: return properties.keys();
026: }
027:
028: public int size() {
029: return properties.size();
030: }
031:
032: public String getValue(String name) {
033: String property = properties.getProperty(name);
034: if (property == null) {
035: return null;
036: }
037: int index = property.indexOf(SEPARATOR);
038: if (index == -1) {
039: return property;
040: }
041: return property.substring(0, index);
042: }
043:
044: public String getValueType(String name) {
045: if (name.length() > 0) {
046: String property = properties.getProperty(name);
047: if (property != null) {
048: int index = property.indexOf(SEPARATOR)
049: + SEPARATOR.length();
050: if (index > 0) {
051: return property.substring(index);
052: }
053: }
054: }
055: return "";
056: }
057:
058: public boolean getBooleanValue(String name) {
059: return Boolean.valueOf(getValue(name)).booleanValue();
060: }
061:
062: public double getDoubleValue(String name) {
063: try {
064: return Double.parseDouble(getValue(name));
065: } catch (NumberFormatException exception) {
066: return 0.0;
067: }
068: }
069:
070: public int getIntegerValue(String name) {
071: try {
072: return Integer.parseInt(getValue(name));
073: } catch (NumberFormatException exception) {
074: return 0;
075: }
076: }
077:
078: public String getProperty(String name) {
079: return getValue(name);
080: }
081:
082: public void setValue(String name, String value) {
083: String valueType = getValueType(name);
084: String property = value + SEPARATOR + valueType;
085: properties.setProperty(name, property);
086: }
087:
088: public void setValueType(String name, String valueType) {
089: name = (name == null) ? "" : name.trim();
090:
091: if (name.length() > 0) {
092: if (valueType == null) {
093: valueType = "";
094: }
095:
096: String value = getValue(name);
097: String property = value + SEPARATOR + valueType;
098:
099: properties.setProperty(name, property);
100: }
101: }
102: }
|