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:com.opengamma.analytics.financial.model.finitedifference.MarkovChain.java

public MarkovChain(final double vol1, final double vol2, final double lambda12, final double lambda21,
        final double probState1, final int seed) {
    Validate.isTrue(vol1 >= 0);
    Validate.isTrue(vol2 >= 0);//  www .ja  v  a2 s .  c  o  m
    Validate.isTrue(lambda12 >= 0);
    Validate.isTrue(lambda21 >= 0);
    Validate.isTrue(probState1 >= 0 && probState1 <= 1.0);
    _vol1 = vol1;
    _vol2 = vol2;
    _lambda12 = lambda12;
    _lambda21 = lambda21;
    _probState1 = probState1;
    _pi1 = lambda21 / (lambda12 + lambda21);
    _rand = new MersenneTwister64(seed);
}

From source file:com.vmware.identity.interop.ldap.LdapConnectionFactoryEx.java

/**
 * Create a LDAP connection with the specified host & port parameter
 * @param host  cannot be null/*  w w  w.  j  ava 2  s  .  c o  m*/
 * @param port  positive number
 * @param connOptions connection options, cannot be null
 * @return the LDAP scheme connection.
 */
public ILdapConnectionEx getLdapConnection(String host, int port, List<LdapSetting> connOptions) {
    Validate.notNull(host);
    Validate.isTrue(port > 0);

    return getLdapConnection(PlatformUtils.getConnectionUriDefaultScheme(host, port), connOptions);
}

From source file:io.yields.math.concepts.operator.Smoothness.java

@Override
public DescriptiveStatistics apply(Collection<Tuple> tuples) {
    Validate.isTrue(tuples.size() > order);
    //first we normalize the tuples so data fits in the unit square
    List<Tuple> normalizedData = normalize(tuples);
    //calculate error (i.e. distance between tuple y and fitted polynomial
    RealMatrix error = computeDistance(normalizedData);
    //group in stats object
    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (double value : error.getColumn(0)) {
        stats.addValue(Math.abs(value));
    }// w w w.j a va  2 s  .  c  om
    return stats;
}

From source file:io.tilt.minka.business.leader.distributor.ClassicalPartitionSolver.java

public List<List<ShardDuty>> balance(final int shards, final List<ShardDuty> weightedDuties) {
    Validate.isTrue(shards > 1);
    Validate.noNullElements(weightedDuties);
    final int[] indexes = buildIndexes(weightedDuties, shards);
    final List<List<ShardDuty>> distro = new ArrayList<>();
    int fromIdx = 0;
    for (int idx : indexes) {
        distro.add(discoverFormedGroups(weightedDuties, fromIdx, idx));
        fromIdx = idx;//  w w  w.j a v  a  2s . co m
    }
    if (indexes[indexes.length - 1] < weightedDuties.size()) {
        distro.add(discoverFormedGroups(weightedDuties, fromIdx, weightedDuties.size()));
    }
    logDistributionResult(distro);
    return distro;
}

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

@Test
public void momentTest() {

    final double[] res1 = CHAIN.getMoments(T, SIMS);
    final double[] res2 = CHAIN_APPROX.getMoments(T);
    Validate.isTrue(res1.length == res2.length);
    for (int i = 0; i < res1.length; i++) {
        assertEquals(res1[i], res2[i], 5e-3 * res1[i]);
    }/*  w ww. j a  v  a 2  s  .c o m*/
}

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

public MarkovChainApprox(final double vol1, final double vol2, final double lambda12, final double lambda21,
        final double probState1, final double expiry) {
    Validate.isTrue(vol1 >= 0);
    Validate.isTrue(vol2 >= 0);/*from w  w w.j  a v  a2 s .c  o m*/
    Validate.isTrue(lambda12 >= 0);
    Validate.isTrue(lambda21 >= 0);
    Validate.isTrue(probState1 >= 0 && probState1 <= 1.0);
    _vol1 = vol1;
    _vol2 = vol2;
    _nu1 = vol1 * vol1;
    _nu2 = vol2 * vol2;
    _lambda12 = lambda12;
    _lambda21 = lambda21;
    _lambda = lambda12 + lambda21;
    _probState1 = probState1;
    _theta = lambda21 / _lambda;
    _t = expiry;

    final double wMin = _probState1 * Math.exp(-_lambda12 * expiry); //prob of always being in state 1
    final double wMax = (1 - _probState1) * Math.exp(-_lambda21 * expiry); //prob of always being in state 1

    final double mu = getM1(expiry);
    final double modM1 = getModMoment(1, wMin, wMax, mu, mu);
    final double modM2 = getModMoment(2, wMin, wMax, mu, getM2(expiry));
    final double modM3 = getModMoment(3, wMin, wMax, mu, getM3(expiry));
    final double skewOverVar = modM3 / modM2;
    double delta2;
    double w;
    double delta1 = (-skewOverVar + Math.sqrt(FunctionUtils.square(skewOverVar) + 4 * modM2)) / 2.0;
    if (delta1 > modM1) {
        delta1 = (modM1 - _nu1) / 2;
        delta2 = modM2 / delta1;
    } else {
        delta2 = delta1 + skewOverVar;
    }
    w = delta2 / (delta1 + delta2);
    Validate.isTrue(w >= 0.0 && w <= 1.0, "weight not physical");

    _weights = new double[] { wMin, wMax, w * (1 - wMin - wMax), (1 - w) * (1 - wMin - wMax) };
    _vols = new double[] { _vol1, _vol2, Math.sqrt(modM1 - delta1), Math.sqrt(modM1 + delta2) };
}

From source file:com.opengamma.analytics.math.ParallelArrayBinarySort.java

/**
 * Sort the content of keys and values simultaneously so that
 * both match the correct ordering. Alters the arrays in place
 * @param keys The keys/*from w  ww  . j  a  va  2s. com*/
 * @param values The values
 */
public static void parallelBinarySort(final long[] keys, final double[] values) {
    Validate.notNull(keys, "x data");
    Validate.notNull(values, "y data");
    Validate.isTrue(keys.length == values.length);
    final int n = keys.length;
    dualArrayQuickSort(keys, values, 0, n - 1);
}

From source file:com.edmunds.etm.management.api.ManagementVips.java

public ManagementVips(ManagementVipType vipType, Collection<ManagementVip> vips) {
    Validate.isTrue(filter(vips, vipType.getCannotContainVipPredicate()).isEmpty());

    this.vipType = vipType;
    vipsByMavenModule = createSortedMap(filter(vips, MAVEN_MODULE_VALID), MAVEN_MODULE_FUNCTION);
    hashCode = new HashCodeBuilder().append(vipsByMavenModule).toHashCode();
}

From source file:ar.com.zauber.commons.launcher.Launcher.java

/**
 * Creates the Launcher.//from  w w w .  j  ava 2  s .  c o  m
 *
 * @param webApplicationPath el path a la aplicacion (puede ser un war)
 * @param contextPath donde publicar
 * @param port donde publicar
 */
public Launcher(final String webApplicationPath, final String contextPath, final int port) {
    super();
    Validate.notNull(webApplicationPath);
    Validate.notNull(contextPath);
    Validate.isTrue(!StringUtils.strip(webApplicationPath).equals(""));
    Validate.isTrue(!StringUtils.strip(contextPath).equals(""));
    Validate.isTrue(port > 0);
    this.contextPath = contextPath;
    this.webApplicationPath = webApplicationPath;
    this.port = port;
}

From source file:com.opengamma.financial.analytics.LabelledMatrix2D.java

public LabelledMatrix2D(final S[] xKeys, final Object[] xLabels, final String xTitle, final T[] yKeys,
        final Object[] yLabels, final String yTitle, final double[][] values, final String valuesTitle) {
    Validate.notNull(xKeys, "x keys");
    final int m = xKeys.length;
    Validate.notNull(xLabels, "x labels");
    Validate.isTrue(xLabels.length == m);
    Validate.notNull(yKeys, "y keys");
    final int n = yKeys.length;
    Validate.notNull(yLabels, "y labels");
    Validate.notNull(yLabels.length == n);
    Validate.notNull(values, "values");
    Validate.isTrue(values.length == n, "number of rows of data and y keys must be the same length");
    _xKeys = Arrays.copyOf(xKeys, m);
    _yKeys = Arrays.copyOf(yKeys, n);
    _xLabels = new Object[m];
    _yLabels = new Object[n];
    _xTitle = xTitle;/*from   www  .j  ava  2s . c o m*/
    _yTitle = yTitle;
    _values = new double[n][m];
    for (int i = 0; i < n; i++) {
        Validate.isTrue(values[i].length == m, "number of columns of data and x keys must be the same length");
        _yLabels[i] = yLabels[i];
        for (int j = 0; j < m; j++) {
            if (i == 0) {
                _xLabels[j] = xLabels[j];
            }
            _values[i][j] = values[i][j];
        }
    }
    _valuesTitle = valuesTitle;
    quickSortX();
    quickSortY();
}