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.derivative.Forex.java
/** * Constructor from two fixed payments. The payments should take place on the same date. The sign of the amounts should be opposite. * @param paymentCurrency1 The first currency payment. * @param paymentCurrency2 The second currency payment. *//* w w w. j a va2s. c om*/ public Forex(final PaymentFixed paymentCurrency1, final PaymentFixed paymentCurrency2) { Validate.notNull(paymentCurrency1, "Payment 1"); Validate.notNull(paymentCurrency2, "Payment 2"); Validate.isTrue(Double.doubleToLongBits(paymentCurrency1.getPaymentTime()) == Double .doubleToLongBits(paymentCurrency2.getPaymentTime()), "Payments on different time"); Validate.isTrue((paymentCurrency1.getAmount() * paymentCurrency2.getAmount()) <= 0, "Payments with same sign"); Validate.isTrue(!paymentCurrency1.getCurrency().equals(paymentCurrency2.getCurrency()), "same currency"); this._paymentCurrency1 = paymentCurrency1; this._paymentCurrency2 = paymentCurrency2; }
From source file:de.xaniox.heavyspleef.core.SimpleBasicTask.java
public long getTaskArgument(int index) { Validate.isTrue(index < taskArgs.length, "Index out of bounds"); return taskArgs[index]; }
From source file:com.opengamma.analytics.math.matrix.MatrixAlgebra.java
/** * Adds two matrices. This operation can only be performed if the matrices are of the same type and dimensions. * @param m1 The first matrix, not null//from w w w .ja v a 2s . c o m * @param m2 The second matrix, not null * @return The sum of the two matrices * @throws IllegalArgumentException If the matrices are not of the same type, if the matrices are not the same shape. */ public Matrix<?> add(final Matrix<?> m1, final Matrix<?> m2) { Validate.notNull(m1, "m1"); Validate.notNull(m2, "m2"); if (m1 instanceof DoubleMatrix1D) { if (m2 instanceof DoubleMatrix1D) { final double[] x1 = ((DoubleMatrix1D) m1).getData(); final double[] x2 = ((DoubleMatrix1D) m2).getData(); final int n = x1.length; Validate.isTrue(n == x2.length, "Can only add matrices of the same shape"); final double[] sum = new double[n]; for (int i = 0; i < n; i++) { sum[i] = x1[i] + x2[i]; } return new DoubleMatrix1D(sum); } throw new IllegalArgumentException("Tried to add a " + m1.getClass() + " and " + m2.getClass()); } else if (m1 instanceof DoubleMatrix2D) { if (m2 instanceof DoubleMatrix2D) { final double[][] x1 = ((DoubleMatrix2D) m1).getData(); final double[][] x2 = ((DoubleMatrix2D) m2).getData(); final int n = x1.length; final int m = x1[0].length; Validate.isTrue(n == x2.length, "Can only add matrices of the same shape"); final double[][] sum = new double[n][x1[0].length]; for (int i = 0; i < n; i++) { Validate.isTrue(m == x2[i].length, "Can only add matrices of the same shape"); for (int j = 0; j < m; j++) { sum[i][j] = x1[i][j] + x2[i][j]; } } return new DoubleMatrix2D(sum); } throw new IllegalArgumentException("Tried to add a " + m1.getClass() + " and " + m2.getClass()); } throw new NotImplementedException(); }
From source file:net.jodah.failsafe.internal.actions.DelayedForAction.java
/** * Constructs a new action which will delay the specified action for the specified amount of time. * * @param expectation the expectation where to get the last recorded action to delay * @param name the name for this action/*ww w . j a v a 2 s .c o m*/ * @param delay the number of seconds to delay * @throws IllegalArgumentException if <code>delay</code> is negative */ DelayedForAction(ActionRegistry<R>.Expectation expectation, String name, int delay) { super(expectation, name); Validate.isTrue(delay >= 0, "number of seconds must not be negative"); this.delay = delay; }
From source file:com.hp.autonomy.aci.content.fieldtext.FieldTextWrapper.java
/** * Creates an immutable copy of the specified {@code FieldText} object. The copy is not backed by the original * object./* w w w . j a v a2 s. com*/ * * @param fieldText The object to copy. Must be non-null. */ public FieldTextWrapper(final FieldText fieldText) { Validate.notNull(fieldText, "FieldText must not be null"); this.fieldText = fieldText.toString(); this.size = fieldText.size(); Validate.notNull(this.fieldText, "FieldText string must not be null"); Validate.isTrue(size >= 0, "FieldText size must be non-negative"); }
From source file:com.opengamma.analytics.financial.model.finitedifference.CrankNicolsonFiniteDifference2D.java
/** * Sets up a scheme that is the weighted average of an explicit and an implicit scheme * @param theta The weight. theta = 0 - fully explicit, theta = 0.5 - Crank-Nicolson, theta = 1.0 - fully implicit *///from w w w . java2s. com public CrankNicolsonFiniteDifference2D(final double theta) { Validate.isTrue(theta >= 0 && theta <= 1.0, "theta must be in the range 0 to 1"); _theta = theta; }
From source file:de.xaniox.heavyspleef.core.event.EventListenerMethod.java
@SuppressWarnings("unchecked") public EventListenerMethod(Object instance, Method method) { this.instance = instance; this.method = method; if (!method.isAccessible()) { method.setAccessible(true);//www. ja va 2 s .co m } subscribe = method.getAnnotation(Subscribe.class); Class<?>[] parameters = method.getParameterTypes(); Validate.isTrue(parameters.length == 1, "method must have only one parameter which must be a subtype of Event"); Class<?> eventClass = parameters[0]; Validate.isTrue(Event.class.isAssignableFrom(eventClass), "First parameter of method must be a subtype of Event"); this.eventClass = (Class<? extends Event>) eventClass; }
From source file:com.opengamma.analytics.financial.equity.future.derivative.EquityFuture.java
/** * //from w ww . ja v a 2 s. com * @param timeToExpiry time (in years as a double) until the date-time at which the reference index is fixed * @param timeToSettlement time (in years as a double) until the date-time at which the contract is settled * @param strike Set strike price at trade time. Note that we may handle margin by resetting this at the end of each trading day * @param currency The reporting currency of the future * @param unitAmount The unit value per tick, in given currency */ public EquityFuture(final double timeToExpiry, final double timeToSettlement, final double strike, final Currency currency, final double unitAmount) { // TODO Case - Validate!!! Validate.isTrue(unitAmount > 0, "point value must be positive"); _timeToExpiry = timeToExpiry; _timeToSettlement = timeToSettlement; _strike = strike; _unitAmount = unitAmount; _currency = currency; }
From source file:com.opengamma.analytics.math.integration.GaussianQuadratureIntegrator1D.java
/** * @param n The number of sample points to be used in the integration, not negative or zero * @param generator The generator of weights and abscissas *//*from ww w .ja v a 2 s. c om*/ public GaussianQuadratureIntegrator1D(final int n, final QuadratureWeightAndAbscissaFunction generator) { Validate.isTrue(n > 0, "number of intervals must be > 0"); Validate.notNull(generator, "generating function"); _n = n; _generator = generator; }
From source file:com.opengamma.analytics.math.statistics.descriptive.SampleNormalizedCentralMomentCalculator.java
/** * @param x The array of data, not null. Must contain at least two data points. * @return The normalized sample central moment. *//*from w ww . j a v a 2s . c o m*/ @Override public Double evaluate(final double[] x) { Validate.notNull(x); Validate.isTrue(x.length >= 2, "Need at least 2 data points to calculate normalized central moment"); if (_n == 0) { return 1.; } return _moment.evaluate(x) / Math.pow(STD_DEV.evaluate(x), _n); }