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.analytics.math.statistics.descriptive.PopulationVarianceCalculator.java

/**
 * @param x The array of data, not null, must contain at least two elements
 * @return The population variance//from w  w  w.j  ava  2s. c  o  m
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    final int n = x.length;
    Validate.isTrue(n >= 2, "Need at least two points to calculate the population variance");
    return _variance.evaluate(x) * (n - 1) / n;
}

From source file:com.opengamma.analytics.math.statistics.descriptive.SampleVarianceCalculator.java

/**
 * @param x The array of data, not null, must contain at least two elements
 * @return The sample variance/*w ww.j av a2s  .c o m*/
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length >= 2, "Need at least two points to calculate the sample variance");
    final Double mean = MEAN.evaluate(x);
    double sum = 0;
    for (final Double value : x) {
        final double diff = value - mean;
        sum += diff * diff;
    }
    final int n = x.length;
    return sum / (n - 1);
}

From source file:com.opengamma.analytics.math.rootfinding.QuadraticRealRootFinder.java

/**
 * {@inheritDoc}/*from  ww w .  j  a  va  2  s . c o  m*/
 * @throws IllegalArgumentException If the function is not a quadratic
 * @throws MathException If the roots are not real
 */
@Override
public Double[] getRoots(final RealPolynomialFunction1D function) {
    Validate.notNull(function, "function");
    final double[] coefficients = function.getCoefficients();
    Validate.isTrue(coefficients.length == 3, "Function is not a quadratic");
    final double c = coefficients[0];
    final double b = coefficients[1];
    final double a = coefficients[2];
    final double discriminant = b * b - 4 * a * c;
    if (discriminant < 0) {
        throw new MathException("No real roots for quadratic");
    }
    final double q = -0.5 * (b + Math.signum(b) * discriminant);
    return new Double[] { q / a, c / q };
}

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

/**
 * {@inheritDoc}//from  w w w  . j  a  va  2  s. c o  m
 */
@Override
public FunctionalDoublesCurve evaluate(final FunctionalDoublesCurve curve, final double shift,
        final String newName) {
    Validate.notNull(curve, "curve");
    final Function<Double, Double> f = curve.getFunction();
    final Function1D<Double, Double> shiftedFunction = new Function1D<Double, Double>() {

        @Override
        public Double evaluate(final Double x) {
            return f.evaluate(x) + shift;
        }

    };
    return FunctionalDoublesCurve.from(shiftedFunction, curve.getFirstDerivativeFunction(), newName);
}

From source file:com.opengamma.analytics.math.interpolation.CombinedInterpolatorExtrapolator.java

public CombinedInterpolatorExtrapolator(final Interpolator1D interpolator, final Interpolator1D extrapolator) {
    Validate.notNull(interpolator, "interpolator");
    Validate.notNull(extrapolator, "extrapolator");
    _interpolator = interpolator;/*from   w w w.  java  2s .c o m*/
    _leftExtrapolator = extrapolator;
    _rightExtrapolator = extrapolator;
}

From source file:net.jadler.mocking.Verifying.java

/**
 * @param requestManager request manager instance to assist the verification
 *//*from  w  w w  .  j av  a 2 s . c o m*/
public Verifying(final RequestManager requestManager) {
    Validate.notNull(requestManager, "requestManager cannot be null");

    this.requestManager = requestManager;
}

From source file:com.opengamma.analytics.financial.interestrate.FDCurveSensitivityCalculator.java

/**
 * Gives the sensitivity of the some metric of an IRD to a points on a one of the family of curves by finite difference
   * @param ird The Interest Rate Derivative
 * @param calculator This calculates the metric
 * @param curves The family of yield curves
 * @param curveName The name of the curve of interest
 * @param times The times along the curve. <b>Note</b> These should be in ascending order and  be known sensitivity points
 * (or the result will be zero)/*w ww  . ja  va 2 s. c o m*/
 * @param absTol If the absolute value of a sensitivities is below this value it is ignored
 * @return Sensitivities at a given points
 */
public static final List<DoublesPair> curveSensitvityFDCalculator(final InstrumentDerivative ird,
        final InstrumentDerivativeVisitorAdapter<YieldCurveBundle, Double> calculator,
        final YieldCurveBundle curves, final String curveName, final double[] times, final double absTol) {

    Validate.notNull(times, "null times");
    Validate.notNull(ird, "null ird");
    Validate.notNull(calculator, "null calculator");
    Validate.notNull(curves, "null curves");
    Validate.isTrue(times[0] >= 0.0, "t less than 0");
    Validate.isTrue(curves.containsName(curveName), "curveName not in curves");

    final List<DoublesPair> res = new ArrayList<>();
    double oldT = times[0];
    boolean first = true;
    for (final double t : times) {
        if (!first) {
            Validate.isTrue(t > oldT, "times not strictly assending");
        } else {
            first = false;
        }
        final double sense = impFDCalculator(ird, calculator, curves, curveName, t);
        if (Math.abs(sense) > absTol) {
            res.add(new DoublesPair(t, sense));
        }
        oldT = t;
    }
    return res;
}

From source file:com.opengamma.analytics.financial.simpleinstruments.pricing.SimpleFuturePresentValueCalculatorDeprecated.java

@Override
public CurrencyAmount visit(final SimpleInstrument derivative, final SimpleFutureDataBundleDeprecated data) {
    Validate.notNull(derivative, "derivative");
    Validate.notNull(data, "data");
    return derivative.accept(this, data);
}

From source file:com.opengamma.analytics.financial.schedule.WeeklyScheduleOnDayCalculator.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.getDayOfWeek() == _dayOfWeek) {
            return new LocalDate[] { startDate };
        }//  w ww. ja  va  2s. c  om
        throw new IllegalArgumentException(
                "Start date and end date were the same but their day of week was not the same as that required");
    }
    final List<LocalDate> dates = new ArrayList<LocalDate>();
    LocalDate date = startDate;
    date = date.with(DateAdjusters.nextOrCurrent(_dayOfWeek));
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.with(DateAdjusters.next(_dayOfWeek));
    }
    return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
}

From source file:com.opengamma.analytics.financial.timeseries.filter.NegativeValueDoubleTimeSeriesFilter.java

@Override
public FilteredTimeSeries evaluate(final LocalDateDoubleTimeSeries ts) {
    Validate.notNull(ts, "ts");
    if (ts.isEmpty()) {
        s_logger.info("Time series was empty");
        return new FilteredTimeSeries(EMPTY_SERIES, EMPTY_SERIES);
    }/*from w  ww  . j av a 2  s  . c om*/
    final int n = ts.size();
    final FastIntDoubleTimeSeries x = (FastIntDoubleTimeSeries) ts.getFastSeries();
    final int[] filteredDates = new int[n];
    final double[] filteredData = new double[n];
    final int[] rejectedDates = new int[n];
    final double[] rejectedData = new double[n];
    final ObjectIterator<Int2DoubleMap.Entry> iter = x.iteratorFast();
    Int2DoubleMap.Entry entry;
    int i = 0, j = 0;
    while (iter.hasNext()) {
        entry = iter.next();
        if (entry.getValue() < 0) {
            rejectedDates[j] = entry.getKey();
            rejectedData[j++] = entry.getValue();
        } else {
            filteredDates[i] = entry.getKey();
            filteredData[i++] = entry.getValue();
        }
    }
    return getFilteredSeries(filteredDates, filteredData, i, rejectedDates, rejectedData, j);
}