List of usage examples for org.apache.commons.lang Validate isTrue
public static void isTrue(boolean expression, String message)
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), "The value must be greater than zero"); Validate.isTrue( myObject.isOk(), "The object is not OK");
For performance reasons, the message string should not involve a string append, instead use the #isTrue(boolean,String,Object) method.
From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SABRFormulaData.java
/** * // w w w . j ava 2 s . com * @param parameters Must be 4 parameters in the order alpha, beta, rho, nu */ public SABRFormulaData(final double[] parameters) { Validate.notNull(parameters, "parameters are null"); Validate.isTrue(parameters.length == NUM_PARAMETERS, "must be " + NUM_PARAMETERS + " parameters"); Validate.isTrue(parameters[0] >= 0.0, "alpha must be >= 0.0"); Validate.isTrue(parameters[1] >= 0.0, "beta must be >= 0.0"); Validate.isTrue(parameters[2] >= -1 && parameters[2] <= 1, "rho must be between -1 and 1"); Validate.isTrue(parameters[3] >= 0.0, "nu must be >= 0.0"); _parameters = new double[NUM_PARAMETERS]; System.arraycopy(parameters, 0, _parameters, 0, NUM_PARAMETERS); }
From source file:com.opengamma.analytics.financial.var.EmpiricalDistributionVaRParameters.java
public EmpiricalDistributionVaRParameters(final double horizon, final double periods, final double quantile) { Validate.isTrue(horizon > 0, "horizon"); Validate.isTrue(periods > 0, "periods"); if (!ArgumentChecker.isInRangeInclusive(0, 1, quantile)) { throw new IllegalArgumentException("Quantile must be between 0 and 1"); }// ww w. j a v a 2 s .c om _percentileCalculator = new PercentileCalculator(1 - quantile); _horizon = horizon; _periods = periods; _quantile = quantile; _mult = Math.sqrt(horizon / periods); }
From source file:com.opengamma.analytics.financial.timeseries.util.TimeSeriesPercentageChangeOperator.java
@Override public DateDoubleTimeSeries<?> evaluate(DateDoubleTimeSeries<?> ts) { Validate.notNull(ts, "time series"); Validate.isTrue(ts.size() > 1, "time series length must be > 1"); final int[] times = ts.timesArrayFast(); final double[] values = ts.valuesArrayFast(); final int n = times.length; final int[] resultTimes = new int[n - 1]; final double[] percentageChanges = new double[n - 1]; for (int i = 1; i < n; i++) { resultTimes[i - 1] = times[i];//from ww w . j a va2 s . c om percentageChanges[i - 1] = (values[i] - values[i - 1]) / values[i - 1]; } return ImmutableLocalDateDoubleTimeSeries.of(resultTimes, percentageChanges); }
From source file:com.opengamma.analytics.math.interpolation.RationalFunctionInterpolator1D.java
public RationalFunctionInterpolator1D(final int degree, double eps) { Validate.isTrue(degree > 0, "Need a degree of at least one to perform rational function interpolation"); _degree = degree;//from ww w. j a va2 s . c o m _eps = eps; }
From source file:com.opengamma.analytics.math.statistics.descriptive.SampleMomentCalculator.java
/** * @param n The degree of the moment to calculate, cannot be negative */// ww w.j a v a2 s .com public SampleMomentCalculator(final int n) { Validate.isTrue(n >= 0, "n must be >= 0"); _n = n; }
From source file:com.opengamma.analytics.math.interpolation.BarycentricRationalFunctionInterpolator1D.java
public BarycentricRationalFunctionInterpolator1D(final int degree, double eps) { Validate.isTrue(degree > 0, "Cannot perform interpolation with rational functions of degree < 1"); _degree = degree;/*from w ww . ja v a 2s .co m*/ _eps = eps; }
From source file:com.opengamma.analytics.math.statistics.descriptive.MeanCalculator.java
/** * @param x The array of data, not null or empty * @return The arithmetic mean/*from ww w . j a v a 2 s .c o m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x); Validate.isTrue(x.length > 0, "x cannot be empty"); if (x.length == 1) { return x[0]; } double sum = 0; for (final Double d : x) { sum += d; } return sum / x.length; }
From source file:com.opengamma.analytics.math.statistics.descriptive.GeometricMeanCalculator.java
/** * @param x The array of data, not null or empty * @return The geometric mean//w w w .j a va 2 s. c o m */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0, "x cannot be empty"); final int n = x.length; double mult = x[0]; for (int i = 1; i < n; i++) { mult *= x[i]; } return Math.pow(mult, 1. / n); }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.formula.CEVFunctionData.java
public CEVFunctionData(final double f, final double df, final double sigma, final double beta) { _forward = f;//from w ww .j a v a 2s . com _numeraire = df; _volatility = sigma; Validate.isTrue(beta >= 0.0, "beta less than zero not supported"); _beta = beta; }
From source file:com.opengamma.analytics.financial.model.volatility.smile.function.HestonModelData.java
public HestonModelData(final double[] parameters) { Validate.notNull(parameters, "null parameters"); Validate.isTrue(parameters.length == NUM_PARAMETERS, "number of parameters wrong"); Validate.isTrue(parameters[0] >= 0.0, "kappa must be >= 0"); Validate.isTrue(parameters[1] >= 0.0, "theta must be >= 0"); Validate.isTrue(parameters[2] >= 0.0, "vol0 must be >= 0"); Validate.isTrue(parameters[3] >= 0.0, "omega must be >= 0"); Validate.isTrue(parameters[4] >= -1.0 && parameters[4] <= 1.0, "rho must be >= -1 && <= 1"); _parameters = new double[NUM_PARAMETERS]; System.arraycopy(parameters, 0, _parameters, 0, NUM_PARAMETERS); }