Example usage for org.apache.commons.lang Validate noNullElements

List of usage examples for org.apache.commons.lang Validate noNullElements

Introduction

In this page you can find the example usage for org.apache.commons.lang Validate noNullElements.

Prototype

public static void noNullElements(Collection collection, String message) 

Source Link

Document

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'.

Usage

From source file:fr.ribesg.bukkit.api.chat.Chat.java

/**
 * Broadcasts the provided {@link Message Message(s)} to
 * {@link Player Players} having the provided permission.
 *
 * @param permission a permission required to receive the message(s)
 * @param messages   the message(s) to send
 *
 * @see Server#broadcast(String, String)
 *//*from  www. j av  a 2s  .c  om*/
public static void broadcast(final String permission, final Message... messages) {
    Validate.notEmpty(permission, "The 'permission' argument should not be null nor empty");
    Validate.notEmpty(messages, "Please provide at least one Message");
    Validate.noNullElements(messages, "The 'messages' argument should not contain null values");
    final String[] mojangsons = new String[messages.length];
    for (int i = 0; i < messages.length; i++) {
        mojangsons[i] = Chat.toMojangson(messages[i]);
    }
    Chat.broadcast(permission, mojangsons);
}

From source file:com.opengamma.financial.convention.daycount.AccruedInterestCalculator.java

/**
 * Calculates the accrued interest for a {@code LocalDate}.
 * //from   w w  w. ja  va2s  .  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
 */
//TODO one where you can pass in array of coupons
public static double getAccruedInterest(final DayCount dayCount, final LocalDate settlementDate,
        final LocalDate[] nominalDates, final double coupon, final double 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;
    if (index < 0) {
        throw new IllegalArgumentException("Settlement date is before first accrual date");
    }
    if (index == length) {
        throw new IllegalArgumentException("Settlement date is after maturity date");
    }
    final ZonedDateTime previousCouponDate = nominalDates[index].atStartOfDay(ZoneOffset.UTC);
    final ZonedDateTime date = settlementDate.atStartOfDay(ZoneOffset.UTC);
    final ZonedDateTime nextCouponDate = nominalDates[index + 1].atStartOfDay(ZoneOffset.UTC);
    final double accruedInterest = getAccruedInterest(dayCount, index, length, previousCouponDate, date,
            nextCouponDate, coupon, paymentsPerYear, isEndOfMonthConvention);
    LocalDate exDividendDate = nominalDates[index + 1];
    for (int j = 0; j < exDividendDays; j++) {
        while (!calendar.isWorkingDay(exDividendDate)) {
            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.interestrate.PresentValueCalculator.java

@Override
public Double[] visit(final InstrumentDerivative[] derivative, final YieldCurveBundle curves) {
    Validate.notNull(derivative, "derivative");
    Validate.noNullElements(derivative, "derivative");
    Validate.notNull(curves, "curves");
    final Double[] output = new Double[derivative.length];
    for (int loopderivative = 0; loopderivative < derivative.length; loopderivative++) {
        output[loopderivative] = derivative[loopderivative].accept(this, curves);
    }/*from w  w  w .  j ava  2 s  . com*/
    return output;
}

From source file:com.vmware.identity.idm.IDPConfig.java

/**
 * @param tokenClaimGroupMappings/*from   ww w . j  a v  a2 s.com*/
 *           Cannot be null or empty; the collection of group sid lists cannot contain null.
 */
public void setTokenClaimGroupMappings(Map<TokenClaimAttribute, List<String>> tokenClaimGroupMappings) {
    Validate.notNull(tokenClaimGroupMappings, "Token claim group mappings is null.");
    Validate.noNullElements(tokenClaimGroupMappings.values(),
            "Token claim group mappings contains null group name list.");
    this.tokenClaimGroupMappings = tokenClaimGroupMappings;
}

From source file:com.opengamma.financial.convention.daycount.AccruedInterestCalculator.java

/**
 * Calculates the accrued interest for a {@code LocalDate}.
 * //  w  ww .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 index The index of the previous coupon in the nominalDates
 * @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 LocalDate settlementDate,
        final LocalDate[] nominalDates, final double coupon, final double paymentsPerYear,
        final boolean isEndOfMonthConvention, final int exDividendDays, final int index,
        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 length = nominalDates.length;
    Validate.isTrue(index >= 0 && index < length);
    final ZonedDateTime previousCouponDate = nominalDates[index].atStartOfDay(ZoneOffset.UTC);
    final ZonedDateTime date = settlementDate.atStartOfDay(ZoneOffset.UTC);
    final ZonedDateTime nextCouponDate = nominalDates[index + 1].atStartOfDay(ZoneOffset.UTC);
    double accruedInterest;
    if (date.isAfter(nextCouponDate)) {
        accruedInterest = 0;
    } else {
        accruedInterest = getAccruedInterest(dayCount, index, length, previousCouponDate, date, nextCouponDate,
                coupon, paymentsPerYear, isEndOfMonthConvention);
    }
    LocalDate exDividendDate = nominalDates[index + 1];
    for (int i = 0; i < exDividendDays; i++) {
        while (!calendar.isWorkingDay(exDividendDate)) {
            exDividendDate = exDividendDate.minusDays(1);
        }
        exDividendDate = exDividendDate.minusDays(1);
    }
    if (exDividendDays != 0 && exDividendDate.isBefore(settlementDate)) {
        return accruedInterest - coupon;
    }
    return accruedInterest;
}

From source file:com.opengamma.financial.convention.daycount.AccruedInterestCalculator.java

/**
 * Calculates the accrued interest for a {@code LocalDate}.
 * //from w  ww  .j a v a  2 s .c  om
 * @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 settlementDates  the settlement dates, 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 index The index of the previous coupon in the nominalDates
 * @param calendar The working day calendar used to calculate the ex-dividend date, not null
 * @return the accrued interest
 */
public static double getAccruedInterest(final DayCount dayCount, final LocalDate settlementDate,
        final LocalDate[] nominalDates, final LocalDate[] settlementDates, final double coupon,
        final double paymentsPerYear, final boolean isEndOfMonthConvention, final int exDividendDays,
        final int index, final Calendar calendar) {
    Validate.notNull(dayCount, "day-count");
    Validate.notNull(settlementDate, "date");
    Validate.notNull(calendar, "calendar");
    Validate.noNullElements(nominalDates, "nominalDates");
    Validate.noNullElements(settlementDates, "settlementDates");
    Validate.isTrue(paymentsPerYear > 0);
    Validate.isTrue(exDividendDays >= 0);
    final int length = nominalDates.length;
    Validate.isTrue(index >= 0 && index < length);
    final LocalDate previousCouponDate = nominalDates[index];
    final LocalDate nextCouponDate = nominalDates[index + 1];
    double accruedInterest;
    if (settlementDate.isAfter(nextCouponDate)) {
        if (settlementDate.isBefore(settlementDates[index + 1])) {
            accruedInterest = coupon;
        } else {
            accruedInterest = 0;
        }
    } else {
        accruedInterest = getAccruedInterest(dayCount, index, length, previousCouponDate, settlementDate,
                nextCouponDate, coupon, paymentsPerYear, isEndOfMonthConvention);
    }
    LocalDate exDividendDate = nominalDates[index + 1];
    for (int i = 0; i < exDividendDays; i++) {
        while (!calendar.isWorkingDay(exDividendDate)) {
            exDividendDate = exDividendDate.minusDays(1);
        }
        exDividendDate = exDividendDate.minusDays(1);
    }
    if (exDividendDays != 0 && exDividendDate.isBefore(settlementDate)) {
        return accruedInterest - coupon;
    }
    return accruedInterest;
}

From source file:de.cubeisland.engine.core.webapi.ApiServer.java

public void setWhitelist(Set<InetAddress> newWhitelist) {
    expectNotNull(newWhitelist, "The whitelist must not be null!");
    Validate.noNullElements(newWhitelist, "The whitelist must not contain null values!");

    this.whitelist.clear();
    this.whitelist.addAll(newWhitelist);
}

From source file:com.opengamma.analytics.math.surface.InterpolatedFromCurvesDoublesSurface.java

/**
 * @param xzCurves Do the curves lie in the <i>x-z</i> plane or the <i>y-z</i> plane.
 * @param points An array of points of intersection of the curves on the remaining axis (e.g. if the curves are in the <i>x-z</i> plane, the points indicate where
 * the curves cross the <i>y</i> axis). Not null
 * @param curves An array of curves, not null, must be the same length as the array of points of intersection
 * @param interpolator The interpolator/*w w  w .  j  a va2s  . c  o  m*/
 * @param isSorted Are the intersection points of the curve sorted in increasing order
 */
public InterpolatedFromCurvesDoublesSurface(final boolean xzCurves, final double[] points,
        final Curve<Double, Double>[] curves, final Interpolator1D interpolator, final boolean isSorted) {
    super();
    Validate.notNull(points, "points");
    Validate.notNull(curves, "curves");
    final int n = points.length;
    Validate.isTrue(points.length > 0 && points.length == curves.length);
    Validate.noNullElements(curves, "curves");
    Validate.notNull(interpolator, "interpolator");
    _xzCurves = xzCurves;
    _points = Arrays.copyOf(points, n);
    _curves = Arrays.copyOf(curves, n);
    _nCurves = n;
    _interpolator = interpolator;
    if (!isSorted) {
        ParallelArrayBinarySort.parallelBinarySort(_points, _curves);
    }
}

From source file:com.opengamma.analytics.math.cube.InterpolatedFromSurfacesDoublesCube.java

/**
 * @param plane The plane in which the surfaces lie
 * @param points An array of points of intersection of the surfaces on the remaining axis (e.g. if the surfaces are in the <i>x-y</i> plane, the points indicate where
 * the surfaces cross the <i>z</i> axis). Not null
 * @param surfaces An array of surfaces, not null, must be the same length as the array of points of intersection
 * @param interpolator The interpolator//from w  ww.  j av a2 s  .c o m
 * @param isSorted Is the intersection point data sorted 
 */
public InterpolatedFromSurfacesDoublesCube(final SurfacePlane plane, final double[] points,
        final Surface<Double, Double, Double>[] surfaces, final Interpolator1D interpolator,
        final boolean isSorted) {
    super();
    Validate.notNull(plane, "plane");
    Validate.notNull(points, "points");
    Validate.notNull(surfaces, "surfaces");
    final int n = points.length;
    Validate.isTrue(n > 0);
    Validate.isTrue(n == surfaces.length);
    Validate.noNullElements(surfaces, "surfaces");
    Validate.notNull(interpolator, "interpolator");
    _plane = plane;
    _points = Arrays.copyOf(points, n);
    _surfaces = Arrays.copyOf(surfaces, n);
    _nSurfaces = n;
    _interpolator = interpolator;
    if (!isSorted) {
        ParallelArrayBinarySort.parallelBinarySort(_points, _surfaces);
    }
}

From source file:de.cubeisland.engine.core.webapi.ApiServer.java

public void setBlacklist(Set<InetAddress> newBlacklist) {
    expectNotNull(newBlacklist, "The blacklist must not be null!");
    Validate.noNullElements(newBlacklist, "The blacklist must not contain null values!");

    this.blacklist.clear();
    this.blacklist.addAll(newBlacklist);
}