lcsim/src/org/lcsim/conditions
diff -u -r1.2 -r1.3
--- ConditionsSet.java 23 May 2006 17:30:32 -0000 1.2
+++ ConditionsSet.java 27 Sep 2006 18:11:25 -0000 1.3
@@ -5,12 +5,14 @@
/**
*
* @author Tony Johnson
+ * $Id: ConditionsSet.java,v 1.3 2006/09/27 18:11:25 ngraf Exp $
*/
public interface ConditionsSet extends Conditions
{
double getDouble(String key) throws IllegalArgumentException;
double getDouble(String key, double defValue);
-
+ double[] getDoubleArray(String key) throws IllegalArgumentException;
+
int getInt(String key) throws IllegalArgumentException;
int getInt(String key, int defValue);
lcsim/src/org/lcsim/conditions
diff -u -r1.3 -r1.4
--- ConditionsSetImplementation.java 24 May 2006 19:21:49 -0000 1.3
+++ ConditionsSetImplementation.java 27 Sep 2006 18:11:25 -0000 1.4
@@ -2,12 +2,16 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
import java.util.Set;
+import java.util.StringTokenizer;
/**
*
* @author Tony Johnson
+ * $Id: ConditionsSetImplementation.java,v 1.4 2006/09/27 18:11:25 ngraf Exp $
*/
class ConditionsSetImplementation extends ConditionsImplementation implements ConditionsSet
{
@@ -51,6 +55,13 @@
if (value == null) return defaultValue;
return parseDouble(value,name);
}
+
+ public double[] getDoubleArray(String name)
+ {
+ String value = props.getProperty(name);
+ if (value == null) throw new IllegalArgumentException("Missing value for "+name);
+ return parseDoubleArray(value,name);
+ }
private int parseInt(String value, String name)
{
try
@@ -59,7 +70,7 @@
}
catch (NumberFormatException e)
{
- throw new RuntimeException("Error reading condiditions: Illegal value "+value+" for "+name);
+ throw new RuntimeException("Error reading conditions: Illegal value "+value+" for "+name);
}
}
private double parseDouble(String value, String name)
@@ -70,9 +81,34 @@
}
catch (NumberFormatException e)
{
- throw new RuntimeException("Error reading condiditions: Illegal value "+value+" for "+name);
+ throw new RuntimeException("Error reading conditions: Illegal value "+value+" for "+name);
}
}
+ private double[] parseDoubleArray(String value, String name)
+ {
+ List<Double> doubles = new ArrayList<Double>();
+ StringTokenizer st = new StringTokenizer(value,",");
+ while(st.hasMoreTokens())
+ {
+ String doubleValue = st.nextToken();
+ try
+ {
+ doubles.add( Double.parseDouble(doubleValue) );
+ }
+ catch (NumberFormatException e)
+ {
+ throw new RuntimeException("Error reading conditions: Illegal value "+value+" for "+name);
+ }
+ }
+ // should be an easier way to do this...
+ double[] returnDoubles = new double[doubles.size()];
+ int i=0;
+ for(Double d : doubles)
+ {
+ returnDoubles[i++] = d;
+ }
+ return returnDoubles;
+ }
public String getString(String name)
{
String value = props.getProperty(name);
@@ -102,7 +138,7 @@
{
if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)) return true;
if ("false".equalsIgnoreCase(value) || "no".equalsIgnoreCase(value)) return false;
- throw new RuntimeException("Error reading condiditions: Illegal value "+value+" for "+name);
+ throw new RuntimeException("Error reading conditions: Illegal value "+value+" for "+name);
}
public Set keySet()