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.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 };
        }/*  w w  w  .  ja  va2s. c om*/
        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.financial.convention.StubCalculator.java

/**
 * Calculates the start stub type from a schedule, number of payments per year and the end of month flag.
 * <p>/*w  w w  . j a  v  a 2s . c o  m*/
 * The {@code DateProvider[]} argument allows callers to pass in arrays of any class
 * that implements {@code DateProvider}, such as {@code LocalDate[]}.
 * 
 * @param schedule  the schedule, at least size 2, not null
 * @param paymentsPerYear  the number of payments per year, one, two, three, four, six or twelve
 * @param isEndOfMonthConvention  whether to use end of month rules
 * @return the stub type, not null
 */
public static StubType getStartStubType(final LocalDate[] schedule, final double paymentsPerYear,
        final boolean isEndOfMonthConvention) {
    Validate.notNull(schedule, "schedule");
    Validate.noNullElements(schedule, "schedule");
    Validate.isTrue(paymentsPerYear > 0);
    Validate.isTrue(12 % paymentsPerYear == 0);

    final int months = (int) (12 / paymentsPerYear);
    final LocalDate first = schedule[0];
    final LocalDate second = schedule[1];
    LocalDate date;
    if (isEndOfMonthConvention && second.equals(second.with(lastDayOfMonth()))) {
        date = second.minusMonths(months);
        date = date.with(lastDayOfMonth());
    } else {
        date = second.minusMonths(months);
    }
    if (date.equals(first)) {
        return StubType.NONE;
    }
    if (date.isBefore(first)) {
        return StubType.SHORT_START;
    }
    return StubType.LONG_START;
}

From source file:com.useekm.fulltext.Word.java

/**
 * This constructor is called for prefix-search-words such as 'xyz*' (for lookup of words starting with xyz).
 * The grammar makes am operator out of the star, hence it can be removed from the lexical token.
 *///ww  w .j av  a  2s.co  m
public Word(String word, boolean removeOperator) {
    Validate.notEmpty(word);
    Validate.isTrue(!removeOperator || (word.length() >= 2 && word.endsWith("*")));
    if (removeOperator)
        this.word = word.substring(0, word.length() - 1);
    else
        this.word = word;
}

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

@Override
public Pair<DoubleFunction1D, DoubleFunction1D>[] getPolynomialsAndFirstDerivative(final int n) {
    Validate.isTrue(n >= 0);
    @SuppressWarnings("unchecked")
    final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = new Pair[n + 1];
    DoubleFunction1D p, dp;/*from  ww w  .ja va  2  s.c o  m*/
    for (int i = 0; i <= n; i++) {
        if (i == 0) {
            polynomials[i] = Pair.of(getOne(), getZero());
        } else if (i == 1) {
            polynomials[i] = Pair.of(getX(), getOne());
        } else {
            p = (polynomials[i - 1].getFirst().multiply(getX()).multiply(2 * i - 1)
                    .subtract(polynomials[i - 2].getFirst().multiply(i - 1))).multiply(1. / i);
            dp = p.derivative();
            polynomials[i] = Pair.of(p, dp);
        }
    }
    return polynomials;
}

From source file:com.prowidesoftware.swift.model.mt.SystemMessage.java

public SystemMessage(final SwiftMessage aMessage) {
    super(aMessage);
    Validate.isTrue(aMessage.isSystemMessage());
}

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

/**
 * @param x The array of data, not null. The first and second elements must be arrays of data, neither of which is null or has less than two elements.
 * @return The sample covariance//w ww  . ja  v  a 2s .c o m
 */
@Override
public Double evaluate(final double[]... x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length > 1);
    final double[] x1 = x[0];
    final double[] x2 = x[1];
    Validate.isTrue(x1.length > 1);
    final int n = x1.length;
    Validate.isTrue(x2.length == n);
    final double mean1 = MEAN_CALCULATOR.evaluate(x1);
    final double mean2 = MEAN_CALCULATOR.evaluate(x2);
    double sum = 0;
    for (int i = 0; i < n; i++) {
        sum += (x1[i] - mean1) * (x2[i] - mean2);
    }
    return sum / (n - 1);
}

From source file:ar.com.zauber.commons.web.version.impl.InmutableVersionProvider.java

/**
 * Creates the InmutableVersionProvider.
 *
 */// w w  w.j  a v  a  2s  . c om
public InmutableVersionProvider(final String version) {
    Validate.isTrue(!StringUtils.isBlank(version));

    this.version = version;
}

From source file:de.gzockoll.test.buildpipeline.Konto.java

/**
 * Addiert den Betrag zum Saldo
 * @param betrag
 */
public void buche(int betrag) {
    Validate.isTrue(saldo + betrag > 0);
    saldo += betrag;
}

From source file:ar.com.zauber.commons.dao.resources.ClasspathResource.java

/** @param resourcePath full path to the resource */
public ClasspathResource(final String resourcePath) {
    Validate.isTrue(StringUtils.isNotBlank(resourcePath));

    this.resourcePath = resourcePath;
}

From source file:ar.com.zauber.commons.passwd.CharLengthPasswordValidator.java

/**
 * Creates the CharLengthPasswordValidator.
 *
 * @param minLength the minunLength/*from  ww w .  ja va  2s .c  o  m*/
 */
public CharLengthPasswordValidator(final int minLength) {
    Validate.isTrue(minLength >= 0);

    this.minLength = minLength;
}