View Javadoc
1 package net.sourceforge.pmd; 2 3 import java.util.Enumeration; 4 import java.util.Properties; 5 6 /*** 7 * 8 * @author Donald A. Leckie 9 * @since October 1, 2002 10 * @version $Revision: 1.7 $, $Date: 2003/06/25 13:01:59 $ 11 */ 12 public class RuleProperties { 13 14 private Properties m_properties = new Properties(); 15 16 // Constants 17 private static final String SEPARATOR = "&PS;"; 18 19 public boolean containsKey(String name) { 20 return m_properties.containsKey(name); 21 } 22 23 /*** 24 ****************************************************************************** 25 * 26 * Returns an enumeration of the property names in this properties table. 27 * 28 * @return An enumeration of the property names in this properties table. 29 */ 30 public Enumeration keys() { 31 return m_properties.keys(); 32 } 33 34 public int size() { 35 return m_properties.size(); 36 } 37 38 public String getValue(String name) { 39 name = (name == null) ? "" : name.trim(); 40 41 if (name.length() > 0) { 42 String property = m_properties.getProperty(name); 43 44 if (property != null) { 45 int index = property.indexOf(SEPARATOR); 46 47 return (index < 0) ? property : property.substring(0, index); 48 } 49 } 50 51 return ""; 52 } 53 54 public String getValueType(String name) { 55 name = (name == null) ? "" : name.trim(); 56 57 if (name.length() > 0) { 58 String property = m_properties.getProperty(name); 59 60 if (property != null) { 61 int index = property.indexOf(SEPARATOR) + SEPARATOR.length(); 62 63 if (index > 0) { 64 return property.substring(index); 65 } 66 } 67 } 68 69 return ""; 70 } 71 72 public boolean getBooleanValue(String name) { 73 return Boolean.getBoolean(getValue(name)); 74 } 75 76 public double getDoubleValue(String name) { 77 try { 78 return Double.parseDouble(getValue(name)); 79 } catch (NumberFormatException exception) { 80 return 0.0; 81 } 82 } 83 84 public int getIntegerValue(String name) { 85 try { 86 return Integer.parseInt(getValue(name)); 87 } catch (NumberFormatException exception) { 88 return 0; 89 } 90 } 91 92 public String getProperty(String name) { 93 return getValue(name); 94 } 95 96 public Object setProperty(String name, String value) { 97 setValue(name, value); 98 99 return null; 100 } 101 102 public void setValue(String name, String value) { 103 name = (name == null) ? "" : name.trim(); 104 105 if (name.length() > 0) { 106 if (value == null) { 107 value = ""; 108 } 109 110 String valueType = getValueType(name); 111 String property = value + SEPARATOR + valueType; 112 113 m_properties.setProperty(name, property); 114 } 115 } 116 117 public void setValueType(String name, String valueType) { 118 name = (name == null) ? "" : name.trim(); 119 120 if (name.length() > 0) { 121 if (valueType == null) { 122 valueType = ""; 123 } 124 125 String value = getValue(name); 126 String property = value + SEPARATOR + valueType; 127 128 m_properties.setProperty(name, property); 129 } 130 } 131 }

This page was automatically generated by Maven