Hi. > > In MathUtils there exists the method: > > public static boolean checkOrder(double[] val, OrderDirection dir, > boolean strict, boolean abort) { > ...code omitted... > } > > > I would like to replace it with the method: > > public static boolean checkOrder(Comparable[] val, OrderDirection dir, > boolean strict, boolean abort ){ > Comparable previous = val[0]; > boolean ok = true; > int max = val.length; > int comp; > for (int i = 1; i < max; i++) { > comp = val[i].compareTo(previous); > switch (dir) { > case INCREASING: > if (strict) { > if (0 <= comp) { > ok = false; > } > } else { > if ( comp < 0) { > ok = false; > } > } > break; > case DECREASING: > if (strict) { > if (comp >= 0) { > ok = false; > } > } else { > if (comp > 0) { > ok = false; > } > } > break; > default: > // Should never happen. > throw new IllegalArgumentException(); > } > > if (!ok && abort) { > throw new NonMonotonousSequenceException(val[i], previous, > i, dir, strict); > } > previous = val[i]; > } > > return ok; > } > > Would this be acceptable to all?
Probably not; we would not be able to call the new method with a "double[]" argument. Wherever such a call occurs, we would have to create a "Double[]" and copy over the contents, which seems a lot of operations just for the sake of a precondition test. Where do you want to use the new method? Anyway, if this method is needed within CM, the obvious possibility is to create it (and, unfortunately, almost duplicate the other one). > > I would also need to change NonMonotonousSequenceException. It would take > comparables in the constructor and look like: > > public NonMonotonousSequenceException(Comparable wrong, > Comparable previous, > int index, > MathUtils.OrderDirection > direction, > boolean strict) { > super(direction == MathUtils.OrderDirection.INCREASING ? > (strict ? > LocalizedFormats.NOT_STRICTLY_INCREASING_SEQUENCE : > LocalizedFormats.NOT_INCREASING_SEQUENCE) : > (strict ? > LocalizedFormats.NOT_STRICTLY_DECREASING_SEQUENCE : > LocalizedFormats.NOT_DECREASING_SEQUENCE), > (Number) previous.compareTo(wrong), > (Number)0, index, index - 1); > > this.direction = direction; > this.strict = strict; > this.index = index; > this.previous = null; > this.previousComp = previous; > } > Same here. Better create a new exception that will directly inherit from "MathIllegalArgumentException" (instead of "MathIllegalNumberException"). [I also don't get what are the arguments.] > > [...] Regards, Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org