DoublesScheduleGenerator { public static double[] truncateSetInclusive(final double lower, final double upper, final double[] set) { final double[] temp = truncateSetExclusive(lower, upper, set); final int n = temp.length; if (n == 0) { return new double[] {lower, upper }; } final boolean addLower = different(lower, temp[0]); final boolean addUpper = different(upper, temp[n - 1]); if (!addLower && !addUpper) { temp[0] = lower; temp[n - 1] = upper; return temp; } final int m = n + (addLower ? 1 : 0) + (addUpper ? 1 : 0); final double[] res = new double[m]; System.arraycopy(temp, 0, res, (addLower ? 1 : 0), n); res[0] = lower; res[m - 1] = upper; return res; }  static double[] getIntegrationsPoints(final double start, final double end, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve); static double[] getIntegrationsPoints(final double start, final double end, final double[] setA, final double[] setB); static double[] combineSets(final double[] set1, final double[] set2); static double[] truncateSetInclusive(final double lower, final double upper, final double[] set); static double[] truncateSetExclusive(final double lower, final double upper, final double[] set); static double[] leftTruncate(final double lower, final double[] set);  }
@Test public void truncateSetInclusiveTest() { final double lower = 0.1; final double upper = 2.5; final double[] set0 = new double[] {-0.2, 1.5, 2.9 }; final double[] exp0 = new double[] {0.1, 1.5, 2.5 }; final double[] res0 = DoublesScheduleGenerator.truncateSetInclusive(lower, upper, set0); assertTrue(equalArrays(exp0, res0)); final double[] set1 = new double[] {-0.2, -0.1 }; final double[] exp1 = new double[] {0.1, 2.5 }; final double[] res1 = DoublesScheduleGenerator.truncateSetInclusive(lower, upper, set1); assertTrue(equalArrays(exp1, res1)); final double[] set2 = new double[] {0.1 + 1.e-3, 1.5, 2.8 }; final double[] exp2 = new double[] {0.1, 1.5, 2.5 }; final double[] res2 = DoublesScheduleGenerator.truncateSetInclusive(lower, upper, set2); assertTrue(equalArrays(exp2, res2)); final double[] set3 = new double[] {0., 1.5, 2.5 + 1.e-3 }; final double[] exp3 = new double[] {0.1, 1.5, 2.5 }; final double[] res3 = DoublesScheduleGenerator.truncateSetInclusive(lower, upper, set3); assertTrue(equalArrays(exp3, res3)); final double[] set4 = new double[] {0.1 - 1.e-4, 1.5, 2.5 - 1.e-4 }; final double[] exp4 = new double[] {0.1, 1.5, 2.5 }; final double[] res4 = DoublesScheduleGenerator.truncateSetInclusive(lower, upper, set4); assertTrue(equalArrays(exp4, res4)); final double[] set5 = new double[] {lower + 1.e-4, lower + 2.e-4 }; final double[] exp5 = new double[] {lower, lower + 1.e-3 }; final double[] res5 = DoublesScheduleGenerator.truncateSetInclusive(lower, lower + 1.e-3, set5); assertTrue(equalArrays(exp5, res5)); }