Example usage for org.apache.commons.lang Validate notNull

List of usage examples for org.apache.commons.lang Validate notNull

Introduction

In this page you can find the example usage for org.apache.commons.lang Validate notNull.

Prototype

public static void notNull(Object object) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the argument is null.

 Validate.notNull(myObject); 

The message in the exception is 'The validated object is null'.

Usage

From source file:hr.fer.spocc.lexer.action.SubactionFactory.java

public static synchronized Subaction getSubaction(SubactionType type) {
    Validate.notNull(type);
    Validate.isTrue(type.isBuiltIn());/*from w ww.  j a v  a2  s  .co m*/

    // check cache
    Subaction ret = BUILTIN_ACTIONS.get(type);
    if (ret != null) {
        return ret;
    }

    switch (type) {
    case ENTER_STATE:
        ret = new EnterStateSubaction();
        break;
    case NEW_LINE:
        ret = new NewLineSubaction();
        break;
    case TOKENIZE:
        ret = new TokenizeSubaction();
        break;
    case TOKENIZE_FIRST:
        ret = new TokenizeFirstSubaction();
        break;
    case SKIP:
        ret = new SkipSubaction();
        break;
    default:
        throw new UnsupportedOperationException("Custom subactions are not yet implemented");
    }

    // cache the action to avoid new object allocations
    BUILTIN_ACTIONS.put(type, ret);

    return ret;
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Abs.java

public static void inPlace(int[] v) {
    Validate.notNull(v);
    final int n = v.length;
    for (int i = 0; i < n; i++) {
        v[i] = Math.abs(v[i]);//from w  w w.  j av  a  2 s. co  m
    }
}

From source file:com.opengamma.analytics.math.utilities.Diff.java

/**
 * Finds the t^{th} numerical difference between value at position (i+1) and (i)
 * (effectively recurses {@link Diff.values} "t" times);
 * @param v the vector/*w w  w  .  j  a  v a 2  s .  c o  m*/
 * @param t the number of differences to be taken (t positive).
 * @return the numerical difference between adjacent elements in v
 */
public static double[] values(final double[] v, final int t) {
    Validate.notNull(v);
    Validate.isTrue((t > -1),
            "Invalid number of differences requested, t must be positive or 0. The given t was: " + t);
    Validate.isTrue((t < v.length),
            "Invalid number of differences requested, 't' is greater than the number of elements in 'v'. The given 't' was: "
                    + t + " and 'v' contains " + v.length + " elements.");
    double[] tmp;
    if (t == 0) { // no differencing done
        tmp = new double[v.length];
        System.arraycopy(v, 0, tmp, 0, v.length);
    } else {
        tmp = values(v);
        for (int i = 0; i < t - 1; i++) {
            tmp = values(tmp);
        }
    }
    return tmp;
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Unique.java

/**
 * Uniques the data, duplicates are removed based on bitwise comparison of data.
 * @param data long[] the data to unique
 * @return the long[] uniqued data/*  w ww.  j  a va  2  s.  co m*/
 */
public static long[] bitwise(long[] data) {
    Validate.notNull(data);
    int n = data.length;
    long[] sorteddata = Sort.stateless(data);
    int j = 0;
    for (int i = 1; i < n; i++) {
        if (sorteddata[i] != sorteddata[j]) {
            j++;
            sorteddata[j] = sorteddata[i];
        }
    }
    return Arrays.copyOf(sorteddata, j + 1);
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Max.java

/**
 * Returns the maximum value in data/*from   w w w  . j  a  v  a 2s.  co m*/
 * @param data the data to search
 * @return max, the maximum
 */

public static long value(long... data) {
    Validate.notNull(data);
    long max = 0x80000000;
    final long n = data.length;
    for (int i = 0; i < n; i++) {
        if (data[i] > max) {
            max = data[i];
        }
    }
    return max;
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Min.java

/**
 * Returns the minimum value in data/*from  www.j av a  2s .co  m*/
 * @param data the data to search
 * @return min, the minimum
 */

public static long value(long... data) {
    Validate.notNull(data);
    long min = 0x7fffffff;
    final long n = data.length;
    for (int i = 0; i < n; i++) {
        if (data[i] < min) {
            min = data[i];
        }
    }
    return min;
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.View.java

/**
 * Looks up the values in v at positions given by index and returns them!
 * @param v the vector/*from  ww w. j a v a  2s  . c  o m*/
 * @param low the lowest element of the range
 * @param high the highest element of the range
 * @return tmp the values looked up by range. i.e. values[low:high];
 */
public static double[] byRange(double[] v, int low, int high) {
    Validate.notNull(v);
    final int n = v.length;
    Validate.isTrue(high < n,
            "Input \"high\" index out of range. " + high + " whereas vector to dereference is length " + n);
    Validate.isTrue(low > -1, "Negative index dereference requested on vector");
    Validate.isTrue(high >= low, "high value is lower than low value, negative range not supported.");
    double[] tmp = new double[high - low + 1]; // fence post
    int ptr = 0;
    for (int i = low; i <= high; i++) {
        tmp[ptr] = v[i];
        ptr++;
    }
    return tmp;
}

From source file:com.opengamma.analytics.math.rootfinding.RealSingleRootFinder.java

@Override
public Double getRoot(final Function1D<Double, Double> function, final Double... startingPoints) {
    Validate.notNull(startingPoints);
    Validate.isTrue(startingPoints.length == 2);
    return getRoot(function, startingPoints[0], startingPoints[1]);
}

From source file:com.opengamma.analytics.financial.interestrate.swap.VanillaSwapPresentValueCalculator.java

public double getPresentValue(final double[] fixedPaymentTimes, final double[] fixedPayment,
        final double floatPaymentTime, final double floatPayment, final YieldAndDiscountCurve fundingCurve) {
    Validate.notNull(fixedPaymentTimes);
    Validate.notNull(fixedPayment);// w w  w . j av  a  2s.  c  o m
    Validate.notNull(fundingCurve);
    if (fixedPaymentTimes.length != fixedPayment.length) {
        throw new IllegalArgumentException("Must have the same number of fixed payment times as payments");
    }
    double presentValue = 0;
    final int n = fixedPaymentTimes.length;
    for (int i = 0; i < n; i++) {
        presentValue += fixedPayment[i] * fundingCurve.getDiscountFactor(fixedPaymentTimes[i]);
    }
    presentValue += floatPayment * fundingCurve.getDiscountFactor(floatPaymentTime);
    return presentValue;
}

From source file:com.vmware.identity.idm.IdmDataRemover.java

public static void removeData(CasIdmClient idmClient) throws Exception {
    logger.debug("IdmDataCreator.removeData called");

    Validate.notNull(idmClient);

    // remove all our tenants
    for (String tenant : tenantsToManage) {
        try {/*w ww. j  a  v a2 s.  c o  m*/
            Tenant existingTenant = idmClient.getTenant(tenant);
            if (existingTenant != null) {
                idmClient.deleteTenant(tenant);
            }
        } catch (NoSuchTenantException ex) {
            // continue
        }
    }

    tenantsToManage.clear();
}