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.financial.analytics.model.forex.option.black.FXOneLookBarrierOptionBlackGammaFunction.java

@Override
protected Object computeValues(final Set<ForexOptionVanilla> vanillaOptions,
        final ForexOptionDataBundle<?> market) {
    Validate.isTrue(market instanceof SmileDeltaTermStructureDataBundle,
            "FXOneLookBarrierOptionBlackGammaFunction requires a Vol surface with a smile.");
    double sum = 0.0;
    for (final ForexOptionVanilla derivative : vanillaOptions) {
        final CurrencyAmount gammaCcy = derivative.accept(CALCULATOR, market);
        sum += gammaCcy.getAmount();//from   www .  j  a va  2 s  .c o m
    }
    return sum;
}

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

/**
 * @param x The array of data, not null. Must contain at least two data points.
 * @return The sample central moment./* w  w w .  ja v  a  2 s.c om*/
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length >= 2, "Need at least 2 data points to calculate central moment");
    if (_n == 0) {
        return 1.;
    }
    final double mu = MEAN.evaluate(x);
    double sum = 0;
    for (final Double d : x) {
        sum += Math.pow(d - mu, _n);
    }
    return sum / (x.length - 1);
}

From source file:com.relicum.ipsum.Signs.GenericSign.java

default void setLine(int i, String line) {

    Validate.isTrue((i < 4 && i > -1), "Index for a sign line must be between 0 and 3");
    line = ChatColor.translateAlternateColorCodes('&', line);
    Validate.isTrue(line.length() < 15, "The length of a sign line must be below 16 characters");

    getLines()[i] = line;/*  w  w  w.ja va2 s  .  c o m*/
}

From source file:bigbluej.DocumentCommand.java

private DocumentCommand(String url, String name, byte[] content) {
    if (StringUtils.isNotBlank(url)) {
        Validate.isTrue(ArrayUtils.isEmpty(content), "when set url, don't set content too!");
        Validate.isTrue(StringUtils.isBlank(name), "when set url, don't set name too!");
    } else if (StringUtils.isNotBlank(name)) {
        Validate.isTrue(ArrayUtils.isNotEmpty(content), "when set name, set content too!");
        Validate.isTrue(StringUtils.isBlank(url), "when set name, don't set url too!");
    } else {//from  ww  w  .  j ava  2s.c o  m
        throw new IllegalArgumentException("set either name or url!");
    }
    this.url = url;
    this.name = name;
    this.content = content;
}

From source file:com.opengamma.analytics.financial.model.option.DistributionFromImpliedVolatility.java

public DistributionFromImpliedVolatility(final double forward, final double maturity,
        final Function1D<Double, Double> impliedVolFunction) {
    Validate.isTrue(maturity > 0.0, "maturity <= 0");
    Validate.isTrue(forward > 0.0, "forward <= 0");
    Validate.notNull(impliedVolFunction, "implied vol function");
    _f = forward;//from   w  ww. j  a  v a2 s  .c  om
    _volFunc = impliedVolFunction;
    _rootT = Math.sqrt(maturity);
}

From source file:com.opengamma.analytics.financial.interestrate.payments.market.CouponFixedDiscountingMarketMethod.java

@Override
public CurrencyAmount presentValue(final InstrumentDerivative instrument, final MarketBundle market) {
    Validate.isTrue(instrument instanceof CouponFixed, "Coupon Fixed");
    return presentValue((CouponFixed) instrument, market);
}

From source file:ar.com.zauber.labs.kraken.providers.wikipedia.model.impl.LangUtils.java

/** tira un {@link IllegalArgumentException} si el lenguaje no es conocido */
public static void validateLang(final String lang) {
    if (KNOWN_LANGUAGES != null) { // puede estar inicializandose 
        Validate.isTrue(KNOWN_LANGUAGES.containsKey(lang), lang + " no es un lenguaje rfc4646 valido");
    }//from   ww  w .  j av a  2  s.co  m
}

From source file:com.pgcraft.spectatorplus.arenas.ArenaSetup.java

/**
 * Switch to the next setup step.//  ww  w  . j  ava  2s.  c om
 *
 * @param location The selected location for this step. {@code null} if it's the first step.
 */
public void next(Location location) {
    step++;

    Validate.isTrue(step <= 0 || location != null, "The location is required for the second and third steps.");

    Player player = Bukkit.getPlayer(playerID);
    Spectator spectator = SpectatorPlus.get().getPlayerData(playerID);

    if (player == null || !player.isOnline()) {
        PluginLogger.warning(
                "Arena setup was executed for an offline player (UUID {0})! This is not a normal thing. Aborting setup.",
                playerID);
        spectator.setArenaSetup(null);

        return;
    }

    switch (step) {
    case 0:
        SpectatorPlus.get().sendMessage(player,
                ChatColor.GOLD + "You just entered arena setup mode for the arena " + ChatColor.RED + arenaName
                        + ChatColor.GOLD + ".",
                true);
        player.sendMessage(ChatColor.GOLD
                + "You'll have to mark the two opposite corners of the arena, which is a 3D rectangular structure.");
        player.sendMessage(ChatColor.GOLD + "Punch the " + ChatColor.RED + "first corner" + ChatColor.GOLD
                + " of the arena.");
        player.sendMessage(ChatColor.GRAY + "You can also use the command " + ChatColor.WHITE
                + "/spec arena corner" + ChatColor.GRAY + " to set the corner at your current location.");
        break;

    case 1:
        corner1 = location;
        SpectatorPlus.get().sendMessage(player, ChatColor.GOLD + "Now, punch the " + ChatColor.RED
                + "second corner" + ChatColor.GOLD + " of the arena, at the opposite corner.", true);
        player.sendMessage(ChatColor.GRAY + "You can still use the " + ChatColor.WHITE + "/spec arena corner"
                + ChatColor.GRAY + " command.");
        break;

    case 2:
        corner2 = location;
        try {
            SpectatorPlus.get().getArenasManager().registerArena(new Arena(arenaName, corner1, corner2));
            SpectatorPlus.get().sendMessage(player,
                    "The arena " + ChatColor.RED + arenaName + ChatColor.GOLD + " was successfully registered!",
                    true);
        } catch (IllegalArgumentException e) {
            SpectatorPlus.get().sendMessage(player, ChatColor.RED + "Cannot register the arena.", true);
            player.sendMessage(ChatColor.RED + "Error: " + e.getMessage());
        }
        spectator.setArenaSetup(null);
        break;
    }
}

From source file:com.opengamma.analytics.financial.var.parametric.DeltaCovarianceMatrixStandardDeviationCalculator.java

@Override
public Double evaluate(final Map<Integer, ParametricVaRDataBundle> data) {
    Validate.notNull(data, "data");
    final ParametricVaRDataBundle firstOrderData = data.get(1);
    Validate.notNull(firstOrderData, "first order data");
    final Matrix<?> delta = firstOrderData.getSensitivities();
    final int s1 = delta.getNumberOfElements();
    Validate.isTrue(s1 > 0, "Value delta vector contained no data");
    final DoubleMatrix2D covariance = firstOrderData.getCovarianceMatrix();
    return Math.sqrt(_algebra.getInnerProduct(delta, _algebra.multiply(covariance, delta)));
}

From source file:com.opengamma.analytics.math.matrix.DoubleMatrix2D.java

/**
 * Sets up an empty matrix/* w  w  w. j a v  a 2 s.c o  m*/
 * @param rows Number of rows
 * @param columns Number of columns
 */
public DoubleMatrix2D(final int rows, final int columns) {
    Validate.isTrue(rows > 0, "row number cannot be negative or zero");
    Validate.isTrue(columns > 0, "column number cannot be negative or zero");
    _rows = rows;
    _columns = columns;
    _data = new double[_rows][_columns];
    _elements = _rows * _columns;
}