List of usage examples for org.apache.commons.lang Validate noNullElements
public static void noNullElements(Collection collection, String message)
Validate an argument, throwing IllegalArgumentException
if the argument Collection has null
elements or is null
.
Validate.noNullElements(myCollection, "The collection must not contain null elements");
If the collection is null then the message in the exception is 'The validated object is null'.
From source file:ValidateExampleV1.java
public static void main(String args[]) { int i = 35;//from w w w.java2 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.analytics.financial.interestrate.capletstripping.CapFloorDecomposer.java
public static SimpleOptionData[] toOptions(final CapFloorIbor[] caplets, final YieldCurveBundle ycb) { Validate.noNullElements(caplets, "null caplets"); Validate.notNull(ycb, "null yield curves"); final int n = caplets.length; SimpleOptionData[] options = new SimpleOptionData[n]; for (int i = 0; i < n; i++) { final YieldAndDiscountCurve discountCurve = ycb.getCurve(caplets[i].getFundingCurveName()); double fwd = caplets[i].accept(PRC, ycb); double t = caplets[i].getFixingTime(); // Vol is at fixing time, discounting from payment. This included the year fraction double df = discountCurve.getDiscountFactor(caplets[i].getPaymentTime()) * caplets[i].getPaymentYearFraction(); options[i] = new SimpleOptionData(fwd, caplets[i].getStrike(), t, df, caplets[i].isCap()); }//from ww w. j a va2s . co m return options; }
From source file:com.opengamma.analytics.math.function.Function1D.java
/** * Implementation of the interface. This method only uses the first argument. * @param x The list of inputs into the function, not null and no null elements * @return The value of the function/*from w w w. j a v a2s . co m*/ */ @Override public T evaluate(final S... x) { Validate.noNullElements(x, "Parameter list"); Validate.notEmpty(x, "parameter list"); if (x.length > 1) { throw new IllegalArgumentException("Array had more than one element"); } return evaluate(x[0]); }
From source file:com.opengamma.analytics.financial.riskfactor.TaylorExpansionMultiplierCalculator.java
public static double getValue(final Map<UnderlyingType, Double> underlyingData, final Underlying underlying) { Validate.notNull(underlying, "underlying"); Validate.notNull(underlyingData, "underlying data"); Validate.notEmpty(underlyingData, "underlying data"); Validate.noNullElements(underlyingData.keySet(), "underlying data keys"); Validate.noNullElements(underlyingData.values(), "underlying data values"); if (underlying instanceof NthOrderUnderlying) { final NthOrderUnderlying nthOrder = (NthOrderUnderlying) underlying; final int n = nthOrder.getOrder(); if (n == 0) { return 1; }// w w w . ja v a2s .c om final UnderlyingType type = nthOrder.getUnderlying(); Validate.isTrue(underlyingData.containsKey(type)); final double value = Math.pow(underlyingData.get(type), n); return value * getMultiplier(underlying); } else if (underlying instanceof MixedOrderUnderlying) { final MixedOrderUnderlying mixedOrder = (MixedOrderUnderlying) underlying; Double result = null; double multiplier; for (final NthOrderUnderlying underlyingOrder : mixedOrder.getUnderlyingOrders()) { if (result == null) { result = getValue(underlyingData, underlyingOrder); } else { multiplier = getValue(underlyingData, underlyingOrder); result = result * multiplier; } } if (result != null) { return result; } } throw new IllegalArgumentException( "Order was neither NthOrderUnderlying nor MixedOrderUnderlying: have " + underlying.getClass()); }
From source file:com.opengamma.financial.convention.StubCalculator.java
/** * Calculates the start stub type from a schedule, number of payments per year and the end of month flag. * <p>/* w w w . j av a2 s . c om*/ * The {@code DateProvider[]} argument allows callers to pass in arrays of any class * that implements {@code DateProvider}, such as {@code LocalDate[]}. * * @param schedule the schedule, at least size 2, not null * @param paymentsPerYear the number of payments per year, one, two, three, four, six or twelve * @param isEndOfMonthConvention whether to use end of month rules * @return the stub type, not null */ public static StubType getStartStubType(final LocalDate[] schedule, final double paymentsPerYear, final boolean isEndOfMonthConvention) { Validate.notNull(schedule, "schedule"); Validate.noNullElements(schedule, "schedule"); Validate.isTrue(paymentsPerYear > 0); Validate.isTrue(12 % paymentsPerYear == 0); final int months = (int) (12 / paymentsPerYear); final LocalDate first = schedule[0]; final LocalDate second = schedule[1]; LocalDate date; if (isEndOfMonthConvention && second.equals(second.with(lastDayOfMonth()))) { date = second.minusMonths(months); date = date.with(lastDayOfMonth()); } else { date = second.minusMonths(months); } if (date.equals(first)) { return StubType.NONE; } if (date.isBefore(first)) { return StubType.SHORT_START; } return StubType.LONG_START; }
From source file:com.opengamma.financial.convention.daycount.AccruedInterestCalculator.java
/** * Calculates the accrued interest for a {@code ZonedDateTime}. * //from ww w. ja va 2 s . c o m * @param dayCount the day count convention, not null * @param settlementDate the settlement date, not null * @param nominalDates the nominalDates, not null, no null elements * @param coupon the coupon value * @param paymentsPerYear the number of payments per year, one, two, three, four, six or twelve * @param isEndOfMonthConvention whether to use end of month rules * @param exDividendDays the number of ex-dividend days * @param calendar The working day calendar to be used in calculating ex-dividend dates, not null * @return the accrued interest */ public static double getAccruedInterest(final DayCount dayCount, final ZonedDateTime settlementDate, final ZonedDateTime[] nominalDates, final double coupon, final int paymentsPerYear, final boolean isEndOfMonthConvention, final int exDividendDays, final Calendar calendar) { Validate.notNull(dayCount, "day-count"); Validate.notNull(settlementDate, "date"); Validate.noNullElements(nominalDates, "nominalDates"); Validate.notNull(calendar, "calendar"); Validate.isTrue(paymentsPerYear > 0); Validate.isTrue(exDividendDays >= 0); final int i = Arrays.binarySearch(nominalDates, settlementDate); if (i > 0) { return 0; } final int index = -i - 2; final int length = nominalDates.length; Validate.isTrue(index >= 0, "Settlement date is before first accrual date"); Validate.isTrue(index < length, "Settlement date is after maturity date"); final double accruedInterest = getAccruedInterest(dayCount, index, length, nominalDates[index], settlementDate, nominalDates[index + 1], coupon, paymentsPerYear, isEndOfMonthConvention); ZonedDateTime exDividendDate = nominalDates[index + 1]; for (int j = 0; j < exDividendDays; j++) { while (!calendar.isWorkingDay(exDividendDate.toLocalDate())) { exDividendDate = exDividendDate.minusDays(1); } exDividendDate = exDividendDate.minusDays(1); } if (exDividendDays != 0 && exDividendDate.isBefore(settlementDate)) { return accruedInterest - coupon; } return accruedInterest; }
From source file:com.opengamma.analytics.financial.pnl.SensitivityAndReturnDataBundle.java
public SensitivityAndReturnDataBundle(final Sensitivity<?> sensitivity, final double value, final Map<UnderlyingType, DoubleTimeSeries<?>> underlyingReturnTS) { Validate.notNull(sensitivity, "sensitivity"); Validate.notNull(underlyingReturnTS, "underlying returns"); Validate.notEmpty(underlyingReturnTS, "underlying returns"); Validate.noNullElements(underlyingReturnTS.keySet(), "underlying return key set"); Validate.noNullElements(underlyingReturnTS.values(), "underlying return values"); _underlyings = sensitivity.getUnderlyingTypes(); Validate.isTrue(_underlyings.size() == underlyingReturnTS.size()); Validate.isTrue(_underlyings.containsAll(underlyingReturnTS.keySet())); _sensitivity = sensitivity;/*ww w . j a va 2 s. c o m*/ _value = value; _underlyingReturnTS = underlyingReturnTS; }
From source file:net.daboross.bukkitdev.skywars.api.events.GameEndEvent.java
public GameEndEvent(SkyWars plugin, SkyGame game, List<Player> players) { Validate.notNull(game, "Game cannot be null"); Validate.noNullElements(players, "No players can be null"); this.plugin = plugin; this.game = game; this.alivePlayers = Collections.unmodifiableList(players); }
From source file:fr.ribesg.bukkit.api.chat.Hover.java
/** * Builds a new Hover of type {@link Type#SHOW_TEXT}. * * @param lines the text//www . j ava 2s. com * * @return a new Hover of type SHOW_TEXT */ public static Hover of(final String... lines) { Validate.notEmpty(lines, "lines can't be empty"); Validate.noNullElements(lines, "lines can't contain null elements"); // TODO Support \n in Strings here if wanted return new Hover(Type.SHOW_TEXT, lines.clone()); }
From source file:net.daboross.bukkitdev.skywars.api.events.GameStartEvent.java
public GameStartEvent(SkyWars plugin, SkyGame newGame, List<Player> players) { Validate.notNull(plugin, "Plugin cannot be null"); Validate.notNull(newGame, "Game cannot be null"); Validate.noNullElements(players, "No players can be null"); this.plugin = plugin; this.newGame = newGame; this.players = Collections.unmodifiableList(players); }