### Question:
VectorPair implements Serializable { public void makeStepwise(int direction) { final Vector X = this.X; final Vector Y = this.Y; final int length = Y.size(); if (length+1 != X.size()) { throw new IllegalArgumentException("Mismatched vector lengths."); } int[] Xi = new int[length*2]; int[] Yi = new int[length*2]; if (length != 0) { boolean swap = false; double x0 = X.doubleValue(0); double y0 = Y.doubleValue(0); for (int i=0,j=0; i<length; i++) { if (direction != 0) { if (i+1 == length) { swap = false; } else { final double xi = X.doubleValue(i+1); final double yi = Y.doubleValue(i+1); int xs = (xi > x0) ? +1 : (xi < x0) ? -1 : 0; if (xs != 0) { boolean up = (direction >= 0) ^ (xs < 0) ^ swap; if (up ? (yi > y0) : (yi < y0)) { swap = !swap; } } x0 = xi; y0 = yi; } } Xi[j] = i; Yi[j++] = i; Xi[j] = swap ? i : i+1; Yi[j++] = swap ? i+1 : i; } assert ArraysExt.isSorted(Xi, false); assert ArraysExt.isSorted(Yi, false); if (Math.abs(direction) >= 2) { direction = Integer.signum(direction); int size = Xi.length; for (int i=size; --i>=2;) { if (Xi[i] == Xi[i-2]) { final double y1, y2; y0 = Y.doubleValue(Yi[i-2]) * direction; y1 = Y.doubleValue(Yi[i-1]) * direction; y2 = Y.doubleValue(Yi[i ]) * direction; if (y1 < Math.min(y0, y2)) { System.arraycopy(Xi, i, Xi, i-1, size-i); System.arraycopy(Yi, i, Yi, i-1, size-i); size--; } } } Xi = ArraysExt.resize(Xi, size); Yi = ArraysExt.resize(Yi, size); } } this.X = X.pick(Xi); this.Y = Y.pick(Yi); } VectorPair(final Vector X, final Vector Y); Vector getX(); Vector getY(); int length(); void omitColinearPoints(final double xTolerance, double yTolerance); void makeStepwise(int direction);  }### Answer:
@Test public void testMakeStepwise() { final double[] x = {1, 2, 3, 4, 5, 6, 7}; final double[] y = {4, 5, 6, 6, 3, 4}; final double[] ey = {4, 4, 5, 5, 6, 6, 6, 6, 3, 3, 4, 4}; final double[] ex = {1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7}; final VectorPair pair = new VectorPair(Vector.create(x, false), Vector.create(y, false)); pair.makeStepwise(0); assertEquals(Vector.create(ey, false), pair.getY()); assertEquals(Vector.create(ex, false), pair.getX()); }