List of usage examples for org.apache.commons.lang Validate isTrue
public static void isTrue(boolean expression)
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'.
From source file:com.opengamma.analytics.math.interpolation.PCHIPInterpolator1D.java
@Override public double firstDerivative(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.differentiate(polyData.getPiecewisePolynomialResultsWithSensitivity(), value);/*from w w w . j ava2s .c om*/ return res.getEntry(0); }
From source file:com.opengamma.analytics.math.function.special.LaguerrePolynomialFunction.java
public Pair<DoubleFunction1D, DoubleFunction1D>[] getPolynomialsAndFirstDerivative(final int n, final double alpha) { Validate.isTrue(n >= 0); @SuppressWarnings("unchecked") final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = new Pair[n + 1]; DoubleFunction1D p, dp, p1, p2; for (int i = 0; i <= n; i++) { if (i == 0) { polynomials[i] = Pair.of(getOne(), getZero()); } else if (i == 1) { polynomials[i] = Pair.of(F1, DF1); } else {/*from w w w . j a v a 2s .c om*/ p1 = polynomials[i - 1].getFirst(); p2 = polynomials[i - 2].getFirst(); p = (p1.multiply(2. * i + alpha - 1).subtract(p1.multiply(getX())) .subtract(p2.multiply((i - 1. + alpha))).divide(i)); dp = (p.multiply(i).subtract(p1.multiply(i + alpha))).divide(getX()); polynomials[i] = Pair.of(p, dp); } } return polynomials; }
From source file:com.opengamma.analytics.financial.simpleinstruments.definition.SimpleFutureDefinition.java
@Override public SimpleFuture toDerivative(final ZonedDateTime date) { Validate.notNull(date, "date"); Validate.isTrue(date.isBefore(_expiryDate)); double timeToFixing = TimeCalculator.getTimeBetween(date, _expiryDate); double timeToDelivery = TimeCalculator.getTimeBetween(date, _settlementDate); return new SimpleFuture(timeToFixing, timeToDelivery, _referencePrice, _unitAmount, _currency); }
From source file:ar.com.zauber.commons.gis.spots.model.GeonameSpot.java
/** * @param location the location of the spot * @param name the spot name//from www . j a v a 2s .c o m * @param ansiName the ansi name * @param countryCode country code * @param population population */ public GeonameSpot(final Point location, final String name, final String ansiName, final String countryCode, final long population) { Validate.notNull(location, "location"); Validate.notNull(name); Validate.notNull(ansiName); Validate.notEmpty(countryCode); Validate.isTrue(population >= 0); this.location = location; this.name = name; this.ansiName = ansiName; this.countryCode = countryCode; this.population = population; }
From source file:com.netflix.simianarmy.aws.janitor.rule.elb.OrphanedELBRule.java
/** * Constructor for OrphanedELBRule.//from w ww.j a v a2 s .c om * * @param calendar * The calendar used to calculate the termination time * @param retentionDays * The number of days that the marked ASG is retained before being terminated */ public OrphanedELBRule(MonkeyCalendar calendar, int retentionDays) { Validate.notNull(calendar); Validate.isTrue(retentionDays >= 0); this.calendar = calendar; this.retentionDays = retentionDays; }
From source file:com.healthcit.cacure.dao.QuestionTableDao.java
@Transactional(propagation = Propagation.REQUIRED) public void reorderQuestions(Long sourceQuestionId, Long targetQuestionId, boolean before) { Validate.notNull(sourceQuestionId);/* ww w. ja va 2s .co m*/ Validate.notNull(targetQuestionId); if (sourceQuestionId.equals(targetQuestionId)) { return; } Query query = em.createQuery("SELECT ord, form.id FROM TableQuestion WHERE id = :id"); Object[] result = (Object[]) query.setParameter("id", sourceQuestionId).getSingleResult(); int sOrd = (Integer) result[0]; long sFormId = (Long) result[1]; result = (Object[]) query.setParameter("id", targetQuestionId).getSingleResult(); int tOrd = (Integer) result[0]; long tFormId = (Long) result[1]; Validate.isTrue(sFormId == tFormId); //reorder only inside one form if (sOrd == tOrd || (before && sOrd == tOrd - 1) || (!before && sOrd == tOrd + 1)) { return; } else if (sOrd < tOrd) { em.createQuery("UPDATE TableQuestion SET ord = ord - 1 WHERE ord > :sOrd and ord " + (before ? "<" : "<=") + " :tOrd and form.id = :formId").setParameter("sOrd", sOrd) .setParameter("tOrd", tOrd).setParameter("formId", sFormId).executeUpdate(); em.createQuery("UPDATE TableQuestion SET ord = :tOrd WHERE id = :qId") .setParameter("qId", sourceQuestionId).setParameter("tOrd", before ? tOrd - 1 : tOrd) .executeUpdate(); } else if (sOrd > tOrd) { em.createQuery("UPDATE TableQuestion SET ord = ord + 1 WHERE ord < :sOrd and ord " + (before ? ">=" : ">") + " :tOrd and form.id = :formId").setParameter("sOrd", sOrd) .setParameter("tOrd", tOrd).setParameter("formId", sFormId).executeUpdate(); em.createQuery("UPDATE TableQuestion SET ord = :tOrd WHERE id = :qId") .setParameter("qId", sourceQuestionId).setParameter("tOrd", before ? tOrd : tOrd + 1) .executeUpdate(); } }
From source file:com.netflix.simianarmy.aws.janitor.rule.instance.NoOwnerInstanceRule.java
/** * Constructor for NoOwnerInstanceRule./*from ww w .j av a 2 s. c o m*/ * * @param calendar * The calendar used to calculate the termination time * @param retentionDays * The number of days that the instance is retained before being terminated */ public NoOwnerInstanceRule(MonkeyCalendar calendar, int retentionDays) { Validate.notNull(calendar); Validate.isTrue(retentionDays >= 0); this.calendar = calendar; this.retentionDays = retentionDays; }
From source file:com.opengamma.analytics.math.interpolation.LogNaturalCubicMonotonicityPreservingInterpolator1D.java
@Override public Double interpolate(final Interpolator1DDataBundle data, final Double value) { Validate.notNull(value, "value"); Validate.notNull(data, "data bundle"); Validate.isTrue(data instanceof Interpolator1DLogPiecewisePoynomialDataBundle); final Interpolator1DLogPiecewisePoynomialDataBundle polyData = (Interpolator1DLogPiecewisePoynomialDataBundle) data; final DoubleMatrix1D res = FUNC.evaluate(polyData.getPiecewisePolynomialResultsWithSensitivity(), value); return Math.exp(res.getEntry(0)); }
From source file:net.iglyduck.utils.sqlbuilder.TempTable.java
protected TempTable from(Object item) { Validate.notNull(item);/*from w ww .j a va 2 s .com*/ Validate.isTrue(item instanceof WrapTable || item instanceof JoinUnit); if (froms == null) { froms = new ArrayList<Object>(); } if (item instanceof WrapTable) { Validate.allElementsOfType(froms, WrapTable.class); } else if (item instanceof JoinUnit) { Validate.isTrue(froms.isEmpty()); } froms.add(item); return this; }
From source file:ar.com.zauber.common.image.impl.FileImageFactory.java
/** * Creates the FileFlyerFactory.//ww w . j a v a 2 s .c o m * * @param baseDir the basedir * @param maxBytes cantidad maxima de bytes a bajar. si es 0 * no hay limite, si es se pasa el maximo * se tira una excepcion */ public FileImageFactory(final File baseDir, final long maxBytes, final int maxSize) { Validate.notNull(baseDir, "baseDir"); Validate.isTrue(maxBytes >= 0); if (!baseDir.exists()) { FileUtils.mkdir(baseDir.getAbsolutePath()); } if (!baseDir.exists()) { throw new IllegalArgumentException("`" + baseDir + "' doesn't exists"); } this.baseDir = baseDir; this.maxBytes = maxBytes; this.maxSize = maxSize; }