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.afterkraft.kraftrpg.bukkit.events.entity.BukkitManaChangeEvent.java

public BukkitManaChangeEvent(Insentient being, int fromMana, int toMana, ManaChangeReason reason) {
    super(being);
    Validate.notNull(reason, "Cannot create an event with a null ManaChangeReason!");
    Validate.isTrue(toMana >= 0, "Cannot handle a Mana event where the mana is less than zero!");
    this.fromMana = fromMana;
    this.toMana = toMana;
    this.reason = reason;
}

From source file:com.opengamma.analytics.financial.interestrate.swaption.method.SwaptionPhysicalG2ppSuccessiveRootFinderCalibrationEngine.java

/**
 * Add an instrument to the basket and the associated calculator.
 * @param instrument An interest rate derivative.
 * @param method A calculator.//from   w ww.  j  av a 2 s. com
 */
@Override
public void addInstrument(final InstrumentDerivative instrument, final PricingMethod method) {
    Validate.isTrue(instrument instanceof SwaptionPhysicalFixedIbor,
            "Calibration instruments should be swaptions");
    getBasket().add(instrument);
    getMethod().add(method);
    getCalibrationPrice().add(0.0);
    _calibrationTimes.add(((SwaptionPhysicalFixedIbor) instrument).getTimeToExpiry());
}

From source file:net.daboross.bukkitdev.skywars.world.providers.WorldEditProtobufStorageProvider.java

@Override
public void copyArena(final World arenaWorld, final SkyArena arena, final SkyBlockLocation target) {
    Validate.isTrue(target.world.equals(arenaWorld.getName()), "Destination world not arena world.");

    if (editWorld == null) {
        editWorld = new BukkitWorld(arenaWorld);
    }//from ww  w  .  j a  va2  s.c  o m

    MemoryBlockArea area = cache.get(arena.getArenaName());
    Validate.notNull(area, "Arena " + arena.getArenaName() + " not loaded.");

    area.applyWorldEdit(arenaWorld, editWorld, target.x, target.y, target.z,
            new RandomChestProvider(plugin.getChestRandomizer(), arena));
}

From source file:com.opengamma.analytics.math.linearalgebra.CholeskyDecompositionOpenGamma.java

/**
 * Perform the decomposition with a given symmetry and positivity threshold.
 * @param matrix The matrix to decompose.
 * @param symmetryThreshold The symmetry threshold.
 * @param positivityThreshold The positivity threshold.
 * @return The Cholesky decomposition.//from w  ww.j a v  a2s  . c o  m
 */
public CholeskyDecompositionResult evaluate(final DoubleMatrix2D matrix, final double symmetryThreshold,
        final double positivityThreshold) {
    Validate.notNull(matrix, "Matrix null");
    int nbRow = matrix.getNumberOfRows();
    int nbCol = matrix.getNumberOfColumns();
    Validate.isTrue(nbRow == nbCol, "Matrix not square");
    double[][] l = new double[nbRow][nbRow];
    // Check symmetry and initial fill of _lTArray
    double[][] matrixData = matrix.getData();
    for (int looprow = 0; looprow < nbRow; looprow++) {
        for (int loopcol = 0; loopcol <= looprow; loopcol++) {
            double maxValue = Math.max(Math.abs(matrixData[looprow][loopcol]),
                    Math.abs(matrixData[loopcol][looprow]));
            double diff = Math.abs(matrixData[looprow][loopcol] - matrixData[loopcol][looprow]);
            Validate.isTrue(diff <= maxValue * symmetryThreshold, "Matrix not symmetrical");
            l[looprow][loopcol] = matrixData[looprow][loopcol];
        }
    }
    // The decomposition
    for (int loopcol = 0; loopcol < nbCol; loopcol++) {
        Validate.isTrue(l[loopcol][loopcol] > positivityThreshold, "Matrix not positive");
        l[loopcol][loopcol] = Math.sqrt(l[loopcol][loopcol]); // Pivot
        double lInverse = 1.0 / l[loopcol][loopcol];
        for (int looprow = loopcol + 1; looprow < nbRow; looprow++) { // Current column
            l[looprow][loopcol] *= lInverse;
        }
        for (int j = loopcol + 1; j < nbRow; j++) { // Other columns
            for (int i = j; i < nbRow; i++) {
                l[i][j] -= l[i][loopcol] * l[j][loopcol];
            }
        }
    }
    return new CholeskyDecompositionOpenGammaResult(l);
}

From source file:it.gualtierotesta.gdocx.GTr.java

/**
 * Set row height with EXACT rule/*from  ww  w.  j a v a2s  . c  om*/
 *
 * @param lHeight height of the row
 * @return same GTr instance
 */
@Nonnull
public GTr height(final long lHeight) {

    Validate.isTrue(0L < lHeight, "Height value not valid");

    final CTHeight cth = FACTORY.createCTHeight();
    cth.setVal(BigInteger.valueOf(lHeight));
    cth.setHRule(STHeightRule.EXACT);
    trPr.getCnfStyleOrDivIdOrGridBefore().add(FACTORY.createCTTrPrBaseTrHeight(cth));
    return this;
}

From source file:ar.com.zauber.garfio.modules.mantis.model.actions.FixInVersionAction.java

/**
 * Creates the AddNoteToIssueAction.//from w w w  . j av a2 s . c o m
 *
 * @param issue involved issue 
 * @param session tracker session
 * @throws JMTException on i/o error.
 */
public FixInVersionAction(final MantisIssue issue, final MantisTrackerSession session, final String aversion)
        throws JMTException {
    super(issue, session);
    Validate.isTrue(!StringUtils.isBlank(aversion), "you must set a version number");

    final String versionNumber = StringUtils.trim(aversion);
    final ProjectVersionData[] versions = session.getSession()
            .getVersions(mantisIssue.getIssueData().getProject().getId().longValue());
    String tmp = null;
    for (final ProjectVersionData v : versions) {
        if (v.getName().equalsIgnoreCase(versionNumber)) {
            if (v.getReleased()) {
                throw new IllegalArgumentException("you specified version `" + versionNumber
                        + "' but it has already been released. " + "Ignoring action.");
            } else {
                tmp = v.getName();
                break;
            }
        }
    }
    if (tmp == null) {
        final StringBuilder sb = new StringBuilder();
        sb.append("you specified version `");
        sb.append(versionNumber);
        sb.append("' but posible versions are: ");
        for (final ProjectVersionData v : versions) {
            if (!v.getReleased()) {
                sb.append(v.getName());
                sb.append(' ');
            }
        }
        sb.append(". Ignoring action.");
        throw new IllegalArgumentException(sb.toString());
    }
    this.version = tmp;
}

From source file:fr.ritaly.dungeonmaster.actuator.LoopingActuator.java

public LoopingActuator(int max, Actuator actuator) throws CloneNotSupportedException {
    Validate.notNull(actuator, "The given actuator is null");
    Validate.isTrue(max >= 0, "The given max count <" + max + "> must be positive or zero");

    this.prototype = actuator;
    this.max = max;
    this.label = getClass().getSimpleName() + "[" + max + " x " + actuator.getLabel() + "]";
}

From source file:com.opengamma.analytics.financial.model.finitedifference.HyperbolicMeshing.java

/**
 * Creates a non-uniform set of points according to the formula x_i = alpha * beta*Sinh(i/N*gamma + delta), where the points run from 
 * x_0 to x_N (i.e. there are N+1 points) and the highest concentration is around some specified point (e.g. the strike for solving option problems)
 * @param xMin The value of x_0/*from   ww w  .  jav a 2  s  .c om*/
 * @param xMax The value of x_N  
 * @param xCent The value where the concentration of points is highest (<b>Note</b> there is no guarantee the a point will correspond exactly 
 * with this value)
 * @param nPoints Number of Points (equal to N+1 in the above formula)
 * @param beta Bunching parameter. A value great than zero. Very small values gives a very high density of points around the specified point, with the
 * density quickly falling away in both directions (the total number of points is fixed), while the distribution tends to uniform for large values. Value 
 * greater than 1 are fairly uniform
 */
public HyperbolicMeshing(final double xMin, final double xMax, final double xCent, final int nPoints,
        final double beta) {
    super(nPoints);
    Validate.isTrue(xMax > xMin, "need xMax > xMin");
    Validate.isTrue(xMax >= xCent && xCent >= xMin, "need xCent between upper and lower bounds");
    Validate.isTrue(beta > 0, "need beta > 0");

    _l = xMin;
    _r = xMax;
    _alpha = xCent;
    _beta = beta * (xMax - xMin);
    _delta = TrigonometricFunctionUtils.asinh((xMin - xCent) / _beta);
    _gamma = (TrigonometricFunctionUtils.asinh((xMax - xCent) / _beta) - _delta);
    _um = new UniformMeshing(nPoints);
    _fpValues = null;
}

From source file:io.horizondb.io.BitSet.java

/**
 * Creates a new <code>BitSet</code> instance with the specified capacity.
 * /*from w  ww  .j  ava  2s.  co m*/
 * @param capacity the <code>BitSet</code> capacity.
 */
public BitSet(int capacity) {

    Validate.isTrue(capacity > 0 && capacity <= 62,
            "The capacity must be greater than zero " + "and less or equals to 62");

    this.readingMask = 1;
    this.writingMask = 1;
    this.limit = computeLimit(capacity);
    this.capacity = capacity;
}

From source file:fr.ritaly.dungeonmaster.actuator.SimpleActuator.java

public SimpleActuator(int count, TriggerAction action, Triggerable... targets) {
    Validate.isTrue(count > 0, "The given tick count <" + count + "> must be positive");
    Validate.notNull(action, "The given trigger action is null");
    Validate.notNull(targets, "The given array is null");
    Validate.isTrue(targets.length > 0, "The given array is empty");

    final StringBuilder builder = new StringBuilder(512);

    boolean first = true;
    for (Triggerable triggerable : targets) {
        if (!first) {
            builder.append(",");
        } else {//from  www.j  av  a2s.  co m
            first = false;
        }

        builder.append(triggerable);
    }

    this.label = "Actuator[" + builder + "]";
    this.temporizer = new Temporizer(label, count);
    this.action = action;
    this.targets = Arrays.asList(targets);
    this.max = count;
}