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:ar.com.zauber.commons.spring.web.misc.HttpPagingHelper.java

/**
 * Creates the HttpPagingHelper./*from  w ww. j ava  2s.c o  m*/
 *
 * @param resultsPerPage cantidad default de resultados por pagina
 * @param maxResultsPerPage cantidad maxima de resultados por pagina
 */
public HttpPagingHelper(final int resultsPerPage, final int maxResultsPerPage) {

    Validate.isTrue(resultsPerPage > 0);
    Validate.isTrue(maxResultsPerPage > 0);

    this.resultsPerPage = resultsPerPage;
    this.maxResultsPerPage = maxResultsPerPage;
}

From source file:de.xaniox.heavyspleef.core.game.GameManager.java

public void addGame(Game game, boolean save) {
    String name = game.getName();

    synchronized (games) {
        Validate.isTrue(!games.containsKey(name));

        games.put(game.getName(), game);
    }//w  w  w .j  a  v  a 2  s  .  c o m

    if (save) {
        heavySpleef.getDatabaseHandler().saveGame(game, null);
    }
}

From source file:net.daboross.bukkitdev.skywars.api.kits.SkyPotionData.java

@SuppressWarnings("deprecation")
private static SkyPotionData getDataRawData(ItemStack item) {
    Validate.isTrue(item.getType() == Material.POTION);

    return new SkyPotionData(item.getDurability());
}

From source file:ar.com.zauber.commons.xmpp.auth.impl.InmutableXmppCredentialsProvider.java

/** Creates the InmutableXmppCredentialsProvider. */
public InmutableXmppCredentialsProvider(final String username, final String password, final String resource,
        final int priority) {
    Validate.isTrue(!StringUtils.isEmpty(username));
    Validate.isTrue(!StringUtils.isEmpty(password));

    this.username = username;
    this.password = password;
    this.priority = priority;

    if (StringUtils.isEmpty(resource)) {
        this.resource = Base64.encodeObject(new Date());
    } else {// w  w  w .  j av  a2s . c  om
        this.resource = resource;
    }
}

From source file:com.opengamma.analytics.math.function.special.OrthonormalHermitePolynomialFunction.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, p1, p2;
    final double divisor = Math.sqrt(2 * n);
    final double sqrt2 = Math.sqrt(2);
    final DoubleFunction1D x = getX();
    for (int i = 0; i <= n; i++) {
        if (i == 0) {
            polynomials[i] = Pair.of((DoubleFunction1D) F0, getZero());
        } else if (i == 1) {
            polynomials[i] = Pair.of(polynomials[0].getFirst().multiply(sqrt2).multiply(x),
                    (DoubleFunction1D) DF1);
        } else {/*from   www .j a  va 2  s . c om*/
            p1 = polynomials[i - 1].getFirst();
            p2 = polynomials[i - 2].getFirst();
            p = p1.multiply(x).multiply(Math.sqrt(2. / i)).subtract(p2.multiply(Math.sqrt((i - 1.) / i)));
            dp = p1.multiply(divisor);
            polynomials[i] = Pair.of(p, dp);
        }
    }
    return polynomials;
}

From source file:com.opengamma.analytics.financial.equity.capm.CAPMBetaCalculator.java

@Override
public Double evaluate(final DoubleTimeSeries<?>... ts) {
    Validate.notNull(ts, "ts");
    final int n = ts.length;
    Validate.isTrue(n > 1);
    if (n > 3) {
        s_logger.warn("Found more than two time series; will only use the first two");
    }//from  w ww. j a va 2 s.c  o m
    final DoubleTimeSeries<?> assetReturn = ts[0];
    final DoubleTimeSeries<?> marketReturn = ts[1];
    testTimeSeriesSize(assetReturn, 2);
    testTimeSeriesSize(marketReturn, 2);
    testTimeSeriesDates(assetReturn, marketReturn);
    return _covarianceCalculator.evaluate(assetReturn, marketReturn)
            / _varianceCalculator.evaluate(marketReturn);
}

From source file:com.opengamma.analytics.financial.riskreward.SharpeRatioCalculator.java

public SharpeRatioCalculator(final double returnPeriodsPerYear,
        final DoubleTimeSeriesStatisticsCalculator expectedExcessReturnCalculator,
        final DoubleTimeSeriesStatisticsCalculator standardDeviationCalculator) {
    Validate.isTrue(returnPeriodsPerYear > 0);
    Validate.notNull(expectedExcessReturnCalculator, "expected excess return calculator");
    Validate.notNull(standardDeviationCalculator, "standard deviation calculator");
    _returnPeriodsPerYear = returnPeriodsPerYear;
    _expectedExcessReturnCalculator = expectedExcessReturnCalculator;
    _standardDeviationCalculator = standardDeviationCalculator;
}

From source file:com.opengamma.analytics.math.surface.DoublesSurface.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
 *//*from  w  w  w .  j a  v  a 2s. co  m*/
public DoublesSurface(final double[] xData, final double[] yData, final double[] zData) {
    super();
    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:ar.com.zauber.commons.conversion.util.ExpressionExtractorConverter.java

/** @param expression una expresion EL {root.size} */
public ExpressionExtractorConverter(final String expression) {
    Validate.isTrue(StringUtils.isNotBlank(expression));
    this.expression = PARSER.parseExpression(expression);
}

From source file:com.codelanx.plotted.Range.java

public Range(int x, int z) {
    Validate.isTrue(x % Range.MAGNITUDE == 0);
    Validate.isTrue(z % Range.MAGNITUDE == 0);
    this.x = x;/*  ww  w  . j  av a2 s  . co m*/
    this.z = z;
}