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

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

Introduction

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

Prototype

public static void isTrue(boolean expression) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the test result is false.

This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

 Validate.isTrue( i > 0 ); Validate.isTrue( myObject.isOk() ); 

The message in the exception is 'The validated expression is false'.

Usage

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

public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    final List<LocalDate> dates = new ArrayList<LocalDate>();
    if (fromEnd) {
        LocalDate date = endDate;
        while (!date.isBefore(startDate)) {
            dates.add(date);//  ww  w .j av a2  s.  c  om
            date = date.minusDays(7);
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
    }
    LocalDate date = startDate;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.plusDays(7);
    }
    return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
}

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;/*from  w  w w  . j  a  va2  s.c o  m*/
        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.math.function.special.OrthonormalHermitePolynomialFunction.java

@Override
public DoubleFunction1D[] getPolynomials(final int n) {
    Validate.isTrue(n >= 0);
    final DoubleFunction1D[] polynomials = new DoubleFunction1D[n + 1];
    for (int i = 0; i <= n; i++) {
        if (i == 0) {
            polynomials[i] = F0;//from  w  ww . j av a2s . c  o m
        } else if (i == 1) {
            polynomials[i] = polynomials[0].multiply(Math.sqrt(2)).multiply(getX());
        } else {
            polynomials[i] = polynomials[i - 1].multiply(getX()).multiply(Math.sqrt(2. / i))
                    .subtract(polynomials[i - 2].multiply(Math.sqrt((i - 1.) / i)));
        }
    }
    return polynomials;
}

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 a v a2  s  .com
        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 };
        }/*from ww w. 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.analytics.math.interpolation.MonotonicIncreasingInterpolator1D.java

@Override
public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DMonotonicIncreasingDataBundle);
    final Interpolator1DMonotonicIncreasingDataBundle miData = (Interpolator1DMonotonicIncreasingDataBundle) 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 .  j a va 2  s.c  om
        dx = value;
        a = miData.getA(0);
        b = miData.getB(0);
    } else if (value > data.lastKey()) {
        h = yData[n];
        dx = value - xData[n];
        a = miData.getA(n + 1);
        b = miData.getB(n + 1);
    } else {
        final int low = data.getLowerBoundIndex(value);
        h = yData[low];
        dx = value - xData[low];
        a = miData.getA(low + 1);
        b = miData.getB(low + 1);
    }
    if (Math.abs(b * dx) < 1e-8) {
        return h + a * (dx + b * dx * dx / 2);
    }
    return h + a / b * (Math.exp(b * dx) - 1);

}

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 va2  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.financial.instrument.Convention.java

public Convention(final int settlementDays, final DayCount dayCount,
        final BusinessDayConvention businessDayConvention, final Calendar workingDayCalendar,
        final String name) {
    Validate.isTrue(settlementDays >= 0);
    Validate.notNull(dayCount);/*  ww  w.j a v a 2 s .c om*/
    Validate.notNull(businessDayConvention);
    Validate.notNull(workingDayCalendar);
    Validate.notNull(name, "name");
    _settlementDays = settlementDays;
    _dayCount = dayCount;
    _businessDayConvention = businessDayConvention;
    _workingDayCalendar = workingDayCalendar;
    _name = name;
}

From source file:it.filosganga.mobile.widgets.component.TableColumn.java

public TableColumn(String label, String shortLabel, int colspan) {

    Validate.notEmpty(label);/*from w  w w  .  ja va2s. c om*/
    Validate.isTrue(colspan >= 1);

    this.label = label;
    this.shortLabel = shortLabel;
    this.colspan = colspan;
}

From source file:ar.com.zauber.commons.web.transformation.utils.WebValidate.java

/**
 * Valida que la URI termine con / y que no este en blanco sino 
 * lanza una excepcion./*from  www.j  av a  2  s . c om*/
 * 
 * @param uri URI a validar.
 * @throws IllegalArgumentException if uri does not validate
 */
public static void uriNotBlank(final String uri) throws IllegalArgumentException {
    Validate.isTrue(!StringUtils.isBlank(uri));
    uriWellFormed(uri);
}