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.var.parametric.ParametricVaRDataBundle.java

public ParametricVaRDataBundle(final List<String> names, final DoubleMatrix1D expectedReturn,
        final Matrix<?> sensitivities, final DoubleMatrix2D covarianceMatrix, final int order) {
    Validate.notNull(sensitivities, "sensitivities");
    Validate.notNull(covarianceMatrix, "covariance matrix");
    Validate.notNull(expectedReturn, "expected return");
    Validate.isTrue(order > 0);
    Validate.isTrue(covarianceMatrix.getNumberOfRows() == covarianceMatrix.getNumberOfColumns());
    if (sensitivities instanceof DoubleMatrix1D) {
        Validate.isTrue(sensitivities.getNumberOfElements() == covarianceMatrix.getNumberOfRows());
        Validate.isTrue(sensitivities.getNumberOfElements() == expectedReturn.getNumberOfElements());
        if (names != null) {
            Validate.isTrue(sensitivities.getNumberOfElements() == names.size());
        }/*from  www . jav  a 2 s.  c o  m*/
    } else if (sensitivities instanceof DoubleMatrix2D) {
        Validate.isTrue(
                ((DoubleMatrix2D) sensitivities).getNumberOfRows() == covarianceMatrix.getNumberOfRows());
        Validate.isTrue(
                ((DoubleMatrix2D) sensitivities).getNumberOfRows() == expectedReturn.getNumberOfElements());
        if (names != null) {
            Validate.isTrue(((DoubleMatrix2D) sensitivities).getNumberOfRows() == names.size());
        }
    } else {
        throw new IllegalArgumentException("Can only handle 1- and 2-d sensitivity matrices");
    }
    _names = names;
    _expectedReturn = expectedReturn;
    _sensitivities = sensitivities;
    _covarianceMatrix = covarianceMatrix;
    _order = order;
}

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

@Override
public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
    final double eps = 1e-10;

    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DPiecewisePoynomialDataBundle);
    final Interpolator1DPiecewisePoynomialDataBundle polyData = (Interpolator1DPiecewisePoynomialDataBundle) data;

    ArgumentChecker.isFalse(value < 0, "value must be zero or positive");
    if (value == 0) {
        return 0.0;
    }/*from  w  w w  . j a  v a 2 s .  c o  m*/

    // TODO direct evaluation using coefficients
    final double t = Math.max(eps, value); // Avoid divide by zero
    final DoubleMatrix1D res = FUNC.evaluate(polyData.getPiecewisePolynomialResultsWithSensitivity(), t);
    return res.getEntry(0) / t;
}

From source file:io.yields.math.framework.kpi.StatDefinition.java

public StatDefinition(StatDefinition parent, String name, String description, Double minValue, Double maxValue,
        Double referenceLevel) {/*  ww w.  java  2s  .c om*/
    super(parent, name, description);
    if (minValue != null && maxValue != null && referenceLevel != null) {
        Validate.isTrue(minValue <= referenceLevel && referenceLevel <= maxValue);
    }
    this.minValue = minValue;
    this.maxValue = maxValue;
    this.referenceLevel = referenceLevel;
}

From source file:com.opengamma.analytics.financial.schedule.AnnualScheduleCalculator.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 };
    }//  w  w  w  .  j  ava  2  s . c  o  m
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime 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_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime 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_ZONED_DATE_TIME_ARRAY);
}

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

@Override
public double firstDerivative(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DPiecewisePoynomialWithExtraKnotsDataBundle);
    final Interpolator1DPiecewisePoynomialWithExtraKnotsDataBundle polyData = (Interpolator1DPiecewisePoynomialWithExtraKnotsDataBundle) data;
    final DoubleMatrix1D res = FUNC.differentiate(polyData.getPiecewisePolynomialResult(), value);
    return res.getEntry(0);
}

From source file:com.opengamma.analytics.math.surface.ObjectsSurface.java

/**
 * @param xData An array of <i>x</i> data, not null
 * @param yData An array of <i>y</i> data, not null
 * @param zData An array of <i>z</i> data, not null
 * @param name The surface name/* w w  w.  jav  a 2 s  .  c o  m*/
 */
public ObjectsSurface(final T[] xData, final U[] yData, final V[] zData, final String name) {
    super(name);
    Validate.notNull(xData, "x data");
    Validate.notNull(yData, "y data");
    Validate.notNull(zData, "z data");
    Validate.isTrue(xData.length == yData.length);
    Validate.isTrue(xData.length == zData.length);
    _n = xData.length;
    _xData = Arrays.copyOf(xData, _n);
    _yData = Arrays.copyOf(yData, _n);
    _zData = Arrays.copyOf(zData, _n);
}

From source file:com.opengamma.analytics.financial.schedule.MonthlyScheduleCalculator.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   w w  w.j  a  v  a 2s .  co  m*/
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime 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_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime 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_ZONED_DATE_TIME_ARRAY);
}

From source file:com.edmunds.etm.management.util.VipDeltaCalculator.java

/**
 * Performs a delta operation on vips managed at the web tier.
 *
 * @param oldVips the previous list of vips
 * @param newVips the current list of vips
 * @return the merged tree with flags to indicate where changes have been made
 *//*  w  w  w  .  j  ava2 s. c  om*/
public ManagementVips deltaWebTier(ManagementVips oldVips, ManagementVips newVips) {
    Validate.isTrue(newVips.getVipType() == COMPLETE);

    // Always copy the new vips since they have the most up to date info.
    return new VipDeltaLogic(oldVips, newVips, true).delta();
}

From source file:hr.fer.spocc.util.CharacterEscaper.java

/**
 * Creates an escaper which escapes with the specified character.
 * The <tt>from</tt> array is used to determine
 * which characters should be escaped, and the corresponding
 * element in the <tt>to</tt> array is used after the escape character
 * in the escaped string./*from   ww  w  .j  a  va 2  s. co m*/
 * 
 * @param from the array of escapable characters
 * @param to the array of the escaped values for the escapable character
 * (order is relevant)
 * @param escapeCharacter the character used for escaping
 */
public CharacterEscaper(char[] from, char[] to, char escapeCharacter) {
    Validate.notNull(from);
    Validate.notNull(to);
    Validate.isTrue(from.length == to.length);

    Map<Character, Character> modifiableEscapeMap = new HashMap<Character, Character>(from.length);
    Map<Character, Character> modifiableUnescapeMap = new HashMap<Character, Character>(from.length);
    for (int i = 0; i < from.length; ++i) {
        Validate.isTrue(!modifiableEscapeMap.containsKey(from[i]) && !modifiableUnescapeMap.containsKey(to[i]),
                "Mapping must be a bijection");
        modifiableEscapeMap.put(from[i], to[i]);
        modifiableUnescapeMap.put(to[i], from[i]);
    }
    // ensure that the escape character is also escaped
    Validate.isTrue(modifiableEscapeMap.containsKey(escapeCharacter),
            "Escape character must also be escapable");

    this.escapeMap = Collections.unmodifiableMap(modifiableEscapeMap);
    this.unescapeMap = Collections.unmodifiableMap(modifiableUnescapeMap);
    this.escapeCharacter = escapeCharacter;
}

From source file:com.opengamma.analytics.math.integration.GaussLaguerreWeightAndAbscissaFunction.java

/**
 * {@inheritDoc}//from  www. j av a  2  s . c o  m
 */
@Override
public GaussianQuadratureData generate(final int n) {
    Validate.isTrue(n > 0);
    final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = LAGUERRE.getPolynomialsAndFirstDerivative(n,
            _alpha);
    final Pair<DoubleFunction1D, DoubleFunction1D> pair = polynomials[n];
    final DoubleFunction1D p1 = polynomials[n - 1].getFirst();
    final DoubleFunction1D function = pair.getFirst();
    final DoubleFunction1D derivative = pair.getSecond();
    final double[] x = new double[n];
    final double[] w = new double[n];
    double root = 0;
    for (int i = 0; i < n; i++) {
        root = ROOT_FINDER.getRoot(function, derivative, getInitialRootGuess(root, i, n, x));
        x[i] = root;
        w[i] = -GAMMA_FUNCTION.evaluate(_alpha + n) / MathUtils.factorialDouble(n)
                / (derivative.evaluate(root) * p1.evaluate(root));
    }
    return new GaussianQuadratureData(x, w);
}