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

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

Introduction

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

Prototype

public static void notNull(Object object, String message) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the argument is null.

 Validate.notNull(myObject, "The object must not be null"); 

Usage

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

/**
 * Calculates the accrued interest for a {@code ZonedDateTime}.
 * // w ww .  j  a  v a 2s. 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.cadiducho.minegram.MinegramPlugin.java

@Override
public void onEnable() {
    instance = this;
    Validate.notNull(instance, "Plugin cannot be null!");
    log("Enabling Minegram " + getDescription().getVersion() + " by Cadiducho");

    File config = new File(getDataFolder() + File.separator + "config.yml");
    if (!config.exists()) {
        getConfig().options().copyDefaults(true);
        saveConfig();/*ww w. j  av a2  s .  c o  m*/
    }

    new BukkitRunnable() {
        @Override
        public void run() {
            if (!bots.isEmpty()) {
                bots.forEach((bot, pluginLoader) -> {
                    try {
                        log("@" + bot.getMe().getUsername() + " loaded by " + pluginLoader.getName());
                    } catch (TelegramException ex) {
                        log("Could not retrieve any info from " + pluginLoader.getName() + "'s bot:");
                        log(ex.getMessage());
                    }
                });
            }
            log("Loaded " + bots.size() + " bots.");
        }
    }.runTaskLater(this, 1);

}

From source file:com.evolveum.midpoint.repo.sql.query2.hqm.condition.NotCondition.java

public NotCondition(RootHibernateQuery rootHibernateQuery, Condition child) {
    super(rootHibernateQuery);
    Validate.notNull(child, "child");
    this.child = child;
}

From source file:com.opengamma.analytics.financial.pnl.DrawdownCalculator.java

/**
 * Calculates the drawdown time series, with the drawdown expressed as a decimal
 * @param ts A time series// w  w w  .j a va 2 s. co m
 * @return The drawdown
 * @throws IllegalArgumentException If the time series is null or empty 
 */
@Override
public DateDoubleTimeSeries<?> evaluate(final DateDoubleTimeSeries<?> ts) {
    Validate.notNull(ts, "time series");
    Validate.isTrue(ts.size() > 0);
    final int n = ts.size();
    final int[] t = ts.timesArrayFast();
    final double[] drawdown = new double[n];
    t[0] = ts.getEarliestTimeFast();
    drawdown[0] = 0;
    double peak = ts.getEarliestValueFast();
    double value;
    for (int i = 1; i < n; i++) {
        value = ts.getValueAtIndexFast(i);
        if (value > peak) {
            peak = value;
            drawdown[i] = 0;
        } else {
            drawdown[i] = (peak - value) / peak;
        }
    }
    return ImmutableLocalDateDoubleTimeSeries.of(t, drawdown);
}

From source file:com.opengamma.analytics.financial.schedule.MonthlyScheduleOnDayCalculator.java

public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        if (startDate.getDayOfMonth() == _dayOfMonth) {
            return new LocalDate[] { startDate };
        }/*ww w .  j  a  v  a 2s  .  co m*/
        throw new IllegalArgumentException(
                "Start date and end date were the same but their day of month was not the same as that required");
    }
    final List<LocalDate> dates = new ArrayList<LocalDate>();
    int year = endDate.getYear();
    MonthOfYear month = startDate.getMonthOfYear();
    LocalDate date = startDate.withMonthOfYear(month.getValue()).withDayOfMonth(_dayOfMonth);
    if (date.isBefore(startDate)) {
        month = month.next();
        date = date.withMonthOfYear(month.getValue());
    }
    year = date.getYear();
    while (!date.isAfter(endDate)) {
        dates.add(date);
        month = month.next();
        if (month == MonthOfYear.JANUARY) {
            year++;
        }
        date = LocalDate.of(year, month.getValue(), _dayOfMonth);
    }
    return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
}

From source file:com.opengamma.analytics.math.curve.SubtractCurveSpreadFunction.java

/**
 * @param curves An array of curves, not null or empty
 * @return A function that will find the value of each curve at the given input <i>x</i> and subtract each in turn
 *//*from w ww.  jav  a2 s  .com*/
@Override
public Function<Double, Double> evaluate(final Curve<Double, Double>... curves) {
    Validate.notNull(curves, "x");
    Validate.notEmpty(curves, "curves");
    return new Function<Double, Double>() {

        @Override
        public Double evaluate(final Double... x) {
            Validate.notNull(x, "x");
            Validate.notEmpty(x, "x");
            final double x0 = x[0];
            double y = curves[0].getYValue(x0);
            for (int i = 1; i < curves.length; i++) {
                y -= curves[i].getYValue(x0);
            }
            return y;
        }

    };
}

From source file:com.opengamma.analytics.math.curve.AddCurveSpreadFunction.java

/**
 * @param curves An array of curves, not null or empty
 * @return A function that will find the value of each curve at the given input <i>x</i> and return the sum of these values
 *//*  ww w  .  ja  v a 2s.co  m*/
@Override
public Function<Double, Double> evaluate(final Curve<Double, Double>... curves) {
    Validate.notNull(curves, "x");
    Validate.notEmpty(curves, "curves");
    return new Function<Double, Double>() {

        @Override
        public Double evaluate(final Double... x) {
            Validate.notNull(x, "x");
            Validate.notEmpty(x, "x");
            final double x0 = x[0];
            double y = curves[0].getYValue(x0);
            for (int i = 1; i < curves.length; i++) {
                y += curves[i].getYValue(x0);
            }
            return y;
        }

    };
}

From source file:com.qubole.quark.plugins.jdbc.EMRDb.java

public EMRDb(Map<String, Object> properties) {
    super(properties);
    Validate.notNull(properties.get("driverName"), "Specify field 'driverName' for EMR");
    Validate.notNull(properties.get("jdbcUrl"), "Specify field 'jdbcUrl' for EMR");
    this.jdbcUrl = (String) properties.get("jdbcUrl");
    this.driverName = (String) properties.get("driverName");
}

From source file:com.opengamma.analytics.financial.credit.cds.ISDAInterpolator1D.java

@Override
public Double interpolate(final Interpolator1DDataBundle data, final Double value) {

    Validate.notNull(value, "Value to be interpolated must not be null");
    Validate.notNull(data, "Data bundle must not be null");
    try {/* ww w .  j a v a  2 s . c  om*/
        final InterpolationBoundedValues boundedValues = data.getBoundedValues(value);

        // Avoid divide by zero errors (offset factors out of the final result if it is used)
        //R White where does this come from? The economically relevant quantity is x*y which is the (negative) log of the survival rate,
        //which is 0 for x (i.e. time t) equal 0. What this does is return y(1) for x = 0.0, which is arbitrary.  
        final double offset = value == 0.0 ? 1.0 : 0.0;

        final double x1 = boundedValues.getLowerBoundKey();
        final double y1 = boundedValues.getLowerBoundValue();
        final double y1x1 = y1 * (x1 + offset);

        if (data.getLowerBoundIndex(value) == data.size() - 1) {
            return y1;
        }

        final double x2 = boundedValues.getHigherBoundKey();
        final double y2 = boundedValues.getHigherBoundValue();
        final double y2x2 = y2 * (x2 + offset);

        return (y1x1 + (value - x1) / (x2 - x1) * (y2x2 - y1x1)) / (value + offset);
    } catch (final ArrayIndexOutOfBoundsException e) {
        throw e;
    }
}

From source file:com.opengamma.analytics.math.statistics.estimation.NormalDistributionMaximumLikelihoodEstimator.java

@Override
public ProbabilityDistribution<Double> evaluate(final double[] x) {
    Validate.notNull(x, "x");
    ArgumentChecker.notEmpty(x, "x");
    return new NormalDistribution(_mean.evaluate(x), _std.evaluate(x));
}