當前位置: 首頁>>代碼示例>>Java>>正文


Java Validate.isTrue方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:Alvin-LB,項目名稱:NameTagChanger,代碼行數:22,代碼來源:NameTagChanger.java

示例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 );
    }
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:17,代碼來源:CraftWorld.java

示例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()]);
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:21,代碼來源:SimpleAddonManager.java

示例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));
  }
}
 
開發者ID:apache,項目名稱:geode-examples,代碼行數:15,代碼來源:Example.java

示例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);
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:11,代碼來源:CraftScoreboard.java

示例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);
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:8,代碼來源:CraftTeam.java

示例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;
}
 
開發者ID:yaogdu,項目名稱:datax,代碼行數:44,代碼來源:JobAssignUtil.java

示例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));
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:8,代碼來源:CraftScoreboard.java

示例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();
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:16,代碼來源:CraftWorld.java

示例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.");
    }
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:14,代碼來源:DbDeployerMain.java

示例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);
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:9,代碼來源:CraftPlayer.java

示例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;
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:10,代碼來源:CraftInventoryCustom.java

示例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;
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:21,代碼來源:ExperienceManager.java

示例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()));
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:15,代碼來源:BarrelParticleForm.java

示例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);
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:6,代碼來源:CraftPlayer.java


注:本文中的org.apache.commons.lang.Validate.isTrue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。