本文整理匯總了Java中org.apache.commons.lang.Validate.isTrue方法的典型用法代碼示例。如果您正苦於以下問題:Java Validate.isTrue方法的具體用法?Java Validate.isTrue怎麽用?Java Validate.isTrue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.Validate
的用法示例。
在下文中一共展示了Validate.isTrue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getChangedSkin
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
/**
* Gets a player's changed skin
*
* @param player the player to get the changed skin of
* @return the changed skin
*/
public Skin getChangedSkin(Player player) {
Validate.isTrue(enabled, "NameTagChanger is disabled");
GameProfileWrapper profile = gameProfiles.get(player.getUniqueId());
if (profile == null) {
return null;
}
Skin skin = getSkinFromGameProfile(profile);
if (skin.equals(getDefaultSkinFromPlayer(player))) {
// The skin is the normal skin for the player,
// meaning there is no changed skin
return null;
} else {
return skin;
}
}
示例2: playEffect
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
public <T> void playEffect(Location loc, Effect effect, T data, int radius) {
if (data != null) {
Validate.isTrue(data.getClass().equals(effect.getData()), "Wrong kind of data for this effect!");
} else {
Validate.isTrue(effect.getData() == null, "Wrong kind of data for this effect!");
}
if (data != null && data.getClass().equals( org.bukkit.material.MaterialData.class )) {
org.bukkit.material.MaterialData materialData = (org.bukkit.material.MaterialData) data;
Validate.isTrue( materialData.getItemType().isBlock(), "Material must be block" );
spigot().playEffect( loc, effect, materialData.getItemType().getId(), materialData.getData(), 0, 0, 0, 1, 1, radius );
} else {
int dataValue = data == null ? 0 : CraftEffect.getDataValue( effect, data );
playEffect( loc, effect, dataValue, radius );
}
}
示例3: loadAddons
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
@Override
public Addon[] loadAddons(File directory) {
Validate.notNull(directory, "Directory cannot be null");
Validate.isTrue(directory.isDirectory(), "Directory must be a directory");
List<Addon> result = new ArrayList<>();
for (File file : directory.listFiles()) {
if (!JAR_PATTERN.matcher(file.getName()).matches()) continue;
try {
result.add(this.loadAddon(file));
} catch (InvalidAddonException e) {
AddonCore.getLogger().log(Level.SEVERE,
"Cannot load '" + file.getName() + "' in folder '" + directory.getPath() + "': " + e.getMessage());
}
}
return result.toArray(new Addon[result.size()]);
}
示例4: adminUserCanPutAndGetEverywhere
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
private static void adminUserCanPutAndGetEverywhere() throws Exception {
String valueFromRegion;
try (Example example = new Example("superUser")) {
// All puts and gets should pass
example.region1.put(AUTHOR_ABERCROMBIE, BOOK_BY_ABERCROMBIE);
example.region2.put(AUTHOR_GROSSMAN, BOOK_BY_GROSSMAN);
valueFromRegion = example.region1.get(AUTHOR_ABERCROMBIE);
Validate.isTrue(BOOK_BY_ABERCROMBIE.equals(valueFromRegion));
valueFromRegion = example.region2.get(AUTHOR_GROSSMAN);
Validate.isTrue(BOOK_BY_GROSSMAN.equals(valueFromRegion));
}
}
示例5: registerNewObjective
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException {
Validate.notNull(name, "Objective name cannot be null");
Validate.notNull(criteria, "Criteria cannot be null");
Validate.isTrue(name.length() <= 16, "The name '" + name + "' is longer than the limit of 16 characters");
Validate.isTrue(board.getObjective(name) == null, "An objective of name '" + name + "' already exists");
CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria);
net.minecraft.scoreboard.ScoreObjective objective = board.addScoreObjective(name, craftCriteria.criteria);
return new CraftObjective(this, objective);
}
示例6: setSuffix
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
public void setSuffix(String suffix) throws IllegalStateException, IllegalArgumentException {
Validate.notNull(suffix, "Suffix cannot be null");
Validate.isTrue(suffix.length() <= 32, "Suffix '" + suffix + "' is longer than the limit of 32 characters");
CraftScoreboard scoreboard = checkState();
team.setNameSuffix(suffix);
}
示例7: assignFairly
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
/**
* 公平的分配 task 到對應的 taskGroup 中。
* 公平體現在:會考慮 task 中對資源負載作的 load 標識進行更均衡的作業分配操作。
* TODO 具體文檔舉例說明
*/
public static List<Configuration> assignFairly(Configuration configuration, int channelNumber, int channelsPerTaskGroup) {
Validate.isTrue(configuration != null, "框架獲得的 Job 不能為 null.");
List<Configuration> contentConfig = configuration.getListConfiguration(CoreConstant.DATAX_JOB_CONTENT);
Validate.isTrue(contentConfig.size() > 0, "框架獲得的切分後的 Job 無內容.");
Validate.isTrue(channelNumber > 0 && channelsPerTaskGroup > 0,
"每個channel的平均task數[averTaskPerChannel],channel數目[channelNumber],每個taskGroup的平均channel數[channelsPerTaskGroup]都應該為正數");
int taskGroupNumber = (int) Math.ceil(1.0 * channelNumber / channelsPerTaskGroup);
Configuration aTaskConfig = contentConfig.get(0);
String readerResourceMark = aTaskConfig.getString(CoreConstant.JOB_READER_PARAMETER + "." +
CommonConstant.LOAD_BALANCE_RESOURCE_MARK);
String writerResourceMark = aTaskConfig.getString(CoreConstant.JOB_WRITER_PARAMETER + "." +
CommonConstant.LOAD_BALANCE_RESOURCE_MARK);
boolean hasLoadBalanceResourceMark = StringUtils.isNotBlank(readerResourceMark) ||
StringUtils.isNotBlank(writerResourceMark);
if (!hasLoadBalanceResourceMark) {
// fake 一個固定的 key 作為資源標識(在 reader 或者 writer 上均可,此處選擇在 reader 上進行 fake)
for (Configuration conf : contentConfig) {
conf.set(CoreConstant.JOB_READER_PARAMETER + "." +
CommonConstant.LOAD_BALANCE_RESOURCE_MARK, "aFakeResourceMarkForLoadBalance");
}
// 是為了避免某些插件沒有設置 資源標識 而進行了一次隨機打亂操作
Collections.shuffle(contentConfig, new Random(System.currentTimeMillis()));
}
LinkedHashMap<String, List<Integer>> resourceMarkAndTaskIdMap = parseAndGetResourceMarkAndTaskIdMap(contentConfig);
List<Configuration> taskGroupConfig = doAssign(resourceMarkAndTaskIdMap, configuration, taskGroupNumber);
// 調整 每個 taskGroup 對應的 Channel 個數(屬於優化範疇)
adjustChannelNumPerTaskGroup(taskGroupConfig, channelNumber);
return taskGroupConfig;
}
示例8: registerNewTeam
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
public Team registerNewTeam(String name) throws IllegalArgumentException {
Validate.notNull(name, "Team name cannot be null");
Validate.isTrue(name.length() <= 16, "Team name '" + name + "' is longer than the limit of 16 characters");
Validate.isTrue(board.getTeam(name) == null, "Team name '" + name + "' is already in use");
return new CraftTeam(this, board.createTeam(name));
}
示例9: spawnFallingBlock
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException {
Validate.notNull(location, "Location cannot be null");
Validate.notNull(material, "Material cannot be null");
Validate.isTrue(material.isBlock(), "Material must be a block");
double x = location.getBlockX() + 0.5;
double y = location.getBlockY() + 0.5;
double z = location.getBlockZ() + 0.5;
net.minecraft.entity.item.EntityFallingBlock entity = new net.minecraft.entity.item.EntityFallingBlock(world, x, y, z, net.minecraft.block.Block.getBlockById(material.getId()), data);
entity.field_145812_b = 1; // ticksLived
world.addEntity(entity, SpawnReason.CUSTOM);
return (FallingBlock) entity.getBukkitEntity();
}
示例10: checkIfCleanBuildShouldProceed
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
private void checkIfCleanBuildShouldProceed(Environment env, boolean noPrompt) {
LOG.info("Request was made to clean the environment...");
Validate.isTrue(env.isCleanBuildAllowed(), "Clean build not allowed for this environment [" + env.getName()
+ "] ! Exiting...");
if (!noPrompt) {
LOG.info("WARNING - This will wipe the whole environment!!! Are you sure you want to proceed? (Y/N)");
String input = this.userInputReader.readLine(null);
Validate.isTrue(input.trim().equalsIgnoreCase("Y"), "User did not enter Y. Hence, we will exit from here.");
}
}
示例11: setStatistic
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
@Override
public void setStatistic(Statistic statistic, int newValue) {
Validate.notNull(statistic, "Statistic cannot be null");
Validate.isTrue(statistic.getType() == Type.UNTYPED, "Must supply additional paramater for this statistic");
Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0");
net.minecraft.stats.StatBase nmsStatistic = CraftStatistic.getNMSStatistic(statistic);
getHandle().func_147099_x().func_150873_a(getHandle(), nmsStatistic, newValue);
}
示例12: MinecraftInventory
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
public MinecraftInventory(InventoryHolder owner, int size, String title) {
Validate.notNull(title, "Title cannot be null");
Validate.isTrue(title.length() <= 32, "Title cannot be longer than 32 characters");
this.items = new net.minecraft.item.ItemStack[size];
this.title = title;
this.viewers = new ArrayList<HumanEntity>();
this.owner = owner;
this.type = InventoryType.CHEST;
}
示例13: getLevelForExp
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
/**
* Get the level that the given amount of XP falls within.
*
* @param exp the amount to check for
* @return the level that a player with this amount total XP would be
* @throws IllegalArgumentException if the given XP is less than 0
*/
public int getLevelForExp(int exp) {
if (exp <= 0) {
return 0;
}
if (exp > xpTotalToReachLevel[xpTotalToReachLevel.length - 1]) {
// need to extend the lookup tables
int newMax = calculateLevelForExp(exp) * 2;
Validate.isTrue(newMax <= hardMaxLevel, "Level for exp " + exp + " > hard max level " + hardMaxLevel);
initLookupTables(newMax);
}
int pos = Arrays.binarySearch(xpTotalToReachLevel, exp);
return pos < 0 ? -pos - 2 : pos;
}
示例14: BarrelParticleForm
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
public BarrelParticleForm(Effect effect, EffectData<?> effectData, Location location, String axis, double dense, double depth, double radius, BlockFace direction) {
super(location, axis, dense, depth, radius, direction, null);
if (effectData != null)
Validate.isTrue(effect.getData() != null && effect.getData().isAssignableFrom(effectData.getDataValue().getClass()), "Wrong kind of effectData for this effect!");
else {
Validate.isTrue(effect.getData() == null, "Wrong kind of effectData for this effect!");
effectData = new EffectData<>(null);
}
EffectData<?> finalEffectData = effectData;
setAction((p, loc) -> p.playEffect(loc, effect, finalEffectData.getDataValue()));
}
示例15: decrementStatistic
import org.apache.commons.lang.Validate; //導入方法依賴的package包/類
@Override
public void decrementStatistic(Statistic statistic, int amount) {
Validate.isTrue(amount > 0, "Amount must be greater than 0");
setStatistic(statistic, getStatistic(statistic) - amount);
}