List of usage examples for org.apache.commons.lang Validate notNull
public static void notNull(Object object, String message)
Validate an argument, throwing IllegalArgumentException
if the argument is null
.
Validate.notNull(myObject, "The object must not be null");
From source file:com.opengamma.analytics.financial.model.volatility.smile.function.HestonModelData.java
public HestonModelData(final double[] parameters) { Validate.notNull(parameters, "null parameters"); Validate.isTrue(parameters.length == NUM_PARAMETERS, "number of parameters wrong"); Validate.isTrue(parameters[0] >= 0.0, "kappa must be >= 0"); Validate.isTrue(parameters[1] >= 0.0, "theta must be >= 0"); Validate.isTrue(parameters[2] >= 0.0, "vol0 must be >= 0"); Validate.isTrue(parameters[3] >= 0.0, "omega must be >= 0"); Validate.isTrue(parameters[4] >= -1.0 && parameters[4] <= 1.0, "rho must be >= -1 && <= 1"); _parameters = new double[NUM_PARAMETERS]; System.arraycopy(parameters, 0, _parameters, 0, NUM_PARAMETERS); }
From source file:com.opengamma.analytics.financial.interestrate.InterestRateCurveSensitivityUtils.java
/** * Takes a list of curve sensitivities (i.e. an unordered list of pairs of times and sensitivities) and returns a list order by ascending * time, and with sensitivities that occur at the same time netted (zero net sensitivities are removed) * @param old An unordered list of pairs of times and sensitivities * @param relTol Relative tolerance - if the net divided by gross sensitivity is less than this it is ignored/removed * @param absTol Absolute tolerance - is the net sensitivity is less than this it is ignored/removed * @return A time ordered netted list//from w ww .j ava 2s.c o m */ static final List<DoublesPair> clean(final List<DoublesPair> old, final double relTol, final double absTol) { Validate.notNull(old, "null list"); Validate.isTrue(relTol >= 0.0 && absTol >= 0.0); if (old.size() == 0) { return new ArrayList<DoublesPair>(); } final List<DoublesPair> res = new ArrayList<DoublesPair>(); final DoublesPair[] sort = old.toArray(new DoublesPair[] {}); Arrays.sort(sort, FirstThenSecondDoublesPairComparator.INSTANCE); final DoublesPair pairOld = sort[0]; double tOld = pairOld.first; double sum = pairOld.getSecond(); double scale = Math.abs(sum); double t = tOld; for (int i = 1; i < sort.length; i++) { final DoublesPair pair = sort[i]; t = pair.first; if (t > tOld) { if (Math.abs(sum) > absTol && Math.abs(sum) / scale > relTol) { res.add(new DoublesPair(tOld, sum)); } tOld = t; sum = pair.getSecondDouble(); scale = Math.abs(sum); } else { sum += pair.getSecondDouble(); scale += Math.abs(pair.getSecondDouble()); } } if (Math.abs(sum) > absTol && Math.abs(sum) / scale > relTol) { res.add(new DoublesPair(t, sum)); } return res; }
From source file:com.relicum.ipsum.Reflection.ReflectionUtil.java
/** * Attempts to get the NMS (net.minecraft.server) class with this name. * While this does cross versions, it's important to note that this class * may have been changed or removed.// www. j a va2s. com * * @param name Class Name * @return NMS class, or null if none exists */ public static final Class<?> getNMSClass(String name) { Validate.notNull(name, "name cannot be null!"); if (PACKAGE == null) { // Lazy-load PACKAGE String serverPackage = Bukkit.getServer().getClass().getPackage().getName(); PACKAGE = serverPackage.substring(serverPackage.lastIndexOf('.') + 1); } name = "net.minecraft.server." + PACKAGE + "." + name; try { return Class.forName(name); } catch (Throwable ex) { } return null; }
From source file:com.opengamma.analytics.financial.interestrate.NelsonSiegelSvennsonBondCurveModel.java
public ParameterizedFunction<Double, DoubleMatrix1D, Double> getParameterizedFunction() { return new ParameterizedFunction<Double, DoubleMatrix1D, Double>() { @Override//from w ww . ja v a2 s .c o m public Double evaluate(final Double t, final DoubleMatrix1D parameters) { Validate.notNull(t, "t"); Validate.notNull(parameters, "parameters"); Validate.isTrue(parameters.getNumberOfElements() == 6); final double beta0 = parameters.getEntry(0); final double beta1 = parameters.getEntry(1); final double beta2 = parameters.getEntry(2); final double lambda1 = parameters.getEntry(3); final double beta3 = parameters.getEntry(4); final double lambda2 = parameters.getEntry(5); final double x1 = t / lambda1; final double x2 = (1 - Math.exp(-x1)) / x1; final double x3 = t / lambda2; final double x4 = (1 - Math.exp(-x3)) / x3; return beta0 + beta1 * x2 + beta2 * (x2 - Math.exp(-x1)) + beta3 * (x4 - Math.exp(-x3)); } public Object writeReplace() { return new InvokedSerializedForm(NelsonSiegelSvennsonBondCurveModel.class, "getParameterizedFunction"); } }; }
From source file:com.opengamma.analytics.math.statistics.descriptive.GeometricMeanCalculator.java
/** * @param x The array of data, not null or empty * @return The geometric mean/* w ww . j a v a 2 s . c om*/ */ @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; double mult = x[0]; for (int i = 1; i < n; i++) { mult *= x[i]; } return Math.pow(mult, 1. / n); }
From source file:com.opengamma.financial.analytics.fixedincome.YieldCurveNodeSensitivityDataBundle.java
public YieldCurveNodeSensitivityDataBundle(final Currency currency, final DoubleLabelledMatrix1D labelledMatrix, final String yieldCurveName) { Validate.notNull(labelledMatrix, "labelled matrix array"); Validate.notNull(currency, "currency"); Validate.notNull(yieldCurveName, "yield curve name array"); _labelledMatrix = labelledMatrix;/*from w w w. j a va 2s . c o m*/ _currency = currency; _yieldCurveName = yieldCurveName; }
From source file:com.opengamma.analytics.financial.timeseries.analysis.DoubleTimeSeriesStatisticsCalculator.java
@Override public Double evaluate(final DoubleTimeSeries<?>... x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0);//from w ww. j av a2 s. c om ArgumentChecker.noNulls(x, "x"); final int n = x.length; final double[][] arrays = new double[n][]; for (int i = 0; i < n; i++) { arrays[i] = x[i].valuesArrayFast(); } return _statistic.evaluate(arrays); }
From source file:com.opengamma.analytics.financial.var.parametric.DeltaGammaCovarianceMatrixMeanCalculator.java
public DeltaGammaCovarianceMatrixMeanCalculator(final MatrixAlgebra algebra) { Validate.notNull(algebra, "algebra"); _algebra = algebra; }
From source file:com.opengamma.financial.analytics.conversion.SimpleFutureConverter.java
@Override public SimpleInstrumentDefinition<?> visitFXFutureSecurity(final FXFutureSecurity security) { Validate.notNull(security, "security"); final ZonedDateTime expiry = security.getExpiry().getExpiry(); final double referencePrice = 0; return new SimpleFXFutureDefinition(expiry, expiry, referencePrice, security.getNumerator(), security.getDenominator(), security.getUnitAmount()); }
From source file:com.opengamma.analytics.financial.model.finitedifference.SecondDerivativeBoundaryCondition2D.java
public SecondDerivativeBoundaryCondition2D(final Surface<Double, Double, Double> boundarySecondDeriviative, double boundaryLevel) { Validate.notNull(boundarySecondDeriviative, "boundaryValue "); _f = boundarySecondDeriviative;/*from ww w . jav a 2 s .co m*/ _level = boundaryLevel; }