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.applications.LocalVolDensity.java

/**
 * Get the coefficients (a, b and c) for the PDE governing the evolution of the transition density for a single underlying (i.e. 1 spatial dimension). The PDE is of the form
 * $frac{\partial V}{\partial t} + a(x,t)\frac{\partial^2V}{\partial x^2}+b(x,t)\frac{\partial V}{\partial x} +c(x,t)V=0$ where $V(x,t)$ is the density
 * @param forward the forward curve//  www .  jav  a  2s .co m
 * @param localVol the local volatility surface (parameterised by strike)
 * @return The coefficients a, b & c - which are all functions of time and asset value (space)
 */
public static ConvectionDiffusionPDE1DCoefficients getStandardCoefficients(final ForwardCurve forward,
        final LocalVolatilitySurfaceStrike localVol) {

    final Function<Double, Double> a = new Function<Double, Double>() {
        @Override
        public Double evaluate(final Double... ts) {
            Validate.isTrue(ts.length == 2);
            final double t = ts[0];
            final double s = ts[1];
            final double sigma = localVol.getVolatility(t, s) * s;
            return -0.5 * sigma * sigma;
        }
    };

    final Function<Double, Double> b = new Function<Double, Double>() {
        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final Double... ts) {
            Validate.isTrue(ts.length == 2);
            final double t = ts[0];
            final double s = ts[1];
            final double lvDiv = getLocalVolFirstDiv(localVol, t, s);
            final double lv = localVol.getVolatility(t, s);
            return s * (forward.getDrift(t) - 2 * lv * (s * lvDiv + lv));
        }
    };

    final Function<Double, Double> c = new Function<Double, Double>() {
        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final Double... ts) {
            Validate.isTrue(ts.length == 2);
            final double t = ts[0];
            final double s = ts[1];
            final double lv1Div = getLocalVolFirstDiv(localVol, t, s);
            final double lv2Div = getLocalVolSecondDiv(localVol, t, s);
            final double lv = localVol.getVolatility(t, s);
            final double temp1 = (lv + s * lv1Div);
            final double temp2 = lv * s * (s * lv2Div + 2 * lv1Div);

            return forward.getDrift(t) - temp1 * temp1 - temp2;
        }
    };

    //    //using a log-normal distribution with a very small Standard deviation as a proxy for a Dirac delta
    //    final Function1D<Double, Double> initialCondition = new Function1D<Double, Double>() {
    //      private final double _volRootTOffset = 0.01;
    //
    //      @Override
    //      public Double evaluate(final Double s) {
    //        if (s == 0) {
    //          return 0.0;
    //        }
    //        final double x = Math.log(s / forward.getSpot());
    //        final NormalDistribution dist = new NormalDistribution(0, _volRootTOffset);
    //        return dist.getPDF(x) / s;
    //      }
    //    };

    return new ConvectionDiffusionPDE1DStandardCoefficients(FunctionalDoublesSurface.from(a),
            FunctionalDoublesSurface.from(b), FunctionalDoublesSurface.from(c));
}

From source file:fr.ritaly.dungeonmaster.item.Food.java

/**
 * Creates a new food item with the given type.
 *
 * @param type/*  w ww  .  j a va2s .c o m*/
 *            the type of food to create. Can't be null.
 */
Food(Type type) {
    super(type);

    Validate.isTrue(Item.Type.getFoodTypes().contains(type));
}

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

@Override
public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DPiecewisePoynomialDataBundle);
    final Interpolator1DPiecewisePoynomialDataBundle polyData = (Interpolator1DPiecewisePoynomialDataBundle) data;
    final DoubleMatrix1D res = FUNC.evaluate(polyData.getPiecewisePolynomialResultsWithSensitivity(), value);
    return res.getEntry(0);
}

From source file:ar.com.zauber.commons.social.twitter.impl.streaming.filter.BoundingBoxImpl.java

/** Creates the BoundingBoxImpl. */
private BoundingBoxImpl(final double swLong, final double swLat, final double neLong, final double neLat) {
    Validate.isTrue(swLat >= -360 && swLat <= 360);
    Validate.isTrue(swLong >= -360 && swLong <= 360);
    Validate.isTrue(neLat >= -360 && neLat <= 360);
    Validate.isTrue(neLong >= -360 && neLong <= 360);
    this.swLat = swLat;
    this.swLong = swLong;
    this.neLat = neLat;
    this.neLong = neLong;
}

From source file:ar.com.zauber.commons.web.version.impl.ManifestVersionProvider.java

/**
 * Creates the ManifestVersionProvider./*from w ww.  ja va2s  . c o  m*/
 *
 * @param manifest manifest en cuestion
 * @param attrName nombre del atributo a devolver
 */
public ManifestVersionProvider(final Manifest manifest, final String attrName) {
    Validate.notNull(manifest);
    Validate.isTrue(!StringUtils.isEmpty(attrName));

    final String v = manifest.getMainAttributes().getValue(attrName);
    this.version = v == null ? "" : v;
}

From source file:com.opengamma.analytics.math.integration.GaussLegendreWeightAndAbscissaFunction.java

/**
 * {@inheritDoc}//from w  w  w  . ja v a 2s  .  c  o  m
 */
@Override
public GaussianQuadratureData generate(final int n) {
    Validate.isTrue(n > 0);
    final int mid = (n + 1) / 2;
    final double[] x = new double[n];
    final double[] w = new double[n];
    final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = LEGENDRE.getPolynomialsAndFirstDerivative(n);
    final Pair<DoubleFunction1D, DoubleFunction1D> pair = polynomials[n];
    final DoubleFunction1D function = pair.getFirst();
    final DoubleFunction1D derivative = pair.getSecond();
    for (int i = 0; i < mid; i++) {
        final double root = ROOT_FINDER.getRoot(function, derivative, getInitialRootGuess(i, n));
        x[i] = -root;
        x[n - i - 1] = root;
        final double dp = derivative.evaluate(root);
        w[i] = 2 / ((1 - root * root) * dp * dp);
        w[n - i - 1] = w[i];
    }
    return new GaussianQuadratureData(x, w);
}

From source file:com.useekm.indexing.algebra.indexer.IdxConstraintQuery.java

/**
 * @param constraintPattern The joined statement pattern. At least one of the variables should be equal to another {@link IdxQuery} in the same {@link IdxJoin}.
 *///from  www .  ja v  a 2  s  .  co  m
public IdxConstraintQuery(StatementPattern constraintPattern) {
    super(constraintPattern.getSubjectVar(), constraintPattern.getPredicateVar(),
            constraintPattern.getObjectVar());
    Validate.isTrue(constraintPattern.getPredicateVar().getValue() instanceof URI);
    Validate.notEmpty(getSubjectVar().getName());
}

From source file:com.opengamma.analytics.financial.schedule.AnnualScheduleOnDayAndMonthCalculator.java

public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        if (MonthDay.from(startDate).equals(_monthDay)) {
            return new LocalDate[] { startDate };
        }//  w w  w .j a  v a  2  s  .  c o  m
        throw new IllegalArgumentException(
                "Start date and end date were the same but the day of month and month of year were not those required");
    }
    LocalDate date = startDate.with(_monthDay);
    if (date.isBefore(startDate)) {
        date = date.plusYears(1);
    }
    final List<LocalDate> dates = new ArrayList<>();
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.plusYears(1);
    }
    return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
}

From source file:com.vmware.identity.saml.config.TokenRestrictions.java

/**
 * @param maximumBearerTokenLifetime/*from   w  w w  . ja v a  2  s.  c om*/
 *           in milliseconds. Positive number.
 * @param maximumHoKTokenLifetime
 *           in milliseconds Positive number.
 */
public TokenRestrictions(long maximumBearerTokenLifetime, long maximumHoKTokenLifetime, int delegationCount,
        int renewCount) {
    Validate.isTrue(maximumBearerTokenLifetime > 0);
    Validate.isTrue(maximumHoKTokenLifetime > 0);
    Validate.isTrue(delegationCount >= 0);
    Validate.isTrue(renewCount >= 0);

    this.maximumBearerTokenLifetime = maximumBearerTokenLifetime;
    this.maximumHoKTokenLifetime = maximumHoKTokenLifetime;
    this.delegationCount = delegationCount;
    this.renewCount = renewCount;
}

From source file:com.opengamma.analytics.financial.pnl.SensitivityAndReturnDataBundle.java

public SensitivityAndReturnDataBundle(final Sensitivity<?> sensitivity, final double value,
        final Map<UnderlyingType, DoubleTimeSeries<?>> underlyingReturnTS) {
    Validate.notNull(sensitivity, "sensitivity");
    Validate.notNull(underlyingReturnTS, "underlying returns");
    Validate.notEmpty(underlyingReturnTS, "underlying returns");
    Validate.noNullElements(underlyingReturnTS.keySet(), "underlying return key set");
    Validate.noNullElements(underlyingReturnTS.values(), "underlying return values");
    _underlyings = sensitivity.getUnderlyingTypes();
    Validate.isTrue(_underlyings.size() == underlyingReturnTS.size());
    Validate.isTrue(_underlyings.containsAll(underlyingReturnTS.keySet()));
    _sensitivity = sensitivity;//from  ww w .  j av a2  s .  co  m
    _value = value;
    _underlyingReturnTS = underlyingReturnTS;
}