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.var.StudentTVaRParameters.java
public StudentTVaRParameters(final double horizon, final double periods, final double quantile, final double dof) { 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"); }/* w w w.j a v a2s . c o m*/ Validate.isTrue(dof > 0, "degrees of freedom"); _horizon = horizon; _periods = periods; _quantile = quantile; _dof = dof; _studentT = new StudentTDistribution(dof); _mult = Math.sqrt((_dof - 2) * horizon / dof / periods) * _studentT.getInverseCDF(quantile); _scale = horizon / periods; }
From source file:com.opengamma.analytics.math.interpolation.data.InterpolatorNDDataBundle.java
private void validateData(final List<Pair<double[], Double>> data) { Validate.notEmpty(data, "no data"); final Iterator<Pair<double[], Double>> iter = data.iterator(); final int dim = iter.next().getFirst().length; Validate.isTrue(dim > 0, "no actual data"); while (iter.hasNext()) { Validate.isTrue(iter.next().getFirst().length == dim, "different dimensions in data"); }//ww w .j a va 2 s.com }
From source file:com.opengamma.analytics.math.statistics.descriptive.SampleCentralMomentCalculator.java
/** * @param n The degree of the moment to calculate, cannot be negative *///from w w w . j av a 2 s .c om public SampleCentralMomentCalculator(final int n) { Validate.isTrue(n >= 0, "n must be >= 0"); _n = n; }
From source file:com.opengamma.analytics.math.statistics.descriptive.MedianCalculator.java
/** * @param x The array of data, not null or empty * @return The median/* www.j ava 2s . com*/ */ @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]; } final double[] x1 = Arrays.copyOf(x, x.length); Arrays.sort(x1); final int mid = x1.length / 2; if (x1.length % 2 == 1) { return x1[mid]; } return (x1[mid] + x1[mid - 1]) / 2.; }
From source file:com.opengamma.analytics.math.statistics.descriptive.robust.TrimmedMeanCalculator.java
@Override public Double evaluate(final double[] x) { Validate.notNull(x, "x was null"); final int length = x.length; Validate.isTrue(length > 0, "x was empty"); final int value = (int) Math.round(length * _gamma); final double[] copy = Arrays.copyOf(x, length); Arrays.sort(copy);/* w w w. jav a 2 s .com*/ final double[] trimmed = new double[length - 2 * value]; for (int i = 0; i < trimmed.length; i++) { trimmed[i] = x[i + value]; } return MEAN_CALCULATOR.evaluate(trimmed); }
From source file:com.opengamma.analytics.financial.simpleinstruments.derivative.SimpleFXFuture.java
public SimpleFXFuture(final double expiry, final double settlement, final double referencePrice, final double unitAmount, final Currency payCurrency, final Currency receiveCurrency) { Validate.notNull(payCurrency, "currency"); Validate.isTrue(expiry >= 0, "time to expiry must be positive"); Validate.isTrue(settlement >= 0, "time to settlement must be positive"); _expiry = expiry;/*from ww w . j a va 2 s . com*/ _settlement = settlement; _referencePrice = referencePrice; _unitAmount = unitAmount; _payCurrency = payCurrency; _receiveCurrency = receiveCurrency; }
From source file:com.opengamma.analytics.math.statistics.descriptive.robust.WinsorizedMeanCalculator.java
@Override public Double evaluate(final double[] x) { Validate.notNull(x, "x was null"); final int length = x.length; Validate.isTrue(length > 0, "x was empty"); final double[] winsorized = Arrays.copyOf(x, length); Arrays.sort(winsorized);//from w w w .j a v a 2 s . co m final int value = (int) Math.round(length * _gamma); final double x1 = winsorized[value]; final double x2 = winsorized[length - value - 1]; for (int i = 0; i < value; i++) { winsorized[i] = x1; winsorized[length - 1 - i] = x2; } return MEAN_CALCULATOR.evaluate(winsorized); }
From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SVIVolatilityFunction.java
@Override public Function1D<SVIFormulaData, Double> getVolatilityFunction(final EuropeanVanillaOption option, final double forward) { Validate.notNull(option, "option"); Validate.isTrue(forward > 0, "Need forward >= 0"); final double strike = option.getStrike(); Validate.isTrue(strike > 0, "Need strike >= 0"); final double kappa = Math.log(strike / forward); return new Function1D<SVIFormulaData, Double>() { @SuppressWarnings("synthetic-access") @Override//from ww w . j a v a2 s . c o m public Double evaluate(final SVIFormulaData data) { return getVolatility(kappa, data); } }; }
From source file:com.opengamma.analytics.math.interpolation.KrigingInterpolatorND.java
@Override public Double interpolate(final InterpolatorNDDataBundle data, final double[] x) { validateInput(data, x);//from ww w . j a va 2 s . c om Validate.isTrue(data instanceof KrigingInterpolatorDataBundle, "KriginInterpolatorND needs a KriginInterpolatorDataBundle"); KrigingInterpolatorDataBundle krigingData = (KrigingInterpolatorDataBundle) data; final List<Pair<double[], Double>> rawData = krigingData.getData(); final Function1D<Double, Double> variogram = krigingData.getVariogram(); final double[] w = krigingData.getWeights(); final int n = rawData.size(); double sum = 0.0; double r; for (int i = 0; i < n; i++) { r = DistanceCalculator.getDistance(x, rawData.get(i).getFirst()); sum += variogram.evaluate(r) * w[i]; } sum += w[n]; return sum; }
From source file:com.opengamma.analytics.math.statistics.descriptive.PercentileCalculator.java
/** * @param percentile The percentile, must be between 0 and 1 */// ww w. j av a2 s .c o m public void setPercentile(final double percentile) { Validate.isTrue(percentile > 0 && percentile < 1, "Percentile must be between 0 and 1"); _percentile = percentile; }