List of usage examples for org.apache.commons.lang Validate isTrue
public static void isTrue(boolean expression)
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 ); Validate.isTrue( myObject.isOk() );
The message in the exception is 'The validated expression is false'.
From source file:ValidateExampleV1.java
public static void main(String args[]) { int i = 35;//w w w .ja v a2 s .c om Validate.isTrue(i > 30); // Passes ok // Validate.isTrue(i > 40, "Invalid value: ", i); // throws custom Exception List data = new ArrayList(); // Validate.notEmpty(data, "Collection cannot be empty"); // throws custom Exception data.add(null); Validate.noNullElements(data, "Collection contains null elements"); // throws custom Exception }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.View.java
/** * Looks up the values in v at positions given by index and returns them! * @param v the vector//w w w. j a v a 2 s. c o m * @param index the indices to look up in the vector * @return tmp the values looked up by index. i.e. values[index]; */ public static double[] byIndex(double[] v, int[] index) { Validate.notNull(v); Validate.notNull(index); Validate.isTrue(Max.value(index) < v.length); Validate.isTrue(Min.value(index) > -1); final int idxn = index.length; double[] tmp = new double[idxn]; for (int i = 0; i < idxn; i++) { tmp[i] = v[index[i]]; } return tmp; }
From source file:com.opengamma.analytics.math.FunctionUtils.java
public static int toTensorIndex(final int[] indices, final int[] dimensions) { Validate.notNull(indices, "indices"); Validate.notNull(dimensions, "dimensions"); final int dim = indices.length; Validate.isTrue(dim == dimensions.length); int sum = 0;/*from w ww. j a v a 2 s .co m*/ int product = 1; for (int i = 0; i < dim; i++) { Validate.isTrue(indices[i] < dimensions[i], "index out of bounds"); sum += indices[i] * product; product *= dimensions[i]; } return sum; }
From source file:com.opengamma.analytics.financial.timeseries.util.TimeSeriesDataTestUtils.java
/** * Tests that the time series has a minimum amount of data * @param ts The time series/* w w w .j a va 2 s . co m*/ * @param minLength The minimum size * @throws IllegalArgumentException If the time series is null, empty, or contains fewer elements than the minimum size, if the minimum size is less than zero */ public static void testTimeSeriesSize(final DoubleTimeSeries<?> ts, final int minLength) { testNotNullOrEmpty(ts); Validate.isTrue(minLength >= 0); Validate.isTrue(ts.size() >= minLength, "time series must contain at least " + minLength + " values"); }
From source file:com.opengamma.analytics.math.ParallelArrayBinarySort.java
/** * Sort the content of keys and values simultaneously so that * both match the correct ordering. Alters the arrays in place * @param keys The keys//from w w w .j av a 2s . co m * @param values The values */ public static void parallelBinarySort(final double[] keys, final double[] values) { Validate.notNull(keys, "x data"); Validate.notNull(values, "y data"); Validate.isTrue(keys.length == values.length); final int n = keys.length; dualArrayQuickSort(keys, values, 0, n - 1); }
From source file:hr.fer.spocc.lexer.action.SubactionFactory.java
public static synchronized Subaction getSubaction(SubactionType type) { Validate.notNull(type);/*from w w w .j a v a2 s .c o m*/ Validate.isTrue(type.isBuiltIn()); // check cache Subaction ret = BUILTIN_ACTIONS.get(type); if (ret != null) { return ret; } switch (type) { case ENTER_STATE: ret = new EnterStateSubaction(); break; case NEW_LINE: ret = new NewLineSubaction(); break; case TOKENIZE: ret = new TokenizeSubaction(); break; case TOKENIZE_FIRST: ret = new TokenizeFirstSubaction(); break; case SKIP: ret = new SkipSubaction(); break; default: throw new UnsupportedOperationException("Custom subactions are not yet implemented"); } // cache the action to avoid new object allocations BUILTIN_ACTIONS.put(type, ret); return ret; }
From source file:com.opengamma.analytics.financial.trade.OptionTradeData.java
public OptionTradeData(final double numberOfContracts, final double pointValue) { Validate.isTrue(pointValue > 0); _numberOfContracts = numberOfContracts; _pointValue = pointValue;//from www. ja v a 2 s. com }
From source file:com.opengamma.analytics.financial.covariance.VolatilityAnnualizingFunction.java
public VolatilityAnnualizingFunction(final double periodsPerYear) { Validate.isTrue(periodsPerYear > 0); _periodsPerYear = periodsPerYear; }
From source file:com.opengamma.analytics.math.function.special.LegendrePolynomialFunction.java
@Override public DoubleFunction1D[] getPolynomials(final int n) { Validate.isTrue(n >= 0); final DoubleFunction1D[] polynomials = new DoubleFunction1D[n + 1]; for (int i = 0; i <= n; i++) { if (i == 0) { polynomials[i] = getOne();//from w w w .j a v a 2s. co m } else if (i == 1) { polynomials[i] = getX(); } else { polynomials[i] = (polynomials[i - 1].multiply(getX()).multiply(2 * i - 1) .subtract(polynomials[i - 2].multiply(i - 1))).multiply(1. / i); } } return polynomials; }
From source file:com.opengamma.analytics.math.function.special.ChebyshevPolynomialOfFirstKindFunction.java
@Override public DoubleFunction1D[] getPolynomials(final int n) { Validate.isTrue(n >= 0); final DoubleFunction1D[] polynomials = new DoubleFunction1D[n + 1]; for (int i = 0; i <= n; i++) { if (i == 0) { polynomials[i] = getOne();/*from w w w . j a v a 2s . c om*/ } else if (i == 1) { polynomials[i] = getX(); } else { polynomials[i] = polynomials[i - 1].multiply(getX()).multiply(2).subtract(polynomials[i - 2]); } } return polynomials; }