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.github.fritaly.graphml4j.Utils.java
/** * Decodes the given hexadecimal string (like "#RRGGBBAA" or "#RRGGBB" * (whether the transparency is set to 0)) into an instance of {@link Color} * .//from w ww .ja va 2s . c o m * * @param value * a string representing the encoded color.Can't be null. * @return a {@link Color}. */ static Color decode(String value) { Validate.notNull(value, "The given encoded value is null"); if (value.length() == 9) { final int i = Integer.decode(value).intValue(); return new Color((i >> 24) & 0xFF, (i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF); } return Color.decode(value); }
From source file:com.opengamma.analytics.financial.forex.derivative.ForexSwap.java
/** * Constructor from the two Forex legs./*from ww w . j av a 2 s. co m*/ * @param nearLeg The near leg. * @param farLeg The far leg. */ public ForexSwap(final Forex nearLeg, final Forex farLeg) { Validate.notNull(nearLeg, "Near leg"); Validate.notNull(farLeg, "Far leg"); this._nearLeg = nearLeg; this._farLeg = farLeg; }
From source file:com.opengamma.analytics.financial.var.parametric.DeltaCovarianceMatrixStandardDeviationCalculator.java
@Override public Double evaluate(final Map<Integer, ParametricVaRDataBundle> data) { Validate.notNull(data, "data"); final ParametricVaRDataBundle firstOrderData = data.get(1); Validate.notNull(firstOrderData, "first order data"); final Matrix<?> delta = firstOrderData.getSensitivities(); final int s1 = delta.getNumberOfElements(); Validate.isTrue(s1 > 0, "Value delta vector contained no data"); final DoubleMatrix2D covariance = firstOrderData.getCovarianceMatrix(); return Math.sqrt(_algebra.getInnerProduct(delta, _algebra.multiply(covariance, delta))); }
From source file:com.opengamma.analytics.math.rootfinding.VectorRootFinder.java
/** * {@inheritDoc}//from ww w . j a v a 2s. c o m * Vector root finders only need a single starting point; if more than one is provided, the first is used and any other points ignored. */ @Override public DoubleMatrix1D getRoot(final Function1D<DoubleMatrix1D, DoubleMatrix1D> function, DoubleMatrix1D... startingPoint) { Validate.notNull(startingPoint, "starting point"); return getRoot(function, startingPoint[0]); }
From source file:com.opengamma.analytics.math.rootfinding.CubicRootFinder.java
/** * {@inheritDoc}/* w ww . jav a 2 s .c o m*/ * @throws IllegalArgumentException If the function is not cubic */ @Override public ComplexNumber[] getRoots(final RealPolynomialFunction1D function) { Validate.notNull(function, "function"); final double[] coefficients = function.getCoefficients(); Validate.isTrue(coefficients.length == 4, "Function is not a cubic"); final double divisor = coefficients[3]; final double a = coefficients[2] / divisor; final double b = coefficients[1] / divisor; final double c = coefficients[0] / divisor; final double aSq = a * a; final double q = (aSq - 3 * b) / 9; final double r = (2 * a * aSq - 9 * a * b + 27 * c) / 54; final double rSq = r * r; final double qCb = q * q * q; final double constant = a / 3; if (rSq < qCb) { final double mult = -2 * Math.sqrt(q); final double theta = Math.acos(r / Math.sqrt(qCb)); return new ComplexNumber[] { new ComplexNumber(mult * Math.cos(theta / 3) - constant, 0), new ComplexNumber(mult * Math.cos((theta + TWO_PI) / 3) - constant, 0), new ComplexNumber(mult * Math.cos((theta - TWO_PI) / 3) - constant, 0) }; } final double s = -Math.signum(r) * Math.cbrt(Math.abs(r) + Math.sqrt(rSq - qCb)); final double t = CompareUtils.closeEquals(s, 0, 1e-16) ? 0 : q / s; final double sum = s + t; final double real = -0.5 * sum - constant; final double imaginary = Math.sqrt(3) * (s - t) / 2; return new ComplexNumber[] { new ComplexNumber(sum - constant, 0), new ComplexNumber(real, imaginary), new ComplexNumber(real, -imaginary) }; }
From source file:com.stealthyone.mcb.mcml.MCMLClickEventURL.java
MCMLClickEventURL(String rawText) { Validate.notNull(rawText, "Raw text cannot be null."); if (rawText.length() == 6) { throw new IllegalArgumentException("URL click event must have input."); }//from ww w .j a va 2 s .c o m url = rawText.substring(5, rawText.length()); }
From source file:com.opengamma.analytics.financial.schedule.ScheduleFactory.java
public static LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final int periodsPerYear, final boolean endOfMonth, final boolean fromEnd, final boolean generateRecursive) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); Validate.isTrue(periodsPerYear > 0); LocalDate[] result = null;/*from www .j av a 2 s . c o m*/ if (periodsPerYear == 1) { if (endOfMonth) { if (fromEnd && endDate.getDayOfMonth() == endDate.lengthOfMonth()) { result = ScheduleCalculatorFactory.ANNUAL_EOM_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else if (startDate.getDayOfMonth() == startDate.lengthOfMonth()) { result = ScheduleCalculatorFactory.ANNUAL_EOM_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else { result = ScheduleCalculatorFactory.ANNUAL_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } } else { result = ScheduleCalculatorFactory.ANNUAL_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } } else if (periodsPerYear == 2) { if (endOfMonth) { if (fromEnd && endDate.getDayOfMonth() == endDate.lengthOfMonth()) { result = ScheduleCalculatorFactory.SEMI_ANNUAL_EOM_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else if (startDate.getDayOfMonth() == startDate.lengthOfMonth()) { result = ScheduleCalculatorFactory.SEMI_ANNUAL_EOM_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else { result = ScheduleCalculatorFactory.SEMI_ANNUAL_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } } else { result = ScheduleCalculatorFactory.SEMI_ANNUAL_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } } else if (periodsPerYear == 4) { if (endOfMonth) { if (fromEnd && endDate.getDayOfMonth() == endDate.lengthOfMonth()) { result = ScheduleCalculatorFactory.QUARTERLY_EOM_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else if (startDate.getDayOfMonth() == startDate.lengthOfMonth()) { result = ScheduleCalculatorFactory.QUARTERLY_EOM_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else { result = ScheduleCalculatorFactory.QUARTERLY_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } } else { result = ScheduleCalculatorFactory.QUARTERLY_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } } else if (periodsPerYear == 12) { if (endOfMonth) { if (fromEnd && endDate.getDayOfMonth() == endDate.lengthOfMonth()) { result = ScheduleCalculatorFactory.END_OF_MONTH_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else if (startDate.getDayOfMonth() == startDate.lengthOfMonth()) { result = ScheduleCalculatorFactory.END_OF_MONTH_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else { result = ScheduleCalculatorFactory.MONTHLY_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } } else { result = ScheduleCalculatorFactory.MONTHLY_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } } else if (periodsPerYear == 52) { if (endOfMonth) { throw new IllegalArgumentException("Cannot get EOM series for weekly frequency"); } result = ScheduleCalculatorFactory.WEEKLY_CALCULATOR.getSchedule(startDate, endDate, fromEnd, generateRecursive); } else if (periodsPerYear == 365 || periodsPerYear == 366) { if (endOfMonth) { throw new IllegalArgumentException("Cannot get EOM series for daily frequency"); } result = ScheduleCalculatorFactory.DAILY_CALCULATOR.getSchedule(startDate, endDate); } Validate.notNull(result, "result"); return result; }
From source file:com.stealthyone.mcb.mcml.MCMLHoverEventText.java
MCMLHoverEventText(String rawText) { Validate.notNull(rawText, "Raw text cannot be null."); if (rawText.length() == 6) { throw new IllegalArgumentException("Text hover event must have input."); }/*from ww w . ja v a 2 s.c o m*/ text = rawText.substring(5, rawText.length() - 1); }
From source file:com.opengamma.analytics.math.function.FunctionND.java
/** * Implementation of the interface. //www .j av a 2 s . co m * @param x The list of inputs into the function, not null * @return The value of the function * @throws IllegalArgumentException If the number of arguments is not equal to the dimension */ @Override public T evaluate(final S... x) { Validate.notNull(x, "x"); if (x.length != _dimension) { throw new IllegalArgumentException( "Number of variables " + x.length + " does not match dimension of function " + _dimension); } return evaluateFunction(x); }
From source file:net.daboross.bukkitdev.skywars.events.events.PlayerDeathInArenaInfo.java
public PlayerDeathInArenaInfo(final int gameId, final Player killed) { Validate.notNull(killed, "Killed cannot be null"); this.gameId = gameId; this.killed = killed; }