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.opengamma.analytics.math.statistics.estimation.LaplaceDistributionMaximumLikelihoodEstimator.java
@Override public ProbabilityDistribution<Double> evaluate(final double[] x) { Validate.notNull(x, "x"); ArgumentChecker.notEmpty(x, "x"); final double median = _median.evaluate(x); final int n = x.length; double b = 0; for (int i = 0; i < n; i++) { b += Math.abs(x[i] - median); }/* w ww.j a v a 2 s . c o m*/ return new LaplaceDistribution(median, b / n); }
From source file:com.opengamma.analytics.math.interpolation.QuadraticSplineInterpolator1D.java
@Override public Double interpolate(final Interpolator1DDataBundle data, final Double value) { Validate.notNull(value, "value"); Validate.notNull(data, "data bundle"); Validate.isTrue(data instanceof Interpolator1DQuadraticSplineDataBundle); final Interpolator1DQuadraticSplineDataBundle quadraticData = (Interpolator1DQuadraticSplineDataBundle) data; final int n = data.size() - 1; final double[] xData = data.getKeys(); final double[] yData = data.getValues(); double h, dx, a, b; if (value < data.firstKey()) { h = 0;// w w w .ja v a2 s . com dx = value; a = quadraticData.getA(0); b = quadraticData.getB(0); } else if (value > data.lastKey()) { h = yData[n]; dx = value - xData[n]; a = quadraticData.getA(n + 1); b = quadraticData.getB(n + 1); } else { final int low = data.getLowerBoundIndex(value); h = yData[low]; dx = value - xData[low]; a = quadraticData.getA(low + 1); b = quadraticData.getB(low + 1); } return h + a * a * dx + a * b * dx * dx + b * b / 3 * dx * dx * dx; }
From source file:com.opengamma.analytics.financial.timeseries.analysis.AutocovarianceFunctionCalculator.java
@Override public double[] evaluate(final DoubleTimeSeries<?> x) { Validate.notNull(x, "x"); if (x.isEmpty()) { throw new IllegalArgumentException("Time series was empty"); }//w ww .j a v a2s . c o m final int h = x.size() - 1; final double[] result = new double[h]; final double mean = _meanCalculator.evaluate(x); double[] x1, x2; final int n = x.size(); double sum; final double[] x0 = x.valuesArrayFast(); for (int i = 0; i < h; i++) { x1 = Arrays.copyOfRange(x0, 0, n - i); x2 = Arrays.copyOfRange(x0, i, n); if (x1.length != x2.length) { throw new IllegalArgumentException("Series were not the same length; this should not happen"); } sum = 0; for (int j = 0; j < x1.length; j++) { sum += (x1[j] - mean) * (x2[j] - mean); } result[i] = sum / n; } return result; }
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 . j a v a 2 s . c o m*/ 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.analytics.financial.schedule.EndOfMonthScheduleCalculator.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() == startDate.getMonthOfYear() .lengthInDays(startDate.toLocalDate().isLeapYear())) { return new LocalDate[] { startDate }; }//from w w w .j ava 2 s. co m throw new IllegalArgumentException( "Start date and end date were the same but neither was the last day of the month"); } final List<LocalDate> dates = new ArrayList<LocalDate>(); LocalDate date = startDate.with(DateAdjusters.lastDayOfMonth()); while (!date.isAfter(endDate)) { dates.add(date); date = date.plus(Period.ofMonths(1)).with(DateAdjusters.lastDayOfMonth()); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.schedule.EndOfYearScheduleCalculator.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() == 31 && startDate.getMonthOfYear() == MonthOfYear.DECEMBER) { return new LocalDate[] { startDate }; }/*w ww. ja v a 2 s. c o m*/ throw new IllegalArgumentException( "Start date and end date were the same but neither was the last day of the year"); } final List<LocalDate> dates = new ArrayList<LocalDate>(); LocalDate date = startDate.with(DateAdjusters.lastDayOfYear()); while (!date.isAfter(endDate)) { dates.add(date); date = date.plusYears(1).with(DateAdjusters.lastDayOfYear()); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.financial.convention.calendar.CalendarBase.java
/** * Creates an instance.//from w ww .j a v a2 s .co m * @param name the convention name, not null */ protected CalendarBase(final String name) { Validate.notNull(name, "name"); _name = name; }
From source file:com.opengamma.analytics.math.interpolation.StepInterpolator1D.java
@Override public double firstDerivative(final Interpolator1DDataBundle data, final Double x) { Validate.notNull(x, "value"); Validate.notNull(data, "data bundle"); return 0.;/* w w w . jav a 2 s .co m*/ }
From source file:com.opengamma.analytics.financial.schedule.FirstOfYearScheduleCalculator.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() == 1 && startDate.getMonthOfYear() == MonthOfYear.JANUARY) { return new LocalDate[] { startDate }; }/*from w ww. j a v a 2 s. c o m*/ throw new IllegalArgumentException( "Start date and end date were the same but neither was the first day of the year"); } final List<LocalDate> dates = new ArrayList<LocalDate>(); LocalDate date = startDate.with(DateAdjusters.firstDayOfYear()); if (date.isBefore(startDate)) { date = date.plusYears(1); } while (!date.isAfter(endDate)) { dates.add(date); date = date.plusYears(1); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.util.surface.StringValue.java
/** * Builder from a map. A new map is created with the same values. * @param map The map./*from w ww. j a v a2 s . c o m*/ * @return The surface value. */ public static StringValue from(final Map<String, Double> map) { Validate.notNull(map, "Map"); HashMap<String, Double> data = new HashMap<String, Double>(); data.putAll(map); return new StringValue(data); }