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.math.rootfinding.RealSingleRootFinder.java

@Override
public Double getRoot(final Function1D<Double, Double> function, final Double... startingPoints) {
    Validate.notNull(startingPoints);/*from   w  w w . j a v  a 2  s .co  m*/
    Validate.isTrue(startingPoints.length == 2);
    return getRoot(function, startingPoints[0], startingPoints[1]);
}

From source file:com.opengamma.analytics.math.function.FunctionND.java

/**
 * @param dimension The dimension of this function
 */
public FunctionND(final int dimension) {
    Validate.isTrue(dimension > 0);
    _dimension = dimension;
}

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

public MonthlyScheduleOnDayCalculator(final int dayOfMonth) {
    Validate.isTrue(dayOfMonth > 0 && dayOfMonth < 32);
    _dayOfMonth = dayOfMonth;
}

From source file:com.opengamma.analytics.math.interpolation.data.Interpolator2DDataBundle.java

public Interpolator2DDataBundle(final double[] xData, final double[] yData, final double[] zData) {
    Validate.notNull(xData, "x data");
    Validate.notNull(yData, "y data");
    Validate.notNull(zData, "z data");
    final int n = xData.length;
    Validate.isTrue(n == yData.length);
    Validate.isTrue(n == zData.length);/*  w w w  .  j av a2s  . co m*/
    _xData = xData;
    _yData = yData;
    _zData = zData;
}

From source file:com.opengamma.analytics.math.function.special.HermitePolynomialFunction.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] = getOne();//w w  w .  ja va  2 s . c o  m
        } else if (i == 1) {
            polynomials[i] = TWO_X;
        } else {
            polynomials[i] = polynomials[i - 1].multiply(2).multiply(getX())
                    .subtract(polynomials[i - 2].multiply(2 * i - 2));
        }
    }
    return polynomials;
}

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

public BasisFunctionAggregation(List<Function1D<T, Double>> functions, double[] weights) {
    Validate.notEmpty(functions, "no functions");
    Validate.notNull(weights, "no weights");
    Validate.isTrue(functions.size() == weights.length);
    _f = functions;/*from  w  w w .  j av a2  s . c o  m*/
    _w = weights;
}

From source file:com.opengamma.analytics.math.ParallelArrayBinarySort.java

/**
 * Sort the content of keys and values simultaneously so that
 * both match the correct ordering. Alters the arrays in place
 * @param keys The keys/* w w w.ja va 2  s . c  o m*/
 * @param values The values
 */
public static void parallelBinarySort(final float[] keys, final double[] values) {
    Validate.notNull(keys, "x data");
    Validate.notNull(values, "y data");
    Validate.isTrue(keys.length == values.length);
    final int n = keys.length;
    dualArrayQuickSort(keys, values, 0, n - 1);
}

From source file:hr.fer.spocc.export.DotExporter.java

public static String toDotString(ParseTree parseTree, String graphName) {
    Validate.isTrue(!graphName.isEmpty() && StringUtils.isAlphanumeric(graphName)
            && Character.isLetter(graphName.charAt(0)));
    StringBuilder dotString = new StringBuilder();
    dotString.append("digraph ").append(graphName).append(" {\n");
    Map<ParseTreeNode, String> nodePrefixMap = new LinkedHashMap<ParseTreeNode, String>();
    toDotNodes(parseTree.getRoot(), new StringBuilder(), nodePrefixMap, dotString);
    toDotEdges(parseTree.getRoot(), nodePrefixMap, dotString);
    dotString.append("}\n");
    return dotString.toString();
}

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

@Override
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate 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 LocalDate[] { startDate };
    }//  ww  w  .ja v a 2s  .  com
    final List<LocalDate> dates = new ArrayList<LocalDate>();
    if (fromEnd) {
        LocalDate date = endDate;
        int i = 1;
        while (!date.isBefore(startDate)) {
            dates.add(date);
            date = generateRecursive ? date.minus(Period.ofYears(1)) : endDate.minus(Period.ofYears(i++));
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
    }
    LocalDate date = startDate;
    int i = 1;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = generateRecursive ? date.plus(Period.ofYears(1)) : startDate.plus(Period.ofYears(i++));
    }
    return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
}

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

@Override
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate 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 LocalDate[] { startDate };
    }/*from  w ww  . j  av  a  2 s .  c  o m*/
    final List<LocalDate> dates = new ArrayList<LocalDate>();
    if (fromEnd) {
        LocalDate date = endDate;
        int i = 1;
        while (!date.isBefore(startDate)) {
            dates.add(date);
            date = generateRecursive ? date.minus(Period.ofMonths(1)) : endDate.minus(Period.ofMonths(i++));
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
    }
    LocalDate date = startDate;
    int i = 1;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = generateRecursive ? date.plus(Period.ofMonths(1)) : startDate.plus(Period.ofMonths(i++));
    }
    return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
}