use of net.sourceforge.processdash.data.MalformedValueException in project processdash by dtuma.
the class PercentageFunction method compileScript.
private static CompiledScript compileScript(String name) throws MalformedValueException {
int flagPos = name.indexOf(PERCENTAGE_FLAG);
if (flagPos <= 0)
throw new MalformedValueException("PercentageFunction: '" + name + "' does not contain '" + PERCENTAGE_FLAG + "'.");
String dataName = name.substring(flagPos + PERCENTAGE_FLAG.length());
String childPrefix = name.substring(0, flagPos);
String numeratorName = DataRepository.createDataName(childPrefix, dataName);
int slashPos = childPrefix.lastIndexOf('/');
if (slashPos == -1)
throw new MalformedValueException("PercentageFunction: '" + name + "' does not have a parent.");
String parentPrefix = name.substring(0, slashPos);
String denominatorName = DataRepository.createDataName(parentPrefix, dataName);
return Compiler.divisionExpr(numeratorName, denominatorName);
}
use of net.sourceforge.processdash.data.MalformedValueException in project processdash by dtuma.
the class DataRepository method putExpression.
public void putExpression(String name, String prefix, String expression) throws MalformedValueException {
try {
CompiledFunction f = new CompiledFunction(name, Compiler.compile(expression), this, prefix);
putValue(name, f, IS_NOT_DEFAULT_VAL);
} catch (CompilationException e) {
throw new MalformedValueException();
}
}
use of net.sourceforge.processdash.data.MalformedValueException in project processdash by dtuma.
the class ResultSet method get.
/** Perform a query and return a result set, using the old-style
mechanism. */
public static ResultSet get(DataRepository data, String[] conditions, String orderBy, String[] dataNames, String basePrefix, Comparator nodeComparator) {
// Construct a regular expression for searching the repository.
StringBuffer re = new StringBuffer("~(.*/)?");
if (conditions != null)
for (int c = 0; c < conditions.length; c++) re.append("{").append(conditions[c]).append("}");
if (orderBy == null)
orderBy = dataNames[0];
re.append(orderBy);
// Find data elements that match the regular expression.
if (basePrefix == null)
basePrefix = "";
SortedList list = SortedList.getInstance(data, re.toString(), basePrefix, FAKE_DATA_NAME, nodeComparator);
String[] prefixes = list.getNames();
// Create a result set to return
ResultSet result = new ResultSet(prefixes.length, dataNames.length);
// write the column headers into the result set.
result.setColName(0, null);
for (int i = 0; i < dataNames.length; i++) result.setColName(i + 1, dataNames[i]);
// get the data and fill the result set.
String prefix, dataName;
int baseLen = basePrefix.length(), tailLen = orderBy.length() + 1;
// remove / as well
if (baseLen > 0)
baseLen++;
String[] fixedUpNames = new String[dataNames.length];
for (int i = dataNames.length; i > 0; ) if (dataNames[--i].charAt(0) == '!')
fixedUpNames[i] = fixupName(dataNames[i]);
SaveableData value;
for (int p = 0; p < prefixes.length; p++) {
// get the next prefix
prefix = prefixes[p];
// remove the name of the orderBy data element, & the preceeding /
prefix = prefix.substring(0, prefix.length() - tailLen);
if (baseLen > prefix.length())
result.setRowName(p + 1, "");
else
result.setRowName(p + 1, prefix.substring(baseLen));
// look up the data for this row.
for (int d = 0; d < dataNames.length; d++) if (dataNames[d].startsWith("![(")) {
dataName = DataRepository.anonymousPrefix + "/" + prefix + "/" + fixedUpNames[d];
value = data.getSimpleValue(dataName);
if (value == null)
try {
value = ValueFactory.create(dataName, dataNames[d], data, prefix);
data.putValue(dataName, value);
} catch (MalformedValueException mve) {
}
result.setData(p + 1, d + 1, value == null ? null : value.getSimpleValue());
} else if (dataNames[d].startsWith("\"")) {
try {
result.setData(p + 1, d + 1, new StringData(dataNames[d]));
} catch (MalformedValueException mve) {
result.setData(p + 1, d + 1, null);
}
} else {
dataName = DataRepository.createDataName(prefix, dataNames[d]);
result.setData(p + 1, d + 1, data.getSimpleValue(dataName));
}
}
return result;
}
use of net.sourceforge.processdash.data.MalformedValueException in project processdash by dtuma.
the class TextMetricsFileImporter method parseValue.
private static Object parseValue(String value) {
SimpleData result;
// is it a tag?
if ("TAG".equalsIgnoreCase(value))
return TagData.getInstance();
// first, try to interpret the string as a number.
if ("0.0".equals(value))
return ImmutableDoubleData.READ_ONLY_ZERO;
if ("NaN".equals(value))
return ImmutableDoubleData.READ_ONLY_NAN;
if (DoubleData.P_INF_STR.equals(value) || DoubleData.N_INF_STR.equals(value))
return ImmutableDoubleData.DIVIDE_BY_ZERO;
if (value.length() > 0)
switch(value.charAt(0)) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
case '+':
case '.':
case ',':
try {
result = new DoubleData(value);
result.setEditable(false);
return result;
} catch (MalformedValueException mfe) {
}
}
// next, try to interpret the string as a date.
try {
result = DateData.create(value);
result.setEditable(false);
return result;
} catch (MalformedValueException mfe) {
}
// give up and interpret it as a plain string.
result = StringData.create(StringData.unescapeString(value));
result.setEditable(false);
return result;
}
use of net.sourceforge.processdash.data.MalformedValueException in project processdash by dtuma.
the class TimeInterpreter method setString.
public void setString(String s) throws MalformedValueException {
try {
Number n = FMT.parse(s);
value = new DoubleData(n.doubleValue());
} catch (Exception pe) {
throw new MalformedValueException();
}
}
Aggregations