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.interpolation.DistanceCalculator.java
public static double getDistance(final double[] x1, final double[] x2) { final int dim = x1.length; Validate.isTrue(dim == x2.length, "different dimensions"); double sum = 0; double diff;//from www. jav a 2s. c o m for (int i = 0; i < dim; i++) { diff = x1[i] - x2[i]; sum += diff * diff; } return Math.sqrt(sum); }
From source file:com.opengamma.analytics.financial.timeseries.util.TimeSeriesDataTestUtils.java
/** * Tests that the time series is not null or empty * @param ts The time series/*from w w w . j a va2s. c o m*/ * @throws IllegalArgumentException If the time series is null or empty */ public static void testNotNullOrEmpty(final DoubleTimeSeries<?> ts) { Validate.notNull(ts, "time series"); Validate.isTrue(!ts.isEmpty(), "time series"); }
From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java
public static double acosh(final double x) { final double y = x * x - 1; Validate.isTrue(y >= 0, "|x|>=1.0 for real solution"); return Math.log(x + Math.sqrt(x * x - 1)); }
From source file:com.jaxio.celerio.util.PackageUtil.java
static public String assemblePackage(String... packageChunks) { StringBuilder sb = new StringBuilder(); for (String packageChunk : packageChunks) { if (stripToNull(packageChunk) != null) { if (sb.length() > 0) { sb.append("."); }/*from www. j a v a 2 s. co m*/ sb.append(packageChunk.trim()); } } Validate.isTrue(sb.length() > 0, "An assembled package is null or empty!"); return sb.toString(); }
From source file:com.github.fritaly.svngraph.Utils.java
public static void validateElement(Element element, String name) { Validate.notNull(element, "The given DOM element is null"); Validate.isTrue(element.getNodeName().equals(name), String.format("The name of the given element isn't valid (Expected: '%s', Actual: '%s'", name, element.getNodeName())); }
From source file:com.opengamma.analytics.financial.model.volatility.surface.Strike.java
public Strike(final double value) { Validate.isTrue(value >= 0, "negative strike"); _value = value; }
From source file:com.opengamma.analytics.financial.model.volatility.surface.Moneyness.java
public Moneyness(final double value) { Validate.isTrue(value >= 0, "negative moneyness"); _value = value; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sum.java
/** * Sums over selected indices of a given vector * @param v the vector over which the sum will be undertaken * @param idx the indices to be included in the sum * @return the sum of dereferenced indices of vector v *///from w w w . j a v a2 s . com public static double overIndices(double[] v, int[] idx) { Validate.notNull(v); Validate.notNull(idx); final int n = v.length; Validate.isTrue(Max.value(idx) < n, "Index out of range. Max of indexes is " + Max.value(idx) + " whereas vector to dereference is length " + n); Validate.isTrue(Min.value(idx) > -1, "Negative index dereference requested on vector"); double tmp = 0; final int idxn = idx.length; for (int i = 0; i < idxn; i++) { tmp += v[idx[i]]; } return tmp; }
From source file:com.opengamma.analytics.math.matrix.DoubleMatrixUtils.java
/** * The identity matrix is a matrix with diagonal elements equals to one and zero elsewhere. * @param dimension The dimension of matrix required, not negative or zero * @return The identity matrix//from w w w . j a va 2s . c o m */ public static DoubleMatrix2D getIdentityMatrix2D(final int dimension) { Validate.isTrue(dimension >= 0, "dimension must be >= 0"); if (dimension == 0) { return DoubleMatrix2D.EMPTY_MATRIX; } if (dimension == 1) { return new DoubleMatrix2D(new double[][] { new double[] { 1 } }); } final double[][] data = new double[dimension][dimension]; for (int i = 0; i < dimension; i++) { data[i][i] = 1; } return new DoubleMatrix2D(data); }
From source file:com.opengamma.analytics.financial.model.finitedifference.MeshingFunction.java
protected MeshingFunction(final int nPoints) { Validate.isTrue(nPoints > 1, "Need more than 1 point for a mesh"); _nPoints = nPoints; }