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.codelanx.codelanxlib.listener.ListenerManager.java
/** * Gets a listener by its string name. Returns null if the listener is * disabled or not registered./* w w w .j a v a2 s. com*/ * * @since 0.0.1 * @version 0.1.0 * * @param <S> The {@link SubListener} type * @param listener An instance of the class type to retrieve * @return The listener class, null if disabled or not registered * @throws IllegalArgumentException If the listener isn't registered */ public static <S extends SubListener<? extends Plugin>> S getListener(Class<S> listener) { Validate.isTrue(ListenerManager.isRegistered(listener), "Class is not registered with listener manager"); return (S) ListenerManager.listeners.get(listener); }
From source file:net.andylizi.laserlib.LaserManagerImpl.java
@Override public Laser createLaser(Location source, Entity target, boolean elder) throws RuntimeException { Objects.requireNonNull(source, "source cannot be null"); Objects.requireNonNull(target, "target cannot be null"); Validate.isTrue(source.getWorld().getUID().equals(target.getWorld().getUID()), "source and target must in the same world"); Location guardianPos = source.clone().add(0, -GUARDIAN_EYE_HEIGHT, 0); try {/*from www . jav a 2 s.c o m*/ DummyEntity guardian = NMSUtil.createDummyGuardian(guardianPos, elder, target.getEntityId()); NMSUtil.dummyGuardians.add(new DummyGuardianRecord(target.getEntityId(), guardian, null)); return new RealLaser(source, guardian, target); } catch (ReflectiveOperationException ex) { throw new RuntimeException(ex); } }
From source file:com.opengamma.analytics.financial.model.volatility.smile.fitting.SABRATMVolatilityCalculator.java
/** * Finds the alpha that gives the required ATM volatility * @param data SABR parameters - the alpha value is ignored * @param option The option/* ww w . java 2 s . co m*/ * @param forward the forward * @param atmVol The ATM volatility * @return the value of alpha */ public double calculate(final SABRFormulaData data, final EuropeanVanillaOption option, final double forward, final double atmVol) { Validate.notNull(data, "data"); Validate.notNull(option, "option"); Validate.isTrue(atmVol > 0, "ATM vol must be > 0"); final Function1D<Double, Double> f = new Function1D<Double, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final Double alpha) { final SABRFormulaData newData = new SABRFormulaData(alpha, data.getBeta(), data.getRho(), data.getNu()); return _sabrFormula.getVolatilityFunction(option, forward).evaluate(newData) - atmVol; } }; final double alphaTry = atmVol * Math.pow(forward, 1 - data.getBeta()); final double[] range = _bracketer.getBracketedPoints(f, alphaTry / 2.0, 2 * alphaTry); return _rootFinder.getRoot(f, range[0], range[1]); }
From source file:net.daboross.bukkitdev.skywars.world.WorldCopier.java
public void destroyArena(SkyBlockLocation arenaMin, SkyBlockLocationRange area) { Validate.notNull(arenaMin, "ArenaMin cannot be null"); Validate.notNull(area, "Area cannot be null"); World world = Bukkit.getWorld(arenaMin.world); Validate.isTrue(world != null, "World not found"); SkyBlockLocation clearingMin = new SkyBlockLocation(arenaMin.x + area.min.x, arenaMin.y + area.min.y, arenaMin.z + area.min.z, null); SkyBlockLocation clearingMax = new SkyBlockLocation(arenaMin.x + area.max.x, arenaMin.y + area.max.y, arenaMin.z + area.max.z, null); destroyArena(clearingMin, clearingMax, world); }
From source file:com.opengamma.analytics.financial.instrument.swap.SwapIborONDefinition.java
/** * Constructor of the fixed-OIS swap from its two legs. * @param iborLeg The Ibor leg.//from w w w .ja va 2s . com * @param oisLeg The OIS leg. */ public SwapIborONDefinition(final AnnuityCouponIborSpreadDefinition iborLeg, final AnnuityCouponOISDefinition oisLeg) { super(iborLeg, oisLeg); Validate.isTrue(iborLeg.getCurrency() == oisLeg.getCurrency(), "Legs should have the same currency"); }
From source file:com.opengamma.analytics.financial.model.finitedifference.applications.TwoStateMarkovChainDataBundle.java
/** * /*w w w .jav a2s. co m*/ * @param vol1 Volatility of state 1 * @param vol2 Volatility of state 1 * @param lambda12 Transition rate from state 1 to 2 * @param lambda21 Transition rate from state 2 to 1 * @param probS1 Probability of starting in state 1 * @param beta1 CEV parameter in state 1 * @param beta2 CEV parameter in state 2 */ public TwoStateMarkovChainDataBundle(final double vol1, final double vol2, final double lambda12, final double lambda21, final double probS1, final double beta1, final double beta2) { Validate.isTrue(vol1 >= 0.0, "vol1 < 0"); Validate.isTrue(vol2 >= vol1, "vol2 < vol1"); Validate.isTrue(lambda12 >= 0.0, "lambda12 < 0"); Validate.isTrue(lambda21 >= 0.0, "lambda21 < 0"); Validate.isTrue(probS1 >= 0.0 && probS1 <= 1.0, "Need 0 <= probS1 <= 1.0"); Validate.isTrue(beta1 >= 0.0 && beta1 <= 2.0, "Need 0 <= beta1 <= 2.0"); Validate.isTrue(beta2 >= 0.0 && beta2 <= 2.0, "Need 0 <= beta2 <= 2.0"); _vol1 = vol1; _vol2 = vol2; _beta1 = beta1; _beta2 = beta2; _lambda12 = lambda12; _lambda21 = lambda21; _p0 = probS1; double sum = lambda12 + lambda21; if (sum == 0) { _pi1 = probS1; } else { _pi1 = lambda21 / sum; } }
From source file:fr.ritaly.dungeonmaster.Temporizer.java
public Temporizer(String label, int max) { Validate.isTrue(!StringUtils.isEmpty(label), String.format("The given label '%s' is blank", label)); Validate.isTrue(max > 0, String.format("The given max value %d must be positive", max)); this.label = label; this.max = max; this.current = max; }
From source file:hr.fer.spocc.regex.AbstractRegularExpression.java
public AbstractRegularExpression(Collection<RegularExpressionElement> c) throws IllegalArgumentException { Validate.isTrue(c != null && !c.isEmpty(), "Element list must be non-empty"); this.elements = Collections.unmodifiableList(new ArrayList<RegularExpressionElement>(c)); RegularExpression<T> root = createParseTree(elements); this.type = root.getType(); if (root.isTrivial()) { this.operator = null; this.subexpression1 = null; this.subexpression2 = null; } else {// w w w . j a v a 2 s . co m this.operator = root.getOperator(); int arity = operator.getArity(); this.subexpression1 = (arity > 0 ? root.getSubexpression(0) : null); this.subexpression2 = (arity > 1 ? root.getSubexpression(1) : null); } }
From source file:fr.ritaly.dungeonmaster.map.Stairs.java
public Stairs(Direction direction, boolean ascending, Position destination) { super(Type.STAIRS, direction); Validate.isTrue(destination != null, "The given destination is null"); this.ascending = ascending; this.destination = destination; }
From source file:com.opengamma.analytics.financial.model.option.definition.SupershareOptionDefinition.java
/** * @param expiry The expiry/*from w ww. ja v a 2 s. c o m*/ * @param lowerBound The lower bound * @param upperBound The upper bound */ public SupershareOptionDefinition(final Expiry expiry, final double lowerBound, final double upperBound) { super(null, expiry, null); Validate.isTrue(lowerBound >= 0, "lower bound must be >= 0"); Validate.isTrue(upperBound >= 0, "upper bound must be >= 0"); Validate.isTrue(upperBound > lowerBound, "Lower bound must be less than upper bound"); _lowerBound = lowerBound; _upperBound = upperBound; }