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:fr.zcraft.zbanque.utils.LocationUtils.java

/**
 * Converts a string location (format "x;y;z" or "x;y;z;pitch" or "x;y;z;pitch;yaw") to a
 * location object./* w  ww  .  jav a2 s.  co m*/
 *
 * @param world The world.
 * @param raw   The raw string.
 *
 * @return The location.
 * @throws IllegalArgumentException if the format is not valid.
 */
public static Location string2Location(World world, String raw) {
    String[] parts = raw.split(";");
    Validate.isTrue(parts.length >= 3, "The location must contains at least three coordinates");

    Location location = new Location(world, Double.valueOf(parts[0]), Double.valueOf(parts[1]),
            Double.valueOf(parts[2]));

    if (parts.length >= 4)
        location.setPitch(Float.valueOf(parts[3]));

    if (parts.length >= 5)
        location.setYaw(Float.valueOf(parts[4]));

    return location;
}

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

/**
 * {@inheritDoc}/* w  ww.j a v  a 2s .  c o m*/
 */
@Override
public double getInnerProduct(final Matrix<?> m1, final Matrix<?> m2) {
    Validate.notNull(m1, "m1");
    Validate.notNull(m2, "m2");
    if (m1 instanceof DoubleMatrix1D && m2 instanceof DoubleMatrix1D) {
        final double[] a = ((DoubleMatrix1D) m1).getData();
        final double[] b = ((DoubleMatrix1D) m2).getData();
        final int l = a.length;
        Validate.isTrue(l == b.length, "Matrix size mismacth");
        double sum = 0.0;
        for (int i = 0; i < l; i++) {
            sum += a[i] * b[i];
        }
        return sum;
    }
    throw new IllegalArgumentException(
            "Can only find inner product of DoubleMatrix1D; have " + m1.getClass() + " and " + m2.getClass());
}

From source file:ca.uhn.hl7v2.testpanel.util.Range.java

public Range(int theStart, int theEnd) {
    Validate.isTrue(theStart >= 0, "theStart: " + theStart);
    Validate.isTrue(theEnd >= 0, "theEnd: " + theStart);

    if (theStart > theEnd) {
        myEnd = theStart;//from  ww w.  j  ava2 s .c o m
        myStart = theEnd;
    } else {
        myStart = theStart;
        myEnd = theEnd;
    }
}

From source file:com.opengamma.analytics.financial.instrument.swap.SwapFixedONDefinition.java

/**
 * Constructor of the fixed-OIS swap from its two legs.
 * @param fixedLeg The fixed leg.//from   w w  w .ja  v a  2 s.  co m
 * @param oisLeg The OIS leg.
 */
public SwapFixedONDefinition(final AnnuityCouponFixedDefinition fixedLeg,
        final AnnuityCouponOISDefinition oisLeg) {
    super(fixedLeg, oisLeg);
    Validate.isTrue(fixedLeg.getCurrency() == oisLeg.getCurrency(), "Legs should have the same currency");
}

From source file:fr.ritaly.dungeonmaster.item.Scroll.java

/**
 * Creates a scroll with the given text.
 *
 * @param text//  w w w  .java2 s. com
 *            a list of strings representing the scroll's text. Can't be
 *            null or empty.
 */
public Scroll(final List<String> text) {
    super(Type.SCROLL);

    Validate.notNull(text, "The given list of text lines is null");
    Validate.isTrue(!text.isEmpty(), "The given list of text lines is empty");

    this.text = new ArrayList<String>(text);
}

From source file:it.filosganga.mobile.widgets.component.TableHeader.java

public int getColumnIndex(TableColumn column) {

    Validate.isTrue(columns.contains(column), "The given cell must be child of this row");

    return sum(extractProperty(columns.subList(0, columns.indexOf(column)), "colspan")).intValue();
}

From source file:com.hp.autonomy.aci.content.fieldtext.MATCHALL.java

public MATCHALL(final Iterable<String> fields, final Iterable<String> values) {
    super("MATCHALL", fields, values);
    Validate.isTrue(!getValues().isEmpty(), "No values specified");
}

From source file:com.hp.autonomy.aci.content.fieldtext.NOTMATCH.java

public NOTMATCH(final Iterable<String> fields, final Iterable<String> values) {
    super("NOTMATCH", fields, values);
    Validate.isTrue(!getValues().isEmpty(), "No values specified");
}

From source file:com.opengamma.analytics.math.curve.InterpolatedCurveBuildingFunction.java

public LinkedHashMap<String, InterpolatedDoublesCurve> evaluate(DoubleMatrix1D x) {
    Validate.notNull(x, "null data x");
    Validate.isTrue(_nNodes == x.getNumberOfElements(), "x wrong length");

    LinkedHashMap<String, InterpolatedDoublesCurve> res = new LinkedHashMap<String, InterpolatedDoublesCurve>();
    int index = 0;

    for (final String name : _interpolators.keySet()) {
        final Interpolator1D interpolator = _interpolators.get(name);
        final double[] nodes = _knotPoints.get(name);
        final double[] values = Arrays.copyOfRange(x.getData(), index, index + nodes.length);
        index += nodes.length;//from   ww w. j  a  v a 2  s  .  co m
        InterpolatedDoublesCurve curve = InterpolatedDoublesCurve.from(nodes, values, interpolator);
        res.put(name, curve);
    }

    return res;
}

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

/**
 * /*from   www . j  a  v a2  s  .c om*/
 * @param strike The strike
 * @param expiry The expiry
 * @param power The power, greater than zero
 * @param isCall Is the option a call or put
 */
public AsymmetricPowerOptionDefinition(final double strike, final Expiry expiry, final double power,
        final boolean isCall) {
    super(strike, expiry, isCall);
    Validate.isTrue(power > 0, "power must be > 0");
    _power = power;
}