Methods Summary |
---|
public java.lang.String | get(java.lang.String name, java.lang.String dflt)Return a string property.
return props.getProperty(name,dflt);
|
public int | get(java.lang.String name, int dflt)Return an int property.
If the property contain ":", e.g. "10:100:5", it is interpreted
as array of ints. It is extracted once, on first call
to get() it, and a by-round-value is returned.
// use value by round if already parsed
int vals[] = (int[]) valByRound.get(name);
if (vals != null) {
return vals[roundNumber % vals.length];
}
// done if not by round
String sval = props.getProperty(name,""+dflt);
if (sval.indexOf(":")<0) {
return Integer.parseInt(sval);
}
// first time this prop is extracted by round
int k = sval.indexOf(":");
String colName = sval.substring(0,k);
sval = sval.substring(k+1);
colForValByRound.put(name,colName);
vals = propToIntArray(sval);
valByRound.put(name,vals);
return vals[roundNumber % vals.length];
|
public boolean | get(java.lang.String name, boolean dflt)Return a boolean property.
If the property contain ":", e.g. "true.true.false", it is interpreted
as array of boleans. It is extracted once, on first call
to get() it, and a by-round-value is returned.
// use value by round if already parsed
boolean vals[] = (boolean[]) valByRound.get(name);
if (vals != null) {
return vals[roundNumber % vals.length];
}
// done if not by round
String sval = props.getProperty(name,""+dflt);
if (sval.indexOf(":")<0) {
return Boolean.valueOf(sval).booleanValue();
}
// first time this prop is extracted by round
int k = sval.indexOf(":");
String colName = sval.substring(0,k);
sval = sval.substring(k+1);
colForValByRound.put(name,colName);
vals = propToBooleanArray(sval);
valByRound.put(name,vals);
return vals[roundNumber % vals.length];
|
public java.lang.String | getAlgorithmText()
return algorithmText;
|
public java.lang.String | getColsNamesForValsByRound()
if (colForValByRound.size()==0) {
return "";
}
StringBuffer sb = new StringBuffer();
for (Iterator it = colForValByRound.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
String colName = (String) colForValByRound.get(name);
sb.append(" ").append(colName);
}
return sb.toString();
|
public java.lang.String | getColsValuesForValsByRound(int roundNum)
if (colForValByRound.size()==0) {
return "";
}
StringBuffer sb = new StringBuffer();
for (Iterator it = colForValByRound.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
String colName = (String) colForValByRound.get(name);
String template = " "+colName;
if (roundNum<0) {
// just append blanks
sb.append(Format.formatPaddLeft("-",template));
} else {
// append actual values, for that round
Object a = valByRound.get(name);
if (a instanceof int[]) {
int ai[] = (int[]) a;
int n = roundNum % ai.length;
sb.append(Format.format(ai[n],template));
} else {
boolean ab[] = (boolean[]) a;
int n = roundNum % ab.length;
sb.append(Format.formatPaddLeft(""+ab[n],template));
}
}
}
return sb.toString();
|
public int | getRoundNumber()
return roundNumber;
|
public int | newRound()Increment the round number, for config values that are extracted by round number.
roundNumber++;
StringBuffer sb = new StringBuffer("--> Round ").append(roundNumber-1).append("-->").append(roundNumber);
// log changes in values
if (valByRound.size()>0) {
sb.append(": ");
for (Iterator iter = valByRound.keySet().iterator(); iter.hasNext();) {
String name = (String) iter.next();
Object a = valByRound.get(name);
if (a instanceof int[]) {
int ai[] = (int[]) a;
int n1 = (roundNumber-1)%ai.length;
int n2 = roundNumber%ai.length;
sb.append(" ").append(name).append(":").append(ai[n1]).append("-->").append(ai[n2]);
} else {
boolean ab[] = (boolean[]) a;
int n1 = (roundNumber-1)%ab.length;
int n2 = roundNumber%ab.length;
sb.append(" ").append(name).append(":").append(ab[n1]).append("-->").append(ab[n2]);
}
}
}
System.out.println();
System.out.println(sb.toString());
System.out.println();
return roundNumber;
|
private void | printProps()
System.out.println("------------> config properties:");
for (Iterator it = props.keySet().iterator(); it.hasNext();) {
String propName = (String) it.next();
System.out.println(propName + " = " + props.getProperty(propName));
}
System.out.println("-------------------------------");
|
private boolean[] | propToBooleanArray(java.lang.String s)
if (s.indexOf(":")<0) {
return new boolean [] { Boolean.valueOf(s).booleanValue() };
}
ArrayList a = new ArrayList();
StringTokenizer st = new StringTokenizer(s,":");
while (st.hasMoreTokens()) {
String t = st.nextToken();
a.add(new Boolean(t));
}
boolean res[] = new boolean[a.size()];
for (int i=0; i<a.size(); i++) {
res[i] = ((Boolean) a.get(i)).booleanValue();
}
return res;
|
private int[] | propToIntArray(java.lang.String s)
if (s.indexOf(":")<0) {
return new int [] { Integer.parseInt(s) };
}
ArrayList a = new ArrayList();
StringTokenizer st = new StringTokenizer(s,":");
while (st.hasMoreTokens()) {
String t = st.nextToken();
a.add(new Integer(t));
}
int res[] = new int[a.size()];
for (int i=0; i<a.size(); i++) {
res[i] = ((Integer) a.get(i)).intValue();
}
return res;
|
public void | set(java.lang.String name, java.lang.String value)Set a property.
Note: once a multiple values property is set, it can no longer be modified.
if (valByRound.get(name) != null) {
throw new Exception("Cannot modify a multi value property!");
}
props.setProperty(name,value);
|