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 ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime date = endDate;
        while (!date.isBefore(startDate)) {
            dates.add(date);//from w  ww .ja  v a 2 s.c  om
            date = date.minusDays(7);
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime date = startDate;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.plusDays(7);
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

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

@Override
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd, final boolean generateRecursive) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        return new ZonedDateTime[] { startDate };
    }/*from ww  w .j a v  a2 s. c om*/
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime date = endDate;
        int i = 3;
        while (!date.isBefore(startDate)) {
            dates.add(date);
            date = generateRecursive ? date.minus(Period.ofMonths(3)) : endDate.minus(Period.ofMonths(i));
            i += 3;
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime date = startDate;
    int i = 3;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = generateRecursive ? date.plus(Period.ofMonths(3)) : startDate.plus(Period.ofMonths(i));
        i += 3;
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

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

@Override
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd, final boolean generateRecursive) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        return new ZonedDateTime[] { startDate };
    }//from   www  .j  a va2s  .c om
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime date = endDate;
        int i = 6;
        while (!date.isBefore(startDate)) {
            dates.add(date);
            date = generateRecursive ? date.minus(Period.ofMonths(6)) : endDate.minus(Period.ofMonths(i));
            i += 6;
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime date = startDate;
    int i = 6;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = generateRecursive ? date.plus(Period.ofMonths(6)) : startDate.plus(Period.ofMonths(i));
        i += 6;
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.tripod.api.query.Query.java

public Query(final String query, final Integer offset, final Integer rows) {
    this.query = query;
    this.offset = offset;
    this.rows = rows;

    Validate.notEmpty(query);/*from   w  ww .j  ava2s . co  m*/
    Validate.notNull(offset);
    Validate.isTrue(offset >= 0);
    Validate.notNull(rows);
    Validate.isTrue(rows > 0);
}

From source file:com.netflix.simianarmy.aws.janitor.rule.ami.UnusedImageRule.java

/**
 * Constructor.//from   w w  w  .j a v  a 2 s . c  om
 *
 * @param calendar
 *            The calendar used to calculate the termination time
 * @param retentionDays
 *            The number of days that the marked ASG is retained before being terminated
 * @param lastReferenceDaysThreshold
 *            The number of days that the image has been not referenced that makes the ASG be
 *            considered obsolete
 */
public UnusedImageRule(MonkeyCalendar calendar, int retentionDays, int lastReferenceDaysThreshold) {
    Validate.notNull(calendar);
    Validate.isTrue(retentionDays >= 0);
    Validate.isTrue(lastReferenceDaysThreshold >= 0);
    this.calendar = calendar;
    this.retentionDays = retentionDays;
    this.lastReferenceDaysThreshold = lastReferenceDaysThreshold;
}

From source file:com.palantir.atlasdb.table.description.render.TypeAndName.java

public String getNonListType() {
    Validate.isTrue(isListType());
    return type.replaceFirst("List<", "").replaceAll(">$", "");
}

From source file:com.opengamma.analytics.math.function.special.JacobiPolynomialFunction.java

public Pair<DoubleFunction1D, DoubleFunction1D>[] getPolynomialsAndFirstDerivative(final int n,
        final double alpha, final double beta) {
    Validate.isTrue(n >= 0);
    @SuppressWarnings("unchecked")
    final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = new Pair[n + 1];
    DoubleFunction1D p, dp, p1, p2;
    for (int i = 0; i <= n; i++) {
        if (i == 0) {
            polynomials[i] = Pair.of(getOne(), getZero());
        } else if (i == 1) {
            final double a1 = (alpha + beta + 2) / 2;
            polynomials[i] = Pair.of(/* w  ww .  j  a va 2s .  co m*/
                    (DoubleFunction1D) new RealPolynomialFunction1D(new double[] { (alpha - beta) / 2, a1 }),
                    (DoubleFunction1D) new RealPolynomialFunction1D(new double[] { a1 }));
        } else {
            final int j = i - 1;
            p1 = polynomials[j].getFirst();
            p2 = polynomials[j - 1].getFirst();
            final DoubleFunction1D temp1 = p1.multiply(getB(alpha, beta, j));
            final DoubleFunction1D temp2 = p1.multiply(getX()).multiply(getC(alpha, beta, j));
            final DoubleFunction1D temp3 = p2.multiply(getD(alpha, beta, j));
            p = (temp1.add(temp2).add(temp3)).divide(getA(alpha, beta, j));
            dp = p.derivative();
            polynomials[i] = Pair.of(p, dp);
        }
    }
    return polynomials;
}

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

@Override
public double firstDerivative(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();

    double dx, a, b;
    if (value < data.firstKey()) {
        dx = value;/*from  w w  w .j av a2  s  . co  m*/
        a = quadraticData.getA(0);
        b = quadraticData.getB(0);
    } else if (value > data.lastKey()) {
        dx = value - xData[n];
        a = quadraticData.getA(n + 1);
        b = quadraticData.getB(n + 1);
    } else {
        final int low = data.getLowerBoundIndex(value);
        dx = value - xData[low];
        a = quadraticData.getA(low + 1);
        b = quadraticData.getB(low + 1);
    }
    return a * a + 2. * a * b * dx + b * b * dx * dx;

}

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

public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime 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) {
            return new ZonedDateTime[] { startDate };
        }/*from w w  w.  jav a2 s .c  o  m*/
        throw new IllegalArgumentException(
                "Start date and end date were the same but neither was the first day of the month");
    }
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    ZonedDateTime date = startDate.with(DateAdjusters.firstDayOfMonth());
    if (date.isBefore(startDate)) {
        date = date.plusMonths(1);
    }
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.plusMonths(1);
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.useekm.types.GeometryMarshall.java

@Override
public void setDatatype(URI datatype) {
    Validate.isTrue(this.datatype.equals(datatype));
}