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.comphenix.protocol.ProtocolLibrary.java
protected static void init(Plugin plugin, ProtocolConfig config, ProtocolManager manager, ErrorReporter reporter, ListeningScheduledExecutorService executorAsync, ListeningScheduledExecutorService executorSync) { Validate.isTrue(!initialized, "ProtocolLib has already been initialized."); ProtocolLibrary.plugin = plugin;//w w w.j av a 2 s. co m ProtocolLibrary.config = config; ProtocolLibrary.manager = manager; ProtocolLibrary.reporter = reporter; ProtocolLibrary.executorAsync = executorAsync; ProtocolLibrary.executorSync = executorSync; initialized = true; }
From source file:com.opengamma.component.factory.tool.DbToolContextComponentFactoryTest.java
@Test public void test_RecognizeMSSQL() { Validate.isTrue(getMSSQLCatalog(MSSQL_URL_1).equals(MSSQL_DB), "url1 did not work"); Validate.isTrue(getMSSQLCatalog(MSSQL_URL_2).equals(MSSQL_DB), "url2 did not work"); Validate.isTrue(getMSSQLCatalog(MSSQL_URL_3).equals(MSSQL_DB), "url3 did not work"); }
From source file:net.daboross.bukkitdev.skywars.events.events.GameEndInfo.java
public GameEndInfo(ArenaGame game, boolean broadcast, boolean endSyncNowPluginShutdown) { Validate.notNull(game, "Game cannot be null"); this.game = game; this.broadcast = broadcast; this.endSyncNowPluginShutdown = endSyncNowPluginShutdown; List<UUID> alive = game.getAlivePlayers(); alivePlayers = new ArrayList<>(); for (UUID uuid : alive) { Player p = Bukkit.getPlayer(uuid); Validate.isTrue(p != null, String.format("Player (uuid: %s) not online", uuid)); alivePlayers.add(p);/* w ww. j av a2s . c o m*/ } }
From source file:com.skelril.aurora.events.shard.PartyActivateEvent.java
public void setInstance(ShardInstance instance) { Validate.notNull(instance);/*from w w w. ja va 2 s . c o m*/ Validate.isTrue(shard.equals(instance.getMaster().getType()), "The instance must be the same type as the shard."); if (this.instance != null) { throw new IllegalStateException("The instance has already been set!"); } this.instance = instance; }
From source file:com.opengamma.analytics.math.interpolation.data.Interpolator1DDataBundleBuilderFunction.java
@Override public LinkedHashMap<String, Interpolator1DDataBundle> evaluate(final DoubleMatrix1D x) { Validate.notNull(x, "null data x"); Validate.isTrue(_nNodes == x.getNumberOfElements(), "x wrong length"); final LinkedHashMap<String, Interpolator1DDataBundle> res = new LinkedHashMap<String, Interpolator1DDataBundle>(); int index = 0; for (final String name : _interpolators.keySet()) { final Interpolator1D interpolator = _interpolators.get(name); final double[] nodes = _knotPoints.get(name); final double[] values = Arrays.copyOfRange(x.getData(), index, index + nodes.length); index += nodes.length;/*from ww w . ja v a 2 s. co m*/ final Interpolator1DDataBundle db = interpolator.getDataBundleFromSortedArrays(nodes, values); res.put(name, db); } return res; }
From source file:io.github.prison.spigot.SpigotSign.java
@Override public void setLine(int line, String value) { Validate.isTrue(line >= 0 && line < 4, "line must be 0 <= line < 4"); bSign.setLine(line, value);// ww w .j ava 2s. c o m bSign.update(); }
From source file:me.st28.flexseries.flexcore.util.MaterialRef.java
public MaterialRef(Material material, short damage) { Validate.notNull(material, "Material cannot be null."); Validate.isTrue(damage >= 0, "Damage value must be 0 or more."); this.material = material; this.damage = damage; }
From source file:com.opengamma.analytics.math.statistics.distribution.BivariateNormalDistribution.java
/** * @param x The parameters for the function, $(x, y, \rho$, with $-1 \geq \rho \geq 1$, not null * @return The cdf/*from ww w . ja v a 2 s . com*/ */ @Override public double getCDF(final double[] x) { Validate.notNull(x); Validate.isTrue(x.length == 3, "Need a, b and rho values"); Validate.isTrue(x[2] >= -1 && x[2] <= 1, "Correlation must be >= -1 and <= 1"); final double a = x[0]; double b = x[1]; final double rho = x[2]; if (a == Double.POSITIVE_INFINITY || b == Double.POSITIVE_INFINITY) { return 1; } if (a == Double.NEGATIVE_INFINITY || b == Double.NEGATIVE_INFINITY) { return 0; } final double sumSq = (a * a + b * b) / 2.; double rho1, rho2, rho3, ab, absDiff, h5, c, d, mult = 0, rho3Sq, eab, e, result; if (Math.abs(rho) >= 0.7) { rho1 = 1 - rho * rho; rho2 = Math.sqrt(rho1); if (rho < 0) { b *= -1; } ab = a * b; eab = Math.exp(-ab / 2.); if (Math.abs(rho) < 1) { absDiff = Math.abs(a - b); h5 = absDiff * absDiff / 2.; absDiff = absDiff / rho2; c = 0.5 - ab / 8.; d = 3. - 2. * c * h5; mult = 0.13298076 * absDiff * d * (1 - NORMAL.getCDF(absDiff)) - Math.exp(-h5 / rho1) * (d + c * rho1) * 0.053051647; for (int i = 0; i < 5; i++) { rho3 = rho2 * X[i]; rho3Sq = rho3 * rho3; rho1 = Math.sqrt(1 - rho3Sq); if (eab == 0) { e = 0; } else { e = Math.exp(-ab / (1 + rho1)) / rho1 / eab; } mult = mult - Y[i] * Math.exp(-h5 / rho3Sq) * (e - 1 - c * rho3Sq); } } result = mult * rho2 * eab + NORMAL.getCDF(Math.min(a, b)); if (rho < 0) { result = NORMAL.getCDF(a) - result; } return result; } ab = a * b; if (rho != 0) { for (int i = 0; i < 5; i++) { rho3 = rho * X[i]; rho1 = 1 - rho3 * rho3; mult = mult + Y[i] * Math.exp((rho3 * ab - sumSq) / rho1) / Math.sqrt(rho1); } } return NORMAL.getCDF(a) * NORMAL.getCDF(b) + rho * mult; }
From source file:com.opengamma.financial.analytics.model.irfutureoption.FutureOptionUtils.java
public static LocalDate getIRFutureOptionWithSerialOptionsExpiry(final int nthFuture, final LocalDate valDate, final Calendar holidayCalendar) { Validate.isTrue(nthFuture > 0, "nthFuture must be greater than 0."); if (nthFuture <= 6) { // We look for expiries in the first 6 serial months after curveDate return getIRFutureMonthlyExpiryDate(nthFuture, valDate, holidayCalendar); } // And for Quarterly expiries thereafter final int nthExpiryAfterSixMonths = nthFuture - 6; final LocalDate sixMonthsForward = valDate.plusMonths(6); return getIRFutureQuarterlyExpiryDate(nthExpiryAfterSixMonths, sixMonthsForward, holidayCalendar); }
From source file:io.cloudslang.engine.partitions.services.PartitionServiceImpl.java
@Override @Transactional/* www .j a va2 s . c om*/ public void createPartitionGroup(String groupName, int groupSize, long timeThreshold, long sizeThreshold) { Validate.notEmpty(groupName, "Group name is empty or null"); Validate.isTrue(groupSize >= MIN_GROUP_SIZE, formatMessage2Small("Group size", groupSize, MIN_GROUP_SIZE)); // Validate.isTrue(timeThreshold==-1 || timeThreshold >= MIN_TIME_THRESHOLD, formatMessage2Small("Time threshold", timeThreshold, MIN_TIME_THRESHOLD)); // Validate.isTrue(sizeThreshold==-1 || sizeThreshold >= MIN_SIZE_THRESHOLD, formatMessage2Small("Size threshold", sizeThreshold, MIN_SIZE_THRESHOLD)); repository.save(new PartitionGroup(groupName, groupSize, timeThreshold, sizeThreshold)); if (logger.isInfoEnabled()) logger.info("Partition group [" + groupName + "] was created, with group size " + groupSize + ", and timeThreshold " + timeThreshold + ", and sizeThreshold " + sizeThreshold); }