Java Code Examples for org.apache.commons.lang.Validate.isTrue()

The following are Jave code examples for showing how to use isTrue() of the org.apache.commons.lang.Validate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: NameTagChanger   File: NameTagChanger.java   View Source Code Vote up 6 votes
/**
 * 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;
    }
}
 
Example 2
Project: Uranium   File: CraftWorld.java   View Source Code Vote up 6 votes
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 );
    }
}
 
Example 3
Project: AlphaLibary   File: SimpleAddonManager.java   View Source Code Vote up 6 votes
@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()]);
}
 
Example 4
Project: geode-examples   File: Example.java   View Source Code Vote up 5 votes
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));
  }
}
 
Example 5
Project: Uranium   File: CraftScoreboard.java   View Source Code Vote up 5 votes
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);
}
 
Example 6
Project: Uranium   File: CraftTeam.java   View Source Code Vote up 5 votes
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);
}
 
Example 7
Project: datax   File: JobAssignUtil.java   View Source Code Vote up 5 votes
/**
 * 公平的分配 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;
}
 
Example 8
Project: Uranium   File: CraftScoreboard.java   View Source Code Vote up 5 votes
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));
}
 
Example 9
Project: Uranium   File: CraftWorld.java   View Source Code Vote up 5 votes
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();
}
 
Example 10
Project: obevo   File: DbDeployerMain.java   View Source Code Vote up 5 votes
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.");
    }
}
 
Example 11
Project: Uranium   File: CraftPlayer.java   View Source Code Vote up 5 votes
@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);
}
 
Example 12
Project: Uranium   File: CraftInventoryCustom.java   View Source Code Vote up 5 votes
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;
}
 
Example 13
Project: PA   File: ExperienceManager.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 14
Project: AlphaLibary   File: BarrelParticleForm.java   View Source Code Vote up 5 votes
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()));
}
 
Example 15
Project: Uranium   File: CraftPlayer.java   View Source Code Vote up 4 votes
@Override
public void decrementStatistic(Statistic statistic, int amount) {
    Validate.isTrue(amount > 0, "Amount must be greater than 0");
    setStatistic(statistic, getStatistic(statistic) - amount);
}
 
Example 16
Project: lams   File: ExtendedMessageFormat.java   View Source Code Vote up 4 votes
/**
 * Apply the specified pattern.
 * 
 * @param pattern String
 */
public final void applyPattern(String pattern) {
    if (registry == null) {
        super.applyPattern(pattern);
        toPattern = super.toPattern();
        return;
    }
    ArrayList foundFormats = new ArrayList();
    ArrayList foundDescriptions = new ArrayList();
    StrBuilder stripCustom = new StrBuilder(pattern.length());

    ParsePosition pos = new ParsePosition(0);
    char[] c = pattern.toCharArray();
    int fmtCount = 0;
    while (pos.getIndex() < pattern.length()) {
        switch (c[pos.getIndex()]) {
        case QUOTE:
            appendQuotedString(pattern, pos, stripCustom, true);
            break;
        case START_FE:
            fmtCount++;
            seekNonWs(pattern, pos);
            int start = pos.getIndex();
            int index = readArgumentIndex(pattern, next(pos));
            stripCustom.append(START_FE).append(index);
            seekNonWs(pattern, pos);
            Format format = null;
            String formatDescription = null;
            if (c[pos.getIndex()] == START_FMT) {
                formatDescription = parseFormatDescription(pattern,
                        next(pos));
                format = getFormat(formatDescription);
                if (format == null) {
                    stripCustom.append(START_FMT).append(formatDescription);
                }
            }
            foundFormats.add(format);
            foundDescriptions.add(format == null ? null : formatDescription);
            Validate.isTrue(foundFormats.size() == fmtCount);
            Validate.isTrue(foundDescriptions.size() == fmtCount);
            if (c[pos.getIndex()] != END_FE) {
                throw new IllegalArgumentException(
                        "Unreadable format element at position " + start);
            }
            //$FALL-THROUGH$
        default:
            stripCustom.append(c[pos.getIndex()]);
            next(pos);
        }
    }
    super.applyPattern(stripCustom.toString());
    toPattern = insertFormats(super.toPattern(), foundDescriptions);
    if (containsElements(foundFormats)) {
        Format[] origFormats = getFormats();
        // only loop over what we know we have, as MessageFormat on Java 1.3 
        // seems to provide an extra format element:
        int i = 0;
        for (Iterator it = foundFormats.iterator(); it.hasNext(); i++) {
            Format f = (Format) it.next();
            if (f != null) {
                origFormats[i] = f;
            }
        }
        super.setFormats(origFormats);
    }
}
 
Example 17
Project: Uranium   File: CraftWorld.java   View Source Code Vote up 4 votes
@Deprecated
public LivingEntity spawnCreature(Location loc, EntityType creatureType) {
    Validate.isTrue(creatureType.isAlive(), "EntityType not instance of LivingEntity");
    return (LivingEntity) spawnEntity(loc, creatureType);
}
 
Example 18
Project: NameTagChanger   File: GameProfileWrapper.java   View Source Code Vote up 4 votes
@SuppressWarnings("ConstantConditions")
public static PropertyWrapper fromHandle(Object object) {
    Validate.isTrue(object instanceof Property, "object " + object + " is not a Property");
    Property property = (Property) object;
    return new PropertyWrapper(property.getName(), property.getValue(), property.getSignature());
}
 
Example 19
Project: Uranium   File: CraftInventoryPlayer.java   View Source Code Vote up 4 votes
public void setHeldItemSlot(int slot) {
    Validate.isTrue(slot >= 0 && slot < net.minecraft.entity.player.InventoryPlayer.getHotbarSize(), "Slot is not between 0 and 8 inclusive");
    this.getInventory().currentItem = slot;
    ((CraftPlayer) this.getHolder()).getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S09PacketHeldItemChange(slot));
}
 
Example 20
Project: PA   File: ExperienceManager.java   View Source Code Vote up 2 votes
/**
 * Retrieves the amount of experience the experience bar can hold at the given level.
 *
 * @param level the level to check
 * @return the amount of experience at this level in the level bar
 * @throws IllegalArgumentException if the level is less than 0
 */
public int getXpNeededToLevelUp(int level) {
    Validate.isTrue(level >= 0, "Level may not be negative.");
    return level > 30 ? 62 + (level - 30) * 7 : level >= 16 ? 17 + (level - 15) * 3 : 17;
}