List of usage examples for org.apache.commons.lang Validate notNull
public static void notNull(Object object)
Validate an argument, throwing IllegalArgumentException
if the argument is null
.
Validate.notNull(myObject);
The message in the exception is 'The validated object is null'.
From source file:com.gmail.gkovalechyn.automaticevents.parsing.IInteger.java
@Override public void setValue(Object value) { Validate.notNull(value); if (!(value instanceof Integer)) { throw new IllegalArgumentException("Incompatible types: Integer and " + value.getClass()); } else {/*from w w w . j a v a2 s.com*/ this.value = value; } }
From source file:com.opengamma.analytics.math.rootfinding.newton.JacobianDirectionFunction.java
public JacobianDirectionFunction(final Decomposition<?> decomposition) { Validate.notNull(decomposition); _decomposition = decomposition; }
From source file:com.opengamma.analytics.financial.model.interestrate.VasicekInterestRateModel.java
@Override public Function1D<VasicekDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time, final ZonedDateTime maturity) { Validate.notNull(time); Validate.notNull(maturity);//from ww w . j av a 2 s . co m return new Function1D<VasicekDataBundle, Double>() { @Override public Double evaluate(final VasicekDataBundle data) { Validate.notNull(data); final double lt = data.getLongTermInterestRate(); final double speed = data.getReversionSpeed(); final double dt = DateUtils.getDifferenceInYears(time, maturity); final double t = DateUtils.getDifferenceInYears(data.getDate(), time); final double sigma = data.getShortRateVolatility(t); final double r = data.getShortRate(t); final double sigmaSq = sigma * sigma; final double speedSq = speed * speed; final double rInfinity = lt - 0.5 * sigmaSq / speedSq; final double factor = 1 - Math.exp(-speed * dt); final double a = rInfinity * (factor / speed - dt) - sigmaSq * factor * factor / (4 * speedSq * speed); final double b = factor / speed; return Math.exp(a - r * b); } }; }
From source file:com.opengamma.analytics.math.rootfinding.newton.NewtonDefaultUpdateFunction.java
@Override public DoubleMatrix2D getUpdatedMatrix(final Function1D<DoubleMatrix1D, DoubleMatrix2D> jacobianFunction, DoubleMatrix1D x, final DoubleMatrix1D deltaX, final DoubleMatrix1D deltaY, final DoubleMatrix2D matrix) { Validate.notNull(jacobianFunction); Validate.notNull(x);/*w ww. j a va 2 s . c om*/ return jacobianFunction.evaluate(x); }
From source file:com.opengamma.analytics.math.matrix.DoubleMatrix1D.java
/** * @param data The data, not null/*from w w w . j a v a2 s.c o m*/ */ public DoubleMatrix1D(final Double[] data) { Validate.notNull(data); _elements = data.length; _data = new double[_elements]; for (int i = 0; i < _elements; i++) { _data[i] = data[i]; } }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Reverse.java
/** * Reverses a vector in place//w w w. j av a2 s . co m * @param v1 the vector to be reversed */ public static void inPlace(double[] v1) { Validate.notNull(v1); double tmp; final int half = v1.length / 2; final int len = v1.length - 1; for (int i = 0; i < half; i++) { tmp = v1[len - i]; v1[len - i] = v1[i]; v1[i] = tmp; } }
From source file:me.st28.flexseries.flexcore.util.TimeUtils.java
public static String translateSeconds(int seconds, TimeUtils.TimeFormat format) { Validate.notNull(format); if (seconds < 0) { throw new IllegalArgumentException("Seconds cannot be negative! (" + seconds + ")"); } else {//from w w w . j ava 2 s.co m StringBuilder returnString = new StringBuilder(); int minutes = seconds / 60; seconds -= minutes * 60; int hours = minutes / 60; minutes -= hours * 60; int days = hours / 24; hours -= days * 24; if (format == TimeUtils.TimeFormat.LONG) { if (days > 0) { returnString.append(days).append(days == 1 ? " day" : " days"); } if (hours > 0) { if (days > 0) { returnString.append(" "); } returnString.append(hours).append(hours == 1 ? " hour" : " hours"); } if (minutes > 0) { if (hours > 0) { returnString.append(" "); } returnString.append(minutes).append(minutes == 1 ? " minute" : " minutes"); } if (seconds > 0 || seconds == 0 && minutes == 0 && hours == 0 && days == 0) { if (minutes > 0) { returnString.append(" "); } returnString.append(seconds).append(seconds == 1 ? " second" : " seconds"); } } else if (format == TimeUtils.TimeFormat.SHORT) { if (days > 0) { returnString.append(Integer.toString(days).length() == 1 ? "0" : "" + days); } if (hours > 0) { if (days > 0) { returnString.append(":"); } returnString.append(Integer.toString(hours).length() == 1 ? "0" : "" + hours); } if (hours > 0) { returnString.append(":"); } returnString.append(Integer.toString(minutes).length() == 1 ? "0" : "" + minutes); if (minutes > 0) { returnString.append(":"); } returnString.append(Integer.toString(seconds).length() == 1 ? "0" : "" + seconds); } else { if (days > 0) { returnString.append(days).append("d"); } if (hours > 0) { returnString.append(hours).append("h"); } if (minutes > 0) { returnString.append(minutes).append("m"); } if (seconds > 0 || seconds == 0 && minutes == 0 && hours == 0 && days == 0) { returnString.append(seconds).append("s"); } } return returnString.toString(); } }
From source file:com.opengamma.analytics.math.linearalgebra.SVDecompositionColt.java
@Override public SVDecompositionResult evaluate(final DoubleMatrix2D x) { Validate.notNull(x); MatrixValidate.notNaNOrInfinite(x);/*from ww w . j a va 2s .c o m*/ final cern.colt.matrix.DoubleMatrix2D coltMatrix = ColtMathWrapper.wrap(x); final SingularValueDecomposition svd = new SingularValueDecomposition(coltMatrix); return new SVDecompositionColtResult(svd); }
From source file:com.opengamma.maths.lowlevelapi.functions.iss.IsInf.java
/** * Walks through a vector looking for positive infinity, if one is found the routine returns TRUE. * @param v the vector (with possible +Inf entries) * @return a boolean, TRUE if a +Inf is found in v, FALSE otherwise */// ww w . j a va2 s. c o m public static boolean anyPositive(double[] v) { Validate.notNull(v); boolean logical = false; final int len = v.length; for (int i = 0; i < len; i++) { if (v[i] == DOUBLEPINF) { logical = true; return logical; } } return logical; }
From source file:com.opengamma.analytics.financial.model.interestrate.HoLeeInterestRateModel.java
@Override public Function1D<StandardDiscountBondModelDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time, final ZonedDateTime maturity) { Validate.notNull(time); Validate.notNull(maturity);//from w ww .j a v a 2 s. co m return new Function1D<StandardDiscountBondModelDataBundle, Double>() { @Override public Double evaluate(final StandardDiscountBondModelDataBundle data) { Validate.notNull(data); final double t = DateUtils.getDifferenceInYears(data.getDate(), time); final double s = DateUtils.getDifferenceInYears(data.getDate(), maturity); final double b = s - t; final double sigma = data.getShortRateVolatility(t); final double rT = data.getShortRate(t); final double rS = data.getShortRate(s); final double pT = Math.exp(-rT * t); final double pS = Math.exp(-rS * s); final double dlnPdt = -rT; final double lnA = Math.log(pS / pT) - b * dlnPdt - 0.5 * sigma * sigma * b * b; return Math.exp(lnA - b * rT); } }; }