public void testIsNumeric() { Assert.IsTrue(StagingRange.isNumeric("0")); Assert.IsTrue(StagingRange.isNumeric("1")); Assert.IsTrue(StagingRange.isNumeric("-1")); Assert.IsTrue(StagingRange.isNumeric("1.1")); Assert.IsFalse(StagingRange.isNumeric(null)); Assert.IsFalse(StagingRange.isNumeric("")); Assert.IsFalse(StagingRange.isNumeric("1.1.1")); Assert.IsFalse(StagingRange.isNumeric("NAN")); }
// Parses a string in having lists of ranges into a List of Range objects // @param values String representing sets value ranges // @return a parsed list of string Range objects public static List <Range> splitValues(String values) { List <Range> convertedRanges = new List <Range>(); if (values != null) { // if the value of the string is "*", then consider it as matching anything if (values == "*") { convertedRanges.Add(_MATCH_ALL_ENDPOINT); } else { // split the string; the "9999" makes sure to not discard empty strings String[] ranges = values.Split(",".ToCharArray(), 9999); foreach (String range in ranges) { // Not sure if this is the best way to handle this, but I ran into a problem when I converted the CS data. One of the tables had // a value of "N0(mol-)". This fails since it considers it a range and we require our ranges to have the same size on both sides. // The only thing I can think of is for cases like this, assume it is not a range and use the whole string as a non-range value. // The problem is that if something is entered incorrectly and was supposed to be a range, we will not process it correctly. We // may need to revisit this issue later. String[] parts = range.Split("-".ToCharArray()); if (parts.Length == 2) { String low = parts[0].Trim(); String high = parts[1].Trim(); // check if both sides of the range are numeric values; if so the length does not have to match bool isNumericRange = StagingRange.isNumeric(low) && StagingRange.isNumeric(high); // if same length, a numeric range, or one of the parts is a context variable, use the low and high as range. Otherwise consier // a single value (i.e. low = high) if (low.Length == high.Length || isNumericRange || DecisionEngineFuncs.isReferenceVariable(low) || DecisionEngineFuncs.isReferenceVariable(high)) { convertedRanges.Add(new StagingRange(low, high)); } else { convertedRanges.Add(new StagingRange(range.Trim(), range.Trim())); } } else { convertedRanges.Add(new StagingRange(range.Trim(), range.Trim())); } } } } return(convertedRanges); }