List of usage examples for org.apache.commons.lang Validate isTrue
public static void isTrue(boolean expression, String message)
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.
From source file:fr.ritaly.dungeonmaster.projectile.SpellProjectile.java
public SpellProjectile(Spell spell, Champion champion) { // TODO Compute the projectile range super(champion.getParty().getDungeon(), champion.getParty().getPosition(), champion.getParty().getDirection(), champion.getSector(), spell.getDuration()); Validate.isTrue(spell.isValid(), "The given spell <" + spell.getName() + "> isn't valid"); Validate.isTrue(spell.getType().isProjectile(), "The given spell <" + spell.getName() + "> isn't a projectile spell"); this.spell = spell; }
From source file:com.opengamma.analytics.math.statistics.distribution.ChiSquareDistribution.java
/** * @param degrees The degrees of freedom of the distribution, not less than one * @param engine A uniform random number generator, not null *//*from w w w . j a va2 s . c o m*/ public ChiSquareDistribution(final double degrees, final RandomEngine engine) { Validate.isTrue(degrees >= 1, "Degrees of freedom must be greater than or equal to one"); Validate.notNull(engine); _chiSquare = new ChiSquare(degrees, engine); _degrees = degrees; }
From source file:com.opengamma.analytics.math.statistics.distribution.NormalDistribution.java
/** * @param mean The mean of the distribution * @param standardDeviation The standard deviation of the distribution, not negative or zero * @param randomEngine A generator of uniform random numbers, not null *//*from w w w . j ava2s .co m*/ public NormalDistribution(final double mean, final double standardDeviation, final RandomEngine randomEngine) { Validate.isTrue(standardDeviation > 0, "standard deviation"); Validate.notNull(randomEngine); _mean = mean; _standardDeviation = standardDeviation; _normal = new Normal(mean, standardDeviation, randomEngine); }
From source file:com.hmsinc.epicenter.classifier.lm.ConditionalClassifier.java
public List<String> classify(String text) { Validate.notNull(classifier, "Classifier has not been initialized!"); final List<String> result = new ArrayList<String>(); if (text != null) { final CharSequence filtered = ClassifierUtils.filter(text, stopwords); if (filtered != null) { final Classification jc = classifier.classify(filtered); if (jc != null) { Validate.isTrue(ScoredClassification.class.isAssignableFrom(jc.getClass()), "Underlying classifier does not support ScoredClassifications"); final ScoredClassification jcs = (ScoredClassification) jc; // FIXME: This probably isn't right. if (jcs.size() > 0 && jcs.score(0) >= DEFAULT_THRESHOLD) { final String category = jcs.bestCategory(); if (!ignoredCategories.contains(category)) { result.add(category); }/* www. ja va 2 s.com*/ logger.debug("Result for \"{}\": {} (probability={})", new Object[] { text, category, jcs.score(0) }); } } } } return result; }
From source file:com.hmsinc.epicenter.classifier.lm.RankedClassifier.java
public List<String> classify(String text) { Validate.notNull(classifier, "Classifier has not been initialized!"); final List<String> result = new ArrayList<String>(); if (text != null) { final CharSequence filtered = ClassifierUtils.filter(text, stopwords); if (filtered != null) { final Classification c = classifier.classify(filtered); if (c != null) { Validate.isTrue(JointClassification.class.isAssignableFrom(c.getClass()), "Underlying classifier does not support JointClassification"); final JointClassification classification = (JointClassification) c; for (int i = 0; i < DEFAULT_NUM_RANKS; i++) { final String category = classification.category(i); logger.debug("Result for \"{}\": {} (score={}, rank={})", new Object[] { text, category, classification.score(i), i }); if (DEFAULT_STOP_ON_OTHER && category.equalsIgnoreCase("other")) { break; }// www. j ava 2 s. c om if (!ignoredCategories.contains(category)) { result.add(category); } } } } } return result; }
From source file:net.joshdevins.rabbitmq.client.ha.retry.SimpleRetryStrategy.java
public void setOperationRetryTimeoutMillis(final long timeout) { Validate.isTrue(timeout >= 0, "timeout must be a positive number"); operationRetryTimeoutMillis = timeout; }
From source file:com.opengamma.analytics.financial.interestrate.inflation.method.CouponInflationZeroCouponMonthlyGearingDiscountingMethod.java
@Override public CurrencyAmount presentValue(InstrumentDerivative instrument, MarketBundle market) { Validate.isTrue(instrument instanceof CouponInflationZeroCouponMonthlyGearing, "Zero-coupon inflation with start of month reference date."); return presentValue((CouponInflationZeroCouponMonthlyGearing) instrument, market); }
From source file:fr.ritaly.dungeonmaster.map.WallLock.java
public WallLock(Direction direction, Item.Type keyType) { super(Type.WALL_LOCK, direction); Validate.notNull(keyType, "The given key type is null"); Validate.isTrue(keyType.isKey(), "The given item type <" + keyType + "> isn't a key"); this.keyType = keyType; }
From source file:com.opengamma.analytics.math.interpolation.LogLinearWithSeasonalitiesInterpolator1D.java
/** * Construct a LogLinearWithSeasonalitiesInterpolator1D from seasonal values. * @param monthlyFactors The seasonal values * *///from w ww . j ava2s. c o m public LogLinearWithSeasonalitiesInterpolator1D(final double[] monthlyFactors) { Validate.notNull(monthlyFactors, "Monthly factors"); Validate.isTrue(monthlyFactors.length == 11, "Monthly factors with incorrect length; should be 11"); double sum = 0.0; final double[] seasonalValues = new double[NB_MONTH]; for (int loopmonth = 0; loopmonth < NB_MONTH - 1; loopmonth++) { seasonalValues[loopmonth] = monthlyFactors[loopmonth]; sum = sum + monthlyFactors[loopmonth]; } seasonalValues[NB_MONTH - 1] = 1.0 - sum; _seasonalValues = seasonalValues; }
From source file:com.opengamma.analytics.financial.interestrate.bond.definition.BillTransaction.java
/** * Constructor.// www .j a v a2 s . c om * @param billPurchased The bill underlying the transaction. * @param quantity The bill quantity. * @param settlementAmount The amount paid at settlement date for the bill transaction. The amount is negative for a purchase (_quantity>0) and positive for a sell (_quantity<0). * @param billStandard The bill with standard settlement date (time). */ public BillTransaction(final BillSecurity billPurchased, final double quantity, final double settlementAmount, final BillSecurity billStandard) { Validate.notNull(billPurchased, "Bill purchased"); Validate.notNull(billStandard, "Bill standard"); Validate.isTrue(quantity * settlementAmount <= 0, "Quantity and settlement amount should have opposite signs"); _billPurchased = billPurchased; _quantity = quantity; _settlementAmount = settlementAmount; _billStandard = billStandard; }