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.math.function.special.NaturalLogGammaFunction.java
/** * @param x The argument of the function, must be greater than zero * @return The value of the function //from w w w. j a va 2s. c o m */ @Override public Double evaluate(final Double x) { Validate.isTrue(x > 0, "x must be greater than zero"); return Gamma.logGamma(x); }
From source file:com.opengamma.analytics.financial.simpleinstruments.derivative.SimpleFuture.java
public SimpleFuture(final double expiry, final double settlement, final double referencePrice, final double unitAmount, final Currency currency) { Validate.notNull(currency, "currency"); Validate.isTrue(expiry >= 0, "time to expiry must be positive"); Validate.isTrue(settlement >= 0, "time to settlement must be positive"); _expiry = expiry;/*from w w w. j av a 2 s. c om*/ _settlement = settlement; _referencePrice = referencePrice; _unitAmount = unitAmount; _currency = currency; }
From source file:com.opengamma.analytics.math.statistics.descriptive.ModeCalculator.java
/** * @param x The array of data, not null or empty * @return The arithmetic mean/* w w w . j av a2 s . c o m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "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 TreeMap<Integer, Double> counts = new TreeMap<Integer, Double>(); int count = 1; for (int i = 1; i < x1.length; i++) { if (Math.abs(x1[i] - x1[i - 1]) < EPS) { count++; } else { counts.put(count, x1[i - 1]); count = 1; } } if (counts.lastKey() == 1) { throw new MathException("Could not find mode for array; no repeated values"); } return counts.lastEntry().getValue(); }
From source file:fr.ribesg.bukkit.api.chat.Click.java
/** * Builds a new Click of type {@link Type#OPEN_URL}. * * @param url an URL matching {@link #HTTP_REGEX} * * @return a new Click of type OPEN_URL/* w ww . j a va2 s. c o m*/ */ public static Click ofOpenUrl(final String url) { Validate.notNull(url, "Url cannot be null!"); Validate.isTrue(HTTP_REGEX.matcher(url).matches(), "Provided url is invalid: " + url); return forType(Type.OPEN_URL, url); }
From source file:com.opengamma.analytics.financial.model.finitedifference.ChebyshevMeshing.java
@Override public Double evaluate(final Integer i) { Validate.isTrue(i >= 0 && i < getNumberOfPoints(), "i out of range"); return _a + _r * (1 - Math.cos(i * Math.PI / _n)); }
From source file:com.opengamma.analytics.math.integration.GaussianQuadratureData.java
/** * @param abscissas An array containing the abscissas, not null * @param weights An array containing the weights, not null, must be the same length as the abscissa array *//*w ww .j a va 2 s. c o m*/ public GaussianQuadratureData(final double[] abscissas, final double[] weights) { Validate.notNull(abscissas, "abscissas"); Validate.notNull(weights, "weights"); Validate.isTrue(abscissas.length == weights.length, "Abscissa and weight arrays must be the same length"); _weights = weights; _abscissas = abscissas; }
From source file:com.opengamma.analytics.financial.var.NormalVaRParameters.java
public NormalVaRParameters(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"); }//from w w w . j a va 2s . c o m _horizon = horizon; _periods = periods; _quantile = quantile; _z = NORMAL.getInverseCDF(quantile); _timeScaling = Math.sqrt(horizon / periods); }
From source file:com.opengamma.analytics.financial.model.volatility.smile.fitting.EuropeanOptionMarketData.java
public EuropeanOptionMarketData(final double forward, final double strike, final double discountFactor, final double timeToExpiry, final boolean isCall, final double impliedVol) { Validate.isTrue(forward > 0, "need forward > 0"); Validate.isTrue(strike >= 0, "need forward >= 0"); Validate.isTrue(timeToExpiry >= 0, "need timeToExpiry >= 0"); Validate.isTrue(impliedVol >= 0, "need impliedVol >= 0"); _fwd = forward;// ww w .j av a2 s . c om _strike = strike; _df = discountFactor; _t = timeToExpiry; _vol = impliedVol; _isCall = isCall; }
From source file:com.opengamma.analytics.math.statistics.descriptive.SampleStandardDeviationCalculator.java
/** * @param x The array of data, not null, must contain at least two data points * @return The sample standard deviation *//*from w w w. j a v a 2s . c o m*/ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length >= 2, "Need at least two points to calculate standard deviation"); return Math.sqrt(VARIANCE.evaluate(x)); }
From source file:com.opengamma.analytics.math.statistics.descriptive.PopulationStandardDeviationCalculator.java
/** * @param x The array of data, not null, must contain at least two data points * @return The population standard deviation *///from www . j a va2s . c o m @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 1, "Need at least two points to calculate standard deviation"); return Math.sqrt(VARIANCE.evaluate(x)); }