BasisFunctionKnots { public static BasisFunctionKnots fromInternalKnots(double[] internalKnots, int degree) { ArgumentChecker.notEmpty(internalKnots, "knots"); ArgumentChecker.notNegative(degree, "degree"); int nInterKnots = internalKnots.length; ArgumentChecker.isTrue(nInterKnots - degree > 0, "Require at least {} knots for degree {}, only given {}", degree + 1, degree, nInterKnots); for (int i = 1; i < nInterKnots; i++) { ArgumentChecker.isTrue(internalKnots[i] - internalKnots[i - 1] > 0, "knots are not ascending"); } int nSplines = nInterKnots + degree - 1; int nTotalKnots = nInterKnots + 2 * degree; double[] knots = new double[nTotalKnots]; double dxa = internalKnots[1] - internalKnots[0]; double dxb = internalKnots[nInterKnots - 1] - internalKnots[nInterKnots - 2]; for (int i = 0; i < degree; i++) { knots[i] = (i - degree) * dxa + internalKnots[0]; knots[degree + nInterKnots + i] = internalKnots[nInterKnots - 1] + dxb * (i + 1); } System.arraycopy(internalKnots, 0, knots, degree, nInterKnots); return new BasisFunctionKnots(knots, degree, nSplines); } private  BasisFunctionKnots(double[] knots, int degree, int nSplines); static BasisFunctionKnots fromUniform(double xa, double xb, int nKnots, int degree); static BasisFunctionKnots fromInternalKnots(double[] internalKnots, int degree); static BasisFunctionKnots fromKnots(double[] knots, int degree); double[] getKnots(); int getNumKnots(); int getDegree(); int getNumSplines();  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullInternalKnots() { BasisFunctionKnots.fromInternalKnots(null, 2); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegDegree2() { BasisFunctionKnots.fromInternalKnots(KNOTS, -1); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWrongOrderInternalKnots() { BasisFunctionKnots.fromInternalKnots(WRONG_ORDER_KNOTS, 3); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testDegreeToHigh2() { BasisFunctionKnots.fromInternalKnots(KNOTS, 11); }