private static BigDecimal[] parseRange(String rangeString, int bigDecimalScale, MathContext mc) throws JSAPException {
if (rangeString.startsWith("[")) {
// expect a real range
if (!rangeString.endsWith("]")) { throw new JSAPException ("Range for selection has to be in format [start:step:stop]"); }
// parse the range
String[] fields = rangeString.substring(1, rangeString.length()-1).split(":");
// get the array
if (fields.length != 3) { throw new JSAPException ("Range for selection has to be in format [start:step:stop]"); }
BigDecimal[] tmp = new BigDecimal[] { (new BigDecimal(fields[0])).setScale(bigDecimalScale), (new BigDecimal(fields[1])).setScale(bigDecimalScale), (new BigDecimal(fields[2])).setScale(bigDecimalScale) };
// now check for the right stepping direction
if (tmp[2].subtract(tmp[0], mc).multiply(tmp[1], mc).compareTo(BigDecimal.ZERO) < 0) { throw new JSAPException ("Range for selection has to be in format [start:step:stop]"); }
// and change the order if necessary
if (tmp[0].compareTo(tmp[2]) > 0) {
BigDecimal swap = tmp[0];
tmp[0] = tmp[2];
tmp[1] = tmp[1].multiply(new BigDecimal("-1"), mc);