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:com.opengamma.analytics.financial.instrument.annuity.AnnuityCouponIborRatchetDefinition.java
/** * Constructor from a list of Ibor-like coupons. * @param payments The Ibor coupons.//from ww w . j a v a 2 s. com */ public AnnuityCouponIborRatchetDefinition(final CouponDefinition[] payments) { super(payments); Validate.isTrue( (payments[0] instanceof CouponFixedDefinition) || (payments[0] instanceof CouponIborGearingDefinition), "First coupon should be CouponFixedDefinition or a CouponIborGearingDefinition"); for (int looppay = 1; looppay < payments.length; looppay++) { Validate.isTrue((payments[looppay] instanceof CouponIborRatchetDefinition), "Next coupons should be CouponIborRatchetDefinition"); } }
From source file:de.matzefratze123.heavyspleef.core.event.EventListenerMethod.java
public void invoke(GameEvent event) { Validate.isTrue(eventClass.isAssignableFrom(event.getClass()), "event must be either " + eventClass.getName() + " or a subtype"); try {// w w w .j a v a2s. c o m method.invoke(instance, event); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException(e); } }
From source file:com.opengamma.analytics.financial.model.option.parameters.BlackFlatCapFloorParameters.java
@Override /**//from w w w . j a v a 2s. c om * Return the volatility for a expiration tenor array. * @param data An array of one doubles with the expiration. * @return The volatility. */ public Double getVolatility(final double[] data) { Validate.notNull(data, "data"); Validate.isTrue(data.length == 1, "data should have one components (expiration)"); return getVolatility(data[0]); }
From source file:ar.com.zauber.commons.xmpp.message.XMPPNotificationStrategy.java
/** @see NotificationStrategy#execute(NotificationAddress[], Message) */ public final void execute(final NotificationAddress[] addresses, final Message message) { Validate.notNull(addresses);/*from www.j av a 2s. c o m*/ Validate.notNull(message); for (final NotificationAddress address : addresses) { Validate.isTrue(address instanceof XMPPNotificationAddress, INVALID_NOTIFICATION_ADDRESS); final XMPPNotificationAddress xmmpAddress = (XMPPNotificationAddress) address; final org.jivesoftware.smack.packet.Message msg; if (message instanceof XMPPMessage) { msg = ((XMPPMessage) message).getXMPPMessage(xmmpAddress.getJid()); } else { msg = new org.jivesoftware.smack.packet.Message(); msg.setBody(message.getContent()); msg.setType(Type.normal); msg.setSubject(message.getSubject()); } msg.setTo(xmmpAddress.getJid()); connection.sendPacket(msg); } }
From source file:com.opengamma.analytics.financial.model.option.definition.CashOrNothingOptionDefinition.java
/** * @param strike The strike/* w ww . j av a 2s . co m*/ * @param expiry The expiry * @param isCall Is the option a call or put * @param payment The payment amount, greater than zero */ public CashOrNothingOptionDefinition(final double strike, final Expiry expiry, final boolean isCall, final double payment) { super(strike, expiry, isCall); Validate.isTrue(payment >= 0, "payment"); _payment = payment; }
From source file:com.opengamma.analytics.financial.model.option.definition.GapOptionDefinition.java
/** * @param strike The strike/* w ww . ja v a 2 s . com*/ * @param expiry The expiry * @param isCall Is the option a call or put * @param payoffStrike The payoff strike of the option, greater than zero */ public GapOptionDefinition(final double strike, final Expiry expiry, final boolean isCall, final double payoffStrike) { super(strike, expiry, isCall); Validate.isTrue(payoffStrike >= 0, "payoff strike"); _payoffStrike = payoffStrike; }
From source file:com.opengamma.analytics.math.statistics.distribution.LaplaceDistribution.java
/** * @param mu The location parameter/* ww w.jav a2 s . co m*/ * @param b The scale parameter, greater than zero * @param engine A uniform random number generator, not null */ public LaplaceDistribution(final double mu, final double b, final RandomEngine engine) { Validate.isTrue(b > 0, "b must be > 0"); Validate.notNull(engine); _mu = mu; _b = b; _engine = engine; }
From source file:com.opengamma.analytics.financial.instrument.swap.SwapFixedONSimplifiedDefinition.java
/** * Constructor of the fixed-OIS swap from its two legs. * @param fixedLeg The fixed leg.//from www. j a v a2 s. com * @param oisLeg The OIS leg. */ public SwapFixedONSimplifiedDefinition(final AnnuityCouponFixedDefinition fixedLeg, final AnnuityCouponONSimplifiedDefinition oisLeg) { super(fixedLeg, oisLeg); Validate.isTrue(fixedLeg.getCurrency() == oisLeg.getCurrency(), "Legs should have the same currency"); }
From source file:com.opengamma.analytics.financial.interestrate.swaption.method.SwaptionPhysicalLMMDDSuccessiveRootFinderCalibrationEngine.java
@Override public void addInstrument(final InstrumentDerivative instrument, final PricingMethod method) { Validate.notNull(instrument, "Instrument"); Validate.notNull(method, "Method"); Validate.isTrue(instrument instanceof SwaptionPhysicalFixedIbor, "Calibration instruments should be swaptions"); SwaptionPhysicalFixedIbor swaption = (SwaptionPhysicalFixedIbor) instrument; getBasket().add(instrument);//from w ww .jav a 2 s .c o m getMethod().add(method); getCalibrationPrice().add(0.0); _instrumentIndex.add(Arrays.binarySearch( ((SwaptionPhysicalLMMDDCalibrationObjective) getCalibrationObjective()).getLMMParameters() .getIborTime(), swaption.getUnderlyingSwap().getSecondLeg() .getNthPayment(swaption.getUnderlyingSwap().getSecondLeg().getNumberOfPayments() - 1) .getPaymentTime())); }
From source file:com.opengamma.analytics.math.statistics.distribution.StudentTDistribution.java
/** * @param degFreedom The number of degrees of freedom, not negative or zero * @param engine A generator of uniform random numbers, not null *//* ww w . j av a 2 s . co m*/ public StudentTDistribution(final double degFreedom, final RandomEngine engine) { Validate.isTrue(degFreedom > 0, "degrees of freedom"); Validate.notNull(engine); _degFreedom = degFreedom; _dist = new StudentT(degFreedom, engine); _beta = new InverseIncompleteBetaFunction(degFreedom / 2., 0.5); }