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.model.option.pricing.fourier.GaussianVegaCE.java

@Override
public Function1D<ComplexNumber, ComplexNumber> getFunction(final double t) {
    Validate.isTrue(t > 0.0, "t > 0");
    final Function1D<ComplexNumber, ComplexNumber> baseFunc = _base.getFunction(t);
    final Function1D<ComplexNumber, ComplexNumber> divFunc = _div.getFunction(t);
    return new Function1D<ComplexNumber, ComplexNumber>() {

        @Override// ww w.j a v  a 2 s . com
        public ComplexNumber evaluate(final ComplexNumber u) {
            Validate.notNull(u, "u");
            final ComplexNumber psi = baseFunc.evaluate(u);
            final ComplexNumber temp = divFunc.evaluate(u);
            final ComplexNumber temp2 = log(temp); //don't like taking logs - bad things happen 
            final ComplexNumber res = add(psi, temp2);
            return res;

        }

    };
}

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

/**
 * @param n The degree of the moment of calculate, cannot be negative
 *///  www  . j  ava  2s .co m
public SampleNormalizedCentralMomentCalculator(final int n) {
    Validate.isTrue(n >= 0, "n must be >= 0");
    _n = n;
    _moment = new SampleCentralMomentCalculator(n);
}

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

/**
 * Constructor.//from w  w w  .  j  a  va 2  s .  c  o m
 * @param decisionTime The time at which an exercise or fixing take place.
 * @param impactTime The time impacting the value at each decision date.
 * @param impactAmount The reference amounts at each impact times.
 */
public DecisionSchedule(double[] decisionTime, double[][] impactTime, double[][] impactAmount) {
    Validate.isTrue(decisionTime.length == impactTime.length, "Incorrect length");
    Validate.isTrue(decisionTime.length == impactAmount.length, "Incorrect length");
    _decisionTime = decisionTime;
    _impactTime = impactTime;
    _impactAmount = impactAmount;
}

From source file:io.yields.math.framework.range.IntegerRange.java

public IntegerRange(Integer min, Integer max, boolean minOpen, boolean maxOpen) {
    super(min, max, minOpen, maxOpen);
    /**/*  ww  w . ja v a  2s  .c  o  m*/
     * if interval is ]i, i+1[, then it is empty
     */
    Validate.isTrue(!(min == max - 1 && minOpen && maxOpen), "Interval cannot be empty.");
}

From source file:ar.com.zauber.commons.web.transformation.censors.impl.AbstractCensorAccess.java

/** uri */
public final void validate(final String uri) {
    try {/*from  w  w  w. j av a  2  s .co m*/
        new URL(uri);
    } catch (final MalformedURLException e) {
        Validate.isTrue(uri.startsWith("/"), "URI `" + uri + "' is not absolute");
    }
}

From source file:com.opengamma.analytics.math.function.special.DoubleRampFunction.java

/**
 * @param x1 The lower edge //from   w ww  . j  a  v  a  2 s. c om
 * @param x2 The upper edge, must be greater than x1
 * @param y1 The height below x1 
 * @param y2 The height above x2 
 */
public DoubleRampFunction(final double x1, final double x2, final double y1, final double y2) {
    Validate.isTrue(x1 < x2, "x1 must be less than x2");
    _x1 = x1;
    _x2 = x2;
    _y1 = y1;
    _y2 = y2;
}

From source file:com.vmware.identity.performanceSupport.PerfBucketMetrics.java

/**
 * c'tor of a metric object with first data entry
 * @param value date entry >=0/*from  w w  w .  j  av a2  s.com*/
 */
public PerfBucketMetrics(long value) {
    Validate.isTrue(value >= 0, Long.toString(value));
    hits = 1;
    totalMs = value;
    ceilingMs = value;
    effectiveCeilingMs = 0;
    floorMs = value;
}

From source file:com.opengamma.analytics.math.function.RealPolynomialFunction1D.java

/**
 * The array of coefficients for a polynomial
 * $p(x) = a_0 + a_1 x + a_2 x^2 + ... + a_{n-1} x^{n-1}$
 * is $\\{a_0, a_1, a_2, ..., a_{n-1}\\}$.
 * @param coefficients The array of coefficients, not null or empty
 *//*from w w  w  .jav  a2s .c o  m*/
public RealPolynomialFunction1D(final double... coefficients) {
    Validate.notNull(coefficients);
    Validate.isTrue(coefficients.length > 0, "coefficients length must be greater than zero");
    _coefficients = coefficients;
    _n = _coefficients.length;
}

From source file:io.cloudslang.lang.cli.utils.MetadataHelperImpl.java

@Override
public String extractMetadata(File file) {
    Validate.notNull(file, "File can not be null");
    Validate.notNull(file.getAbsolutePath(), "File path can not be null");
    Validate.isTrue(file.isFile(), "File: " + file.getName() + " was not found");

    Metadata metadata = slang.extractMetadata(SlangSource.fromFile(file));

    return prettyPrint(metadata);
}

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

public Barrier(final KnockType knock, final BarrierType barrier, final ObservationType observation,
        final double level) {
    Validate.notNull(knock, "knock type");
    Validate.notNull(barrier, "barrier type");
    Validate.notNull(observation, "observation type");
    Validate.isTrue(level > 0, "barrier level must be > 0");
    _knock = knock;/*from  w w w  .jav  a 2 s.c o m*/
    _barrier = barrier;
    _observation = observation;
    _level = level;
}