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.instrument.annuity.AnnuityCapFloorCMSDefinition.java

/**
 * CMS cap/floor (or leg of CMS caplet/floorlet) constructor from standard description. The cap/floor are fixing in advance and payment in arrears. 
 * The CMS fixing is done at a standard lag before the coupon start. The date are computed from the settlement date (stub last) with a short stub is necessary.
 * @param settlementDate The settlement date.
 * @param maturityDate The annuity maturity date.
 * @param notional The notional.//w  ww.ja  v a 2 s  .  com
 * @param index The CMS index.
 * @param paymentPeriod The payment period of the coupons.
 * @param dayCount The day count of the coupons.
 * @param isPayer Payer (true) / receiver (false) fleg.
 * @param strike The common strike.
 * @param isCap The cap (true) / floor (false) flag.
 * @return The CMS coupon leg.
 */
public static AnnuityCapFloorCMSDefinition from(final ZonedDateTime settlementDate,
        final ZonedDateTime maturityDate, final double notional, final IndexSwap index,
        final Period paymentPeriod, final DayCount dayCount, final boolean isPayer, final double strike,
        final boolean isCap) {
    Validate.notNull(settlementDate, "settlement date");
    Validate.notNull(maturityDate, "maturity date");
    Validate.notNull(index, "index");
    Validate.isTrue(notional > 0, "notional <= 0");
    Validate.notNull(paymentPeriod, "Payment period");
    final ZonedDateTime[] paymentDatesUnadjusted = ScheduleCalculator.getUnadjustedDateSchedule(settlementDate,
            maturityDate, paymentPeriod, true, false);
    final ZonedDateTime[] paymentDates = ScheduleCalculator.getAdjustedDateSchedule(paymentDatesUnadjusted,
            index.getIborIndex().getBusinessDayConvention(), index.getIborIndex().getCalendar(), false);
    final double sign = isPayer ? -1.0 : 1.0;
    final CapFloorCMSDefinition[] coupons = new CapFloorCMSDefinition[paymentDates.length];
    coupons[0] = CapFloorCMSDefinition.from(paymentDates[0], settlementDate, paymentDates[0],
            dayCount.getDayCountFraction(settlementDate, paymentDates[0]), sign * notional, index, strike,
            isCap);
    for (int loopcpn = 1; loopcpn < paymentDates.length; loopcpn++) {
        coupons[loopcpn] = CapFloorCMSDefinition.from(paymentDates[loopcpn], paymentDates[loopcpn - 1],
                paymentDates[loopcpn],
                dayCount.getDayCountFraction(paymentDates[loopcpn - 1], paymentDates[loopcpn]), sign * notional,
                index, strike, isCap);
    }
    return new AnnuityCapFloorCMSDefinition(coupons);
}

From source file:hr.fer.spocc.grammar.cfg.CfgProductionRule.java

public CfgProductionRule(Variable<T> leftSideSymbol, Symbol<T>... rightSideSymbols) {
    super(leftSideSymbol, rightSideSymbols);
    Validate.isTrue(getLeftSide().size() == 1, "Left side must have exactly one symbol");
    Validate.isTrue(getLeftSideSymbol().getSymbolType() == SymbolType.VARIABLE, "Left side must be a variable");
}

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

/**
 * creates a non-uniform set of points according by joining two ExponentialMeshing
 * @param lowerBound The value of x_0/*from  ww  w  . ja  va  2 s .  c  om*/
 * @param upperBound The value of x_N
 * @param centre the value where we switch from the lower to upper ExponentialMeshing
 * @param nPoints Number of Points
 * @param lambdaLower Bunching parameter. lambda = 0 is uniform, lambda > 0 gives a high density of points near X_0 and lambda < 0 gives a high density
 * of points near centre
 *  @param lambdaUpper Bunching parameter. lambda = 0 is uniform, lambda > 0 gives a high density of points near centre and lambda < 0 gives a high density
 * of points near x_N
 */
public DoubleExponentialMeshing(final double lowerBound, final double upperBound, final double centre,
        final int nPoints, final double lambdaLower, final double lambdaUpper) {
    super(nPoints);
    Validate.isTrue(centre > lowerBound, "need centre > lowerBound");
    Validate.isTrue(centre < upperBound, "need centre < upperBound");
    final double frac = (centre - lowerBound) / (upperBound - lowerBound);
    final int nPointsLower = (int) (frac * nPoints);
    final int nPointUpper = nPoints - nPointsLower + 1;
    _nPointsLower = nPointsLower;
    _lowerMesh = new ExponentialMeshing(lowerBound, centre, nPointsLower, lambdaLower);
    _upperMesh = new ExponentialMeshing(centre, upperBound, nPointUpper, lambdaUpper);
}

From source file:com.opengamma.analytics.math.interpolation.RadialBasisFunction.java

protected void validateInput(final List<Pair<double[], Double>> weights, final double[] x) {
    Validate.notNull(x, "null position");
    Validate.notNull(weights, "null data");

    final int dim = x.length;
    Validate.isTrue(dim > 0, "0 dimension");
    Validate.isTrue(weights.get(0).getFirst().length == dim, "data and requested point different dimension");
}

From source file:com.opengamma.analytics.financial.interestrate.BlackSwaptionSensitivityNodeCalculator.java

/**
 * Calculate the node sensitivities from existing sensitivities and a set of parameters with node points.
 * @param sensitivities The sensitivities. 
 * @param parameters The Black volatility parameters.
 * @return The node sensitivities.//from  w ww  .j av a 2  s  .c  o m
 */
public PresentValueBlackSwaptionSensitivity calculateNodeSensitivities(
        final PresentValueBlackSwaptionSensitivity sensitivities,
        final BlackFlatSwaptionParameters parameters) {
    Validate.isTrue(parameters.getGeneratorSwap().equals(sensitivities.getGeneratorSwap()),
            "Sensitivities and parameters should refer to the same swap generator");
    ArgumentChecker.isTrue(parameters.getVolatilitySurface() instanceof InterpolatedDoublesSurface,
            "Can only calculate node sensitivities for interpolated double surfaces");
    final InterpolatedDoublesSurface interpolatedSurface = (InterpolatedDoublesSurface) parameters
            .getVolatilitySurface();
    final Map<Double, Interpolator1DDataBundle> volatilityData = (Map<Double, Interpolator1DDataBundle>) interpolatedSurface
            .getInterpolatorData();
    SurfaceValue volatilityNode = new SurfaceValue();
    for (final Entry<DoublesPair, Double> entry : sensitivities.getSensitivity().getMap().entrySet()) {
        final Map<DoublesPair, Double> weight = interpolatedSurface.getInterpolator()
                .getNodeSensitivitiesForValue(volatilityData, entry.getKey());
        volatilityNode = SurfaceValue.plus(volatilityNode,
                SurfaceValue.multiplyBy(SurfaceValue.from(weight), entry.getValue()));
    }
    return new PresentValueBlackSwaptionSensitivity(volatilityNode, parameters.getGeneratorSwap());
}

From source file:fr.ritaly.dungeonmaster.projectile.SpellProjectileFactory.java

public SpellProjectileFactory(Spell spell) {
    Validate.notNull(spell, "The given spell is null");
    Validate.isTrue(spell.getType().isProjectile(),
            String.format("The given spell %s isn't a projectile spell", spell.getName()));

    this.spell = spell;
}

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

/**
 * @param data The data/*from   w  w w .j  a  v a  2s  .c o  m*/
 * @param beta The beta
 */
public KrigingInterpolatorDataBundle(final List<Pair<double[], Double>> data, final double beta) {
    super(data);
    Validate.isTrue(beta >= 1 && beta < 2, "Beta was not in acceptable range (1 <= beta < 2");
    _variogram = calculateVariogram(data, beta);
    _weights = calculateWeights(data, _variogram);
}

From source file:de.matzefratze123.heavyspleef.core.event.EventListenerMethod.java

@SuppressWarnings("unchecked")
public EventListenerMethod(Object instance, Method method) {
    this.instance = instance;
    this.method = method;

    if (!method.isAccessible()) {
        method.setAccessible(true);//from   www.  ja v a 2 s.  c  o  m
    }

    Class<?>[] parameters = method.getParameterTypes();
    Validate.isTrue(parameters.length == 1,
            "method must have only one parameter which must be a subtype of GameEvent");

    Class<?> eventClass = parameters[0];
    Validate.isTrue(GameEvent.class.isAssignableFrom(eventClass),
            "First parameter of method must be a subtype of GameEvent");

    this.eventClass = (Class<? extends GameEvent>) eventClass;
}

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

/**
 * @param x The argument of the function, not null. Must have $x_1 < x < x_2$
 * @return The value of the function/*from w  w w. j  av  a 2 s  . c o m*/
 */
@Override
public Double evaluate(final Double x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x != _x1, "Function is undefined for x = x1");
    Validate.isTrue(x != _x2, "Function is undefined for x = x2");
    if (x > _x1 && x < _x2) {
        return _y;
    }
    return 0.;
}

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

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