List of usage examples for org.apache.commons.lang Validate isTrue
public static void isTrue(boolean expression)
Validate an argument, throwing IllegalArgumentException
if the test result is false
.
This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.
Validate.isTrue( i > 0 ); Validate.isTrue( myObject.isOk() );
The message in the exception is 'The validated expression is false'.
From source file:com.opengamma.analytics.financial.schedule.QuarterlyScheduleCalculator.java
@Override public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd, final boolean generateRecursive) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate)); if (startDate.equals(endDate)) { return new LocalDate[] { startDate }; }//from w ww. j a va 2s . c o m final List<LocalDate> dates = new ArrayList<LocalDate>(); if (fromEnd) { LocalDate date = endDate; int i = 3; while (!date.isBefore(startDate)) { dates.add(date); date = generateRecursive ? date.minus(Period.ofMonths(3)) : endDate.minus(Period.ofMonths(i)); i += 3; } Collections.reverse(dates); return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); } LocalDate date = startDate; int i = 3; while (!date.isAfter(endDate)) { dates.add(date); date = generateRecursive ? date.plus(Period.ofMonths(3)) : startDate.plus(Period.ofMonths(i)); i += 3; } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.schedule.SemiAnnualScheduleCalculator.java
@Override public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd, final boolean generateRecursive) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate)); if (startDate.equals(endDate)) { return new LocalDate[] { startDate }; }// ww w . j a va2 s . c o m final List<LocalDate> dates = new ArrayList<LocalDate>(); if (fromEnd) { LocalDate date = endDate; int i = 6; while (!date.isBefore(startDate)) { dates.add(date); date = generateRecursive ? date.minus(Period.ofMonths(6)) : endDate.minus(Period.ofMonths(i)); i += 6; } Collections.reverse(dates); return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); } LocalDate date = startDate; int i = 6; while (!date.isAfter(endDate)) { dates.add(date); date = generateRecursive ? date.plus(Period.ofMonths(6)) : startDate.plus(Period.ofMonths(i)); i += 6; } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.timeseries.analysis.DoubleTimeSeriesStatisticsCalculator.java
@Override public Double evaluate(final DoubleTimeSeries<?>... x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0); ArgumentChecker.noNulls(x, "x"); final int n = x.length; final double[][] arrays = new double[n][]; for (int i = 0; i < n; i++) { arrays[i] = x[i].valuesArrayFast(); }/*from w ww. jav a 2 s .c o m*/ return _statistic.evaluate(arrays); }
From source file:com.opengamma.analytics.financial.interestrate.InterestRateCurveSensitivityUtils.java
/** * Takes a list of curve sensitivities (i.e. an unordered list of pairs of times and sensitivities) and returns a list order by ascending * time, and with sensitivities that occur at the same time netted (zero net sensitivities are removed) * @param old An unordered list of pairs of times and sensitivities * @param relTol Relative tolerance - if the net divided by gross sensitivity is less than this it is ignored/removed * @param absTol Absolute tolerance - is the net sensitivity is less than this it is ignored/removed * @return A time ordered netted list/* w ww . java2 s . c o m*/ */ static final List<DoublesPair> clean(final List<DoublesPair> old, final double relTol, final double absTol) { Validate.notNull(old, "null list"); Validate.isTrue(relTol >= 0.0 && absTol >= 0.0); if (old.size() == 0) { return new ArrayList<DoublesPair>(); } final List<DoublesPair> res = new ArrayList<DoublesPair>(); final DoublesPair[] sort = old.toArray(new DoublesPair[] {}); Arrays.sort(sort, FirstThenSecondDoublesPairComparator.INSTANCE); final DoublesPair pairOld = sort[0]; double tOld = pairOld.first; double sum = pairOld.getSecond(); double scale = Math.abs(sum); double t = tOld; for (int i = 1; i < sort.length; i++) { final DoublesPair pair = sort[i]; t = pair.first; if (t > tOld) { if (Math.abs(sum) > absTol && Math.abs(sum) / scale > relTol) { res.add(new DoublesPair(tOld, sum)); } tOld = t; sum = pair.getSecondDouble(); scale = Math.abs(sum); } else { sum += pair.getSecondDouble(); scale += Math.abs(pair.getSecondDouble()); } } if (Math.abs(sum) > absTol && Math.abs(sum) / scale > relTol) { res.add(new DoublesPair(t, sum)); } return res; }
From source file:com.opengamma.analytics.financial.schedule.DailyScheduleCalculator.java
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate)); if (startDate.equals(endDate)) { return new LocalDate[] { startDate }; }// w ww . j av a2 s . com final List<LocalDate> dates = new ArrayList<LocalDate>(); LocalDate date = startDate; while (!date.isAfter(endDate)) { dates.add(date); date = date.plusDays(1); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:it.filosganga.mobile.widgets.component.TableCell.java
public TableCell(List<Component> children, boolean summary, int colspan) { super(children); Validate.isTrue(colspan >= 1); this.summary = summary; this.colspan = colspan; }
From source file:com.opengamma.analytics.financial.interestrate.NelsonSiegelSvennsonBondCurveModel.java
public ParameterizedFunction<Double, DoubleMatrix1D, Double> getParameterizedFunction() { return new ParameterizedFunction<Double, DoubleMatrix1D, Double>() { @Override// ww w. j a va2 s .c o m public Double evaluate(final Double t, final DoubleMatrix1D parameters) { Validate.notNull(t, "t"); Validate.notNull(parameters, "parameters"); Validate.isTrue(parameters.getNumberOfElements() == 6); final double beta0 = parameters.getEntry(0); final double beta1 = parameters.getEntry(1); final double beta2 = parameters.getEntry(2); final double lambda1 = parameters.getEntry(3); final double beta3 = parameters.getEntry(4); final double lambda2 = parameters.getEntry(5); final double x1 = t / lambda1; final double x2 = (1 - Math.exp(-x1)) / x1; final double x3 = t / lambda2; final double x4 = (1 - Math.exp(-x3)) / x3; return beta0 + beta1 * x2 + beta2 * (x2 - Math.exp(-x1)) + beta3 * (x4 - Math.exp(-x3)); } public Object writeReplace() { return new InvokedSerializedForm(NelsonSiegelSvennsonBondCurveModel.class, "getParameterizedFunction"); } }; }
From source file:com.opengamma.analytics.financial.var.parametric.DeltaMeanCalculator.java
@Override public Double evaluate(final Map<Integer, ParametricVaRDataBundle> data) { Validate.notNull(data, "data"); Validate.isTrue(data.containsKey(1)); final ParametricVaRDataBundle deltaData = data.get(1); final DoubleMatrix1D mean = deltaData.getExpectedReturn(); final DoubleMatrix1D delta = (DoubleMatrix1D) deltaData.getSensitivities(); return _algebra.getInnerProduct(delta, mean); }
From source file:com.opengamma.analytics.financial.schedule.FirstOfMonthScheduleCalculator.java
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate)); if (startDate.equals(endDate)) { if (startDate.getDayOfMonth() == 1) { return new LocalDate[] { startDate }; }//from ww w . j ava2s . c om throw new IllegalArgumentException( "Start date and end date were the same but neither was the first day of the month"); } final List<LocalDate> dates = new ArrayList<LocalDate>(); LocalDate date = startDate.with(DateAdjusters.firstDayOfMonth()); if (date.isBefore(startDate)) { date = date.plusMonths(1); } while (!date.isAfter(endDate)) { dates.add(date); date = date.plusMonths(1); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.interestrate.NelsonSiegelBondCurveModel.java
public ParameterizedFunction<Double, DoubleMatrix1D, Double> getParameterizedFunction() { return new ParameterizedFunction<Double, DoubleMatrix1D, Double>() { @Override/*from ww w. j av a2 s. c o m*/ public Double evaluate(final Double t, final DoubleMatrix1D parameters) { Validate.notNull(t, "t"); Validate.notNull(parameters, "parameters"); Validate.isTrue(parameters.getNumberOfElements() == 4); final double beta0 = parameters.getEntry(0); final double beta1 = parameters.getEntry(1); final double beta2 = parameters.getEntry(2); final double lambda = parameters.getEntry(3); final double x1 = t / lambda; final double x2 = Epsilon.epsilon(-x1); return beta0 + beta1 * x2 + beta2 * (x2 - Math.exp(-x1)); } public Object writeReplace() { return new InvokedSerializedForm(NelsonSiegelBondCurveModel.class, "getParameterizedFunction"); } }; }