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.financial.analytics.conversion.BondFutureTradeConverter.java

/**
 * Convert a Trade on a Bond FutureSecurity into the OG-Analytics Definition. 
 * TODO Consider extending the function arguments to allow dynamic treatment of the reference price of the future.
 * This is currently just a wrapper on the Security converter, but the Trade contains data we may wish to use for risk management. 
 * @param trade A trade containing a BondFutureSecurity
 * @return BondFutureDefinition//from  w  w  w. ja  v  a2s . c om
 */
public BondFutureDefinition convert(final Trade trade) {
    Validate.notNull(trade, "trade");
    Validate.isTrue(trade.getSecurity() instanceof BondFutureSecurity,
            "Can only handle trades with security type BondFutureSecurity");
    final BondFutureDefinition underlyingFuture = (BondFutureDefinition) ((BondFutureSecurity) trade
            .getSecurity()).accept(_securityConverter);
    return underlyingFuture;
}

From source file:ch.algotrader.adapter.fix.DefaultFixTicketIdGenerator.java

@Override
public String generateId(final Security security) {

    Validate.notNull(security, "Security is null");
    Validate.isTrue(security.getId() > 0, "Security id is not initialized");

    return Long.toString(security.getId());
}

From source file:com.opengamma.analytics.math.minimization.DoubleRangeLimitTransform.java

/**
 * @param lower Lower limit//from  ww w .  j  a v a  2  s  .  co m
 * @param upper Upper limit
 * @throws IllegalArgumentException If the upper limit is not greater than the lower limit
 */
public DoubleRangeLimitTransform(final double lower, final double upper) {
    Validate.isTrue(upper > lower, "upper limit must be greater than lower");
    _lower = lower;
    _upper = upper;
    _mid = (lower + upper) / 2;
    _scale = (upper - lower) / 2;
}

From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.MeanCorrection.java

/**
 * Returns the mean (drift) corrected characteristic exponent
 * @param t The time/*from   w  w w.j a v  a  2 s  . c o  m*/
 * @return A function to calculate the characteristic exponent
 */
@Override
public Function1D<ComplexNumber, ComplexNumber> getFunction(final double t) {

    final Function1D<ComplexNumber, ComplexNumber> func = _base.getFunction(t);
    final ComplexNumber temp = func.evaluate(MINUS_I);
    Validate.isTrue(Math.abs(temp.getImaginary()) < 1e-12, "problem with CharacteristicExponent");
    final ComplexNumber w = new ComplexNumber(0, -temp.getReal());

    return new Function1D<ComplexNumber, ComplexNumber>() {
        @Override
        public ComplexNumber evaluate(final ComplexNumber u) {
            return add(func.evaluate(u), multiply(w, u));
        }
    };
}

From source file:com.opengamma.analytics.math.interpolation.data.Interpolator1DDataBundleBuilderFunction.java

public Interpolator1DDataBundleBuilderFunction(final LinkedHashMap<String, double[]> knotPoints,
        final LinkedHashMap<String, Interpolator1D> interpolators) {
    Validate.notNull(knotPoints, "null knot points");
    Validate.notNull(interpolators, "null interpolators");
    int count = 0;
    final Set<String> names = knotPoints.keySet();
    for (final String name : names) {
        final int size = knotPoints.get(name).length;
        Validate.isTrue(size > 0, "no knot points for " + name);
        count += size;/*from   ww  w . j  a  v  a2  s  .  co m*/
    }
    _knotPoints = knotPoints;
    _interpolators = interpolators;
    _nNodes = count;
}

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

/**
 * @param x The data, not null or empty/*from   ww w. ja v  a  2 s. c  o  m*/
 * @return The percentile
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length > 0, "x cannot be empty");
    final int length = x.length;
    final double[] copy = Arrays.copyOf(x, length);
    Arrays.sort(copy);
    final double n = _percentile * (length - 1) + 1;
    if (Math.round(n) == 1) {
        return copy[0];
    }
    if (Math.round(n) == length) {
        return copy[length - 1];
    }
    final double d = n % 1;
    final int k = (int) Math.round(n - d);
    return copy[k - 1] + d * (copy[k] - copy[k - 1]);
}

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

/**
 * Sums over a selected range indices of a given vector
 * Will do SUM(v(low:high))// w  w  w.  java 2 s.  c om
 * @param v the vector over which the sum will be undertaken
 * @param low the lowest element of the range
 * @param high the highest element of the range
 * @return the sum of dereferenced specified range of vector v
 */
public static double overRange(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 = 0;
    for (int i = low; i <= high; i++) {
        tmp += v[i];
    }
    return tmp;
}

From source file:com.opengamma.analytics.financial.interestrate.payments.method.CouponCMSGenericMethod.java

@Override
public CurrencyAmount presentValue(final InstrumentDerivative instrument, final YieldCurveBundle curves) {
    Validate.isTrue(instrument instanceof CouponCMS, "CMS coupon");
    final CouponCMS coupon = (CouponCMS) instrument;
    final CapFloorCMS cap0 = CapFloorCMS.from(coupon, 0.0, true);
    return _methodCap.presentValue(cap0, curves);
}

From source file:com.opengamma.financial.analytics.conversion.InterestRateFutureTradeConverter.java

public InterestRateFutureTransactionDefinition convert(final Trade trade) {
    Validate.notNull(trade, "trade");
    Validate.isTrue(trade.getSecurity() instanceof InterestRateFutureSecurity,
            "Can only handle trades with security type InterestRateFutureSecurity");
    final InterestRateFutureSecurityDefinition securityDefinition = _securityConverter
            .visitInterestRateFutureSecurity((InterestRateFutureSecurity) trade.getSecurity());
    // REVIEW: Setting this quantity to one so that we don't double-count the number of trades when the position scaling takes place
    final int quantity = trade.getQuantity().intValue();
    ZonedDateTime tradeDate;/*from   w  ww. ja  va  2 s  .co  m*/
    if (trade.getTradeTime() != null) {
        final ZoneId zone = trade.getTradeTime().getOffset();
        tradeDate = trade.getTradeDate().atTime(trade.getTradeTime().toLocalTime()).atZone(zone);
    } else {
        tradeDate = trade.getTradeDate().atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    }
    final double tradePrice = trade.getPremium() == null ? 0 : trade.getPremium(); //TODO remove the default value and throw an exception
    return new InterestRateFutureTransactionDefinition(securityDefinition, tradeDate, tradePrice, quantity);
    //tradeDate, tradePrice, securityDefinition.getLastTradingDate(), securityDefinition.getIborIndex(),
    //securityDefinition.getNotional(), securityDefinition.getPaymentAccrualFactor(), quantity, securityDefinition.getName());
}

From source file:com.skelril.aurora.events.anticheat.RapidHitEvent.java

public void setDamage(int damage) {

    Validate.isTrue(damage >= -1, "The damage must be greater than or equal to negative one");
    this.damage = damage;
}