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.forex.method.PresentValueForexBlackVolatilityQuoteSensitivityDataBundle.java
/** * Constructor with initial sensitivities for a given currency pair. * @param ccy1 First currency, not null/*from ww w . j a va 2s.c o m*/ * @param ccy2 Second currency, not null * @param expiries The expiries for the vega matrix, not null * @param delta The deltas for the vega matrix, not null * @param vega The initial sensitivity, not null */ public PresentValueForexBlackVolatilityQuoteSensitivityDataBundle(final Currency ccy1, final Currency ccy2, final double[] expiries, final double[] delta, final double[][] vega) { Validate.notNull(ccy1, "currency 1"); Validate.notNull(ccy2, "currency 2"); Validate.notNull(expiries, "expiries"); Validate.notNull(delta, "delta"); Validate.notNull(vega, "Matrix"); Validate.isTrue(vega.length == expiries.length, "Number of rows did not match number of expiries"); Validate.isTrue(vega[0].length == delta.length, "Number of columns did not match number of delta"); _currencyPair = ObjectsPair.of(ccy1, ccy2); _expiries = expiries; _delta = delta; _vega = vega; }
From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.IntegralLimitCalculator.java
/** * //from w w w. ja va 2 s . c o m * @param psi The characteristic function, not null * @param alpha The value of $\alpha$, not 0 or -1 * @param tol The tolerance for the root * @return The root */ public double solve(final Function1D<ComplexNumber, ComplexNumber> psi, final double alpha, final double tol) { Validate.notNull(psi, "psi null"); Validate.isTrue(alpha != 0.0 && alpha != -1.0, "alpha cannot be -1 or 0"); Validate.isTrue(tol > 0.0, "need tol > 0"); final double k = Math.log(tol) + Math.log(ComplexMathUtils.mod(psi.evaluate(new ComplexNumber(0.0, -(1 + alpha))))); final Function1D<Double, Double> f = new Function1D<Double, Double>() { @Override public Double evaluate(final Double x) { final ComplexNumber z = new ComplexNumber(x, -(1 + alpha)); return Math.log(ComplexMathUtils.mod(psi.evaluate(z))) - k; } }; double[] range = null; try { range = s_bracketRoot.getBracketedPoints(f, 0.0, 200.0); } catch (MathException e) { s_log.warn("Could not find integral limit. Using default of 500"); return 500.0; } return s_root.getRoot(f, range[0], range[1]); }
From source file:de.matzefratze123.heavyspleef.core.SimpleBasicTask.java
@Override public void start() { if (isRunning()) { throw new IllegalStateException("Task is already running"); }//from w w w . ja v a 2 s . c o m long delay = 0; long period = 0; if (taskType.getArgsLength() > 0) { Validate.isTrue(taskArgs.length >= 1, "Must specify delay in taskArgs"); delay = taskArgs[0]; if (taskType.getArgsLength() > 1) { Validate.isTrue(taskArgs.length >= 2, "Must specify delay and period in taskArgs"); period = taskArgs[1]; } } switch (taskType) { case ASYNC_DELAYED_TASK: task = scheduler.runTaskLaterAsynchronously(plugin, this, delay); break; case ASYNC_REPEATING_TASK: task = scheduler.runTaskTimerAsynchronously(plugin, this, delay, period); break; case ASYNC_RUN_TASK: task = scheduler.runTaskAsynchronously(plugin, this); break; case SYNC_DELAYED_TASK: task = scheduler.runTaskLater(plugin, this, delay); break; case SYNC_REPEATING_TASK: task = scheduler.runTaskTimer(plugin, this, delay, period); break; case SYNC_RUN_TASK: task = scheduler.runTask(plugin, this); break; default: break; } }
From source file:com.opengamma.analytics.financial.equity.variance.pricing.RealizedVariance.java
@Override public Double evaluate(final VarianceSwap swap) { double[] obs = swap.getObservations(); int nObs = obs.length; if (nObs < 2) { return 0.0; }//from www. j a v a 2 s.c o m Double[] weights = new Double[obs.length - 1]; if (swap.getObservationWeights().length == 0) { Arrays.fill(weights, 1.0); } else if (swap.getObservationWeights().length == 1) { Arrays.fill(weights, swap.getObservationWeights()[0]); } else { int nWeights = swap.getObservationWeights().length; Validate.isTrue(nWeights == nObs - 1, "If provided, observationWeights must be of length one less than observations, as they weight returns log(obs[i]/obs[i-1])." + " Found " + nWeights + " weights and " + nObs + " observations."); } Validate.isTrue(obs[0] != 0.0, "In VarianceSwap, the first observation is zero so the estimate of RealizedVariance is undefined. Check time series."); double logReturns = 0; for (int i = 1; i < nObs; i++) { Validate.isTrue(obs[i] != 0.0, "Encountered an invalid observation of zero in VarianceSwap at " + i + "'th observation. " + "The estimate of RealizedVariance is undefined. Check time series."); logReturns += weights[i - 1] * FunctionUtils.square(Math.log(obs[i] / obs[i - 1])); } return logReturns / (nObs - 1) * swap.getAnnualizationFactor(); }
From source file:com.opengamma.analytics.math.linearalgebra.TridiagonalMatrix.java
/** * @param a An array containing the diagonal values of the matrix, not null * @param b An array containing the upper sub-diagonal values of the matrix, not null. Its length must be one less than the length of the diagonal array * @param c An array containing the lower sub-diagonal values of the matrix, not null. Its length must be one less than the length of the diagonal array *///from www.jav a 2 s . c o m public TridiagonalMatrix(final double[] a, final double[] b, final double[] c) { Validate.notNull(a, "a"); Validate.notNull(b, "b"); Validate.notNull(c, "c"); final int n = a.length; Validate.isTrue(b.length == n - 1, "Length of subdiagonal b is incorrect"); Validate.isTrue(c.length == n - 1, "Length of subdiagonal c is incorrect"); _a = a; _b = b; _c = c; }
From source file:ar.com.zauber.commons.web.uri.factory.RelativePathUriFactory.java
/** Creates a new {@link RelativePathUriFactory} */ public RelativePathUriFactory(final UriFactory callback, final String encoding, final RequestProvider requestProvider) { Validate.notNull(callback);//from w w w . ja v a2s.c o m Validate.notNull(encoding); Validate.notNull(requestProvider); Validate.isTrue(Charset.isSupported(encoding), "Encoding no soportado"); defaultEncoding = encoding; this.callback = callback; this.requestProvider = requestProvider; }
From source file:net.daboross.bukkitdev.skywars.api.arenaconfig.SkyArenaConfig.java
public SkyArenaConfig(String arenaName, List<SkyPlayerLocation> spawns, int numTeams, int teamSize, final int minPlayers, int placementY, SkyBoundariesConfig boundaries, final List<SkyArenaChest> chests) { Validate.isTrue(numTeams >= 2, "Num teams can't be smaller than 2"); Validate.isTrue(teamSize >= 1, "Team size can't be smaller than 1"); Validate.isTrue(minPlayers <= numTeams * teamSize, "Min players can't be smaller tha max players (num teams * team size)"); Validate.isTrue(placementY >= 0, "placement-y can't be smaller than 0"); Validate.notNull(boundaries);//from w w w . j av a 2 s . c om Validate.notNull(spawns); Validate.isTrue(spawns.size() >= numTeams, "Number of spawns needs to be at least as big as numTeams"); this.arenaName = arenaName; this.spawns = new ArrayList<>(spawns.size()); for (SkyPlayerLocation l : spawns) { this.spawns.add(l.changeWorld(null)); } this.numTeams = numTeams; this.teamSize = teamSize; this.minPlayers = minPlayers; this.placementY = placementY; this.boundaries = boundaries; this.chests = chests; }
From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.MeanCorrection.java
@Override public ComplexNumber getValue(ComplexNumber u, double t) { final ComplexNumber temp = _base.getValue(MINUS_I, t); Validate.isTrue(Math.abs(temp.getImaginary()) < 1e-12, "problem with CharacteristicExponent"); final ComplexNumber w = new ComplexNumber(0, -temp.getReal()); return add(_base.getValue(u, t), multiply(w, u)); }
From source file:ar.com.zauber.garfio.modules.mantis.model.MantisTrackerSession.java
/** constructor * @param username *//*from w ww .j a va2 s . co m*/ public MantisTrackerSession(final ActionFactory actionFactory, final ISession session, final String username) { Validate.notNull(actionFactory, "actionFactory is null"); Validate.notNull(session, "session is null"); Validate.isTrue(!StringUtils.isBlank(username), "username is blank"); this.actionFactory = actionFactory; this.session = session; this.username = username; }
From source file:com.opengamma.analytics.math.statistics.descriptive.PartialMomentCalculator.java
/** * @param x The array of data, not null or empty * @return The partial moment//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 > 0, "x cannot be empty"); final int n = x.length; final double[] copyX = Arrays.copyOf(x, n); Arrays.sort(copyX); double sum = 0; if (_useDownSide) { int i = 0; if (copyX[i] > _threshold) { return 0.; } while (i < n && copyX[i] < _threshold) { sum += (copyX[i] - _threshold) * (copyX[i] - _threshold); i++; } return Math.sqrt(sum / i); } int i = n - 1; int count = 0; if (copyX[i] < _threshold) { return 0.; } while (i >= 0 && copyX[i] > _threshold) { sum += (copyX[i] - _threshold) * (copyX[i] - _threshold); count++; i--; } return Math.sqrt(sum / count); }