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, String message) 

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), "The value must be greater than zero"); Validate.isTrue( myObject.isOk(), "The object is not OK"); 

For performance reasons, the message string should not involve a string append, instead use the #isTrue(boolean,String,Object) method.

Usage

From source file:com.opengamma.analytics.financial.montecarlo.MonteCarloDiscountFactorCalculator.java

@Override
public Double visitCapFloorIbor(final CapFloorIbor payment,
        final MonteCarloDiscountFactorDataBundle mcResults) {
    final Double[][][] pathDiscountFactors = mcResults.getPathDiscountingFactor();
    final double[][] impactAmount = mcResults.getImpactAmount();
    Validate.isTrue(pathDiscountFactors[0].length == 1, "Only one decision date for cap/floor.");
    double price = 0;
    final int nbPath = pathDiscountFactors.length;
    double ibor;//from w  ww  .j  a  v  a 2s  .c  o m
    final double omega = (payment.isCap() ? 1.0 : -1.0);
    for (int looppath = 0; looppath < nbPath; looppath++) {
        ibor = (-impactAmount[0][0] * pathDiscountFactors[looppath][0][0]
                / (impactAmount[0][1] * pathDiscountFactors[looppath][0][1]) - 1.0)
                / payment.getFixingAccrualFactor();
        price += Math.max(omega * (ibor - payment.getStrike()), 0) * pathDiscountFactors[looppath][0][2];
    }
    price = price / nbPath * payment.getNotional() * payment.getPaymentYearFraction();
    return price;
}

From source file:com.opengamma.analytics.math.minimization.DoubleRangeLimitTransform.java

/**
 * {@inheritDoc}//ww  w. j  av a 2s.co m
 * @throws IllegalArgumentException If $x > b$ or $x < a$
 */
@Override
public double transform(final double x) {
    Validate.isTrue(x <= _upper && x >= _lower, "parameter out of range");
    if (x == _upper) {
        return TANH_MAX;
    } else if (x == _lower) {
        return -TANH_MAX;
    }
    return TrigonometricFunctionUtils.atanh((x - _mid) / _scale);
}

From source file:io.cloudslang.lang.compiler.Extension.java

private static void validateFileExtension(String fileName, Extension fileExtension, Extension[] extensions,
        String[] extensionValues) {
    boolean validFileExtension = false;
    for (Extension extension : extensions) {
        if (extension.equals(fileExtension)) {
            validFileExtension = true;/*from w  w  w  .  j  a va  2 s .  c  om*/
        }
    }
    String extensionsAsString = Arrays.toString(extensionValues);
    Validate.isTrue(validFileExtension, "File: " + fileName + " must have one of the following extensions: "
            + extensionsAsString.substring(1, extensionsAsString.length() - 1) + ".");
}

From source file:com.skelril.aurora.events.custom.item.SpecialAttackEvent.java

public void setSpec(SpecialAttack spec) {

    Validate.isTrue(getPlayer().equals(spec.getOwner()), "The owner and the spec owner must match!");

    this.spec = spec;
}

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

public List<Function1D<double[], Double>> generateSet(double[] xa, double[] xb, int[] nKnots,
        final int[] degree) {

    int dim = xa.length;
    Validate.isTrue(dim == xb.length, "xb wrong dimension");
    Validate.isTrue(dim == nKnots.length, "nKnots wrong dimension");
    Validate.isTrue(dim == degree.length, "degree wrong dimension");

    int[] n = new int[dim];
    int[] nSplines = new int[dim];
    double[][] knots = new double[dim][];

    double[] dx = new double[dim];
    int product = 1;
    for (int k = 0; k < dim; k++) {
        int p = nKnots[k] + 2 * degree[k];
        n[k] = p;/*from  ww  w.  j av  a 2 s  . c o m*/
        knots[k] = new double[p];
        nSplines[k] = nKnots[k] + degree[k] - 1;
        product *= nSplines[k];
        dx[k] = (xb[k] - xa[k]) / (nKnots[k] - 1);

        // knots to the left and right of the range
        for (int i = 0; i < degree[k]; i++) {
            knots[k][i] = (i - degree[k]) * dx[k] + xa[k];
            knots[k][degree[k] + nKnots[k] + i] = xb[k] + dx[k] * (i + 1);
        }
        // knots in the main range
        for (int i = 0; i < nKnots[k] - 1; i++) {
            knots[k][i + degree[k]] = xa[k] + i * dx[k];
        }
        knots[k][nKnots[k] + degree[k] - 1] = xb[k];
    }

    List<Function1D<double[], Double>> functions = new ArrayList<Function1D<double[], Double>>(product);

    for (int i = 0; i < product; i++) {
        int[] indicies = FunctionUtils.fromTensorIndex(i, nSplines);
        functions.add(generate(knots, degree, indicies));
    }
    return functions;
}

From source file:com.opengamma.analytics.financial.interestrate.annuity.derivative.AnnuityCouponIborRatchet.java

/**
 * @param payments The payments composing the annuity.
 */// w  w  w  .  j a  v a  2  s .c o  m
public AnnuityCouponIborRatchet(Coupon[] payments) {
    super(payments);
    _isFixed = new boolean[payments.length];
    Validate.isTrue((payments[0] instanceof CouponFixed) || (payments[0] instanceof CouponIborGearing),
            "First coupon should be CouponFixed or a CouponIborGearing");
    _isFixed[0] = (payments[0] instanceof CouponFixed);
    for (int looppay = 1; looppay < payments.length; looppay++) {
        Validate.isTrue(
                (payments[looppay] instanceof CouponFixed) || (payments[looppay] instanceof CouponIborRatchet),
                "Next coupons should be CouponFixed or CouponIborRatchet");
        _isFixed[looppay] = (payments[looppay] instanceof CouponFixed);
    }
}

From source file:com.opengamma.analytics.financial.interestrate.inflation.method.CouponInflationZeroCouponInterpolationDiscountingMethod.java

@Override
public CurrencyAmount presentValue(InstrumentDerivative instrument, MarketBundle market) {
    Validate.isTrue(instrument instanceof CouponInflationZeroCouponInterpolation,
            "Zero-coupon inflation with start of month reference date.");
    return presentValue((CouponInflationZeroCouponInterpolation) instrument, market);
}

From source file:de.matzefratze123.heavyspleef.core.player.SpleefPlayer.java

public UUID getUniqueId() {
    Validate.isTrue(isOnline(), "Player is not online");
    return getBukkitPlayer().getUniqueId();
}

From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.FourierPricer.java

public double price(final BlackFunctionData data, final EuropeanVanillaOption option,
        final MartingaleCharacteristicExponent ce, final double alpha, final double limitTolerance,
        final boolean useVarianceReduction) {
    Validate.notNull(data, "data");
    Validate.notNull(option, "option");
    Validate.notNull(ce, "characteristic exponent");
    Validate.isTrue(limitTolerance > 0, "limit tolerance must be > 0");
    Validate.isTrue(alpha <= ce.getLargestAlpha() && alpha >= ce.getSmallestAlpha(),
            "The value of alpha is not valid for the Characteristic Exponent and will most likely lead to mispricing. Choose a value between "
                    + ce.getSmallestAlpha() + " and " + ce.getLargestAlpha());
    final EuropeanPriceIntegrand integrand = new EuropeanPriceIntegrand(ce, alpha, useVarianceReduction);
    final EuropeanCallFourierTransform psi = new EuropeanCallFourierTransform(ce);
    final double strike = option.getStrike();
    final double t = option.getTimeToExpiry();
    final boolean isCall = option.isCall();
    final double forward = data.getForward();
    final double discountFactor = data.getDiscountFactor();
    final Function1D<ComplexNumber, ComplexNumber> characteristicFunction = psi.getFunction(t);
    final double xMax = LIMIT_CALCULATOR.solve(characteristicFunction, alpha, limitTolerance);
    final Function1D<Double, Double> func = integrand.getFunction(data, option);
    final double integral = Math.exp(-alpha * Math.log(strike / forward))
            * _integrator.integrate(func, 0.0, xMax) / Math.PI;
    if (useVarianceReduction) {
        final double black = BLACK_PRICE_FUNCTION.getPriceFunction(option).evaluate(data);
        final double diff = discountFactor * forward * integral;
        return diff + black;
    }/*from   ww w . j  ava  2s  . co m*/

    if (isCall) {
        if (alpha > 0.0) {
            return discountFactor * forward * integral;
        } else if (alpha < -1.0) {
            return discountFactor * (forward * (1 + integral) - strike);
        } else {
            return discountFactor * forward * (integral + 1);
        }
    }
    if (alpha > 0.0) {
        return discountFactor * (forward * (integral - 1) + strike);
    } else if (alpha < -1.0) {
        return discountFactor * forward * integral;
    }
    return discountFactor * (forward * integral + strike);
}

From source file:com.mxhero.plugin.cloudstorage.onedrive.api.command.RefreshBusinessCommand.java

/**
 * Instantiates a new command.//from w  w w.jav  a 2  s . co m
 *
 * @param clientBuilder the client builder
 * @param application the application
 * @param credential the credential
 */
public RefreshBusinessCommand(HttpClientBuilder clientBuilder, Application application, Credential credential) {
    super(clientBuilder, application, credential);
    Validate.isTrue(credential instanceof BusinessCredential, "credential must be of type BusinessCredential");
}