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


Java Validate類代碼示例

本文整理匯總了Java中org.apache.commons.lang.Validate的典型用法代碼示例。如果您正苦於以下問題:Java Validate類的具體用法?Java Validate怎麽用?Java Validate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Validate類屬於org.apache.commons.lang包,在下文中一共展示了Validate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tabComplete

import org.apache.commons.lang.Validate; //導入依賴的package包/類
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
{
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 1)
    {
        return StringUtil.copyPartialMatches(args[0], COMMANDS, new ArrayList<String>(COMMANDS.size()));
    }
    if (((args.length == 2) && "get".equalsIgnoreCase(args[0])) || "set".equalsIgnoreCase(args[0]))
    {
        return StringUtil.copyPartialMatches(args[1], MinecraftServer.getServer().tileEntityConfig.getSettings().keySet(), new ArrayList<String>(MinecraftServer.getServer().tileEntityConfig.getSettings().size()));
    }

    return ImmutableList.of();
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:19,代碼來源:TileEntityCommand.java

示例2: enable

import org.apache.commons.lang.Validate; //導入依賴的package包/類
/**
 * Enables NameTagChanger and creates necessary packet handlers.
 * Is done automatically by the constructor, so only use this method
 * if the disable() method has previously been called.
 */
public void enable() {
    if (plugin == null) {
        return;
    }
    if (!ReflectUtil.isVersionHigherThan(1, 7, 10)) {
        printMessage("NameTagChanger has detected that you are running 1.7 or lower. This probably means that NameTagChanger will not work or throw errors, but you are still free to try and use it.\nIf you are not a developer, please consider contacting the developer of " + plugin.getName() + " and informing them about this message.");
    }
    ConfigurationSerialization.registerClass(Skin.class);
    Validate.isTrue(!enabled, "NameTagChanger is already enabled");
    if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
        packetHandler = new ProtocolLibPacketHandler(plugin);
    } else {
        packetHandler = new ChannelPacketHandler(plugin);
    }
    enabled = true;
    Metrics metrics = new Metrics(plugin);
    metrics.addCustomChart(new Metrics.SimplePie("packet_implementation", () -> packetHandler instanceof ProtocolLibPacketHandler ? "ProtocolLib" : "ChannelInjector"));
}
 
開發者ID:Alvin-LB,項目名稱:NameTagChanger,代碼行數:24,代碼來源:NameTagChanger.java

示例3: sendSignChange

import org.apache.commons.lang.Validate; //導入依賴的package包/類
@Override
public void sendSignChange(Location loc, String[] lines) {
    if (getHandle().playerNetServerHandler == null) {
        return;
    }

    if (lines == null) {
        lines = new String[4];
    }

    Validate.notNull(loc, "Location can not be null");
    if (lines.length < 4) {
        throw new IllegalArgumentException("Must have at least 4 lines");
    }

    // Limit to 15 chars per line and set null lines to blank
    String[] astring = CraftSign.sanitizeLines(lines);

    getHandle().playerNetServerHandler.sendPacket(new S33PacketUpdateSign(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), astring));
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:21,代碼來源:CraftPlayer.java

示例4: ParticleShapeDefinition

import org.apache.commons.lang.Validate; //導入依賴的package包/類
/**
 * Construct a new ParticleShapeDefinition with a given location, and mathmatical equations
 * for both the x and z axis
 * 
 * @param initialLocation the initial starting location
 * @param xExpression the expression for the x axis
 * @param zExpression the expression for the y axis
 */
public ParticleShapeDefinition(Location initialLocation, String xExpression, String zExpression) {
	Validate.notNull(initialLocation, "Null initial locations are not supported");
	Validate.notEmpty(xExpression, "The x axis expression cannot be null or empty");
	Validate.notEmpty(zExpression, "The z axis expression cannot be null or empty");
	
	this.variables.put("x", 0.0);
	this.variables.put("z", 0.0);
	this.variables.put("t", 0.0);
	this.variables.put("theta", 0.0);
	
	this.initialLocation = initialLocation;
	this.world = initialLocation.getWorld();
	this.xExpression = MathUtils.parseExpression(xExpression, variables);
	this.zExpression = MathUtils.parseExpression(zExpression, variables);
}
 
開發者ID:2008Choco,項目名稱:DragonEggDrop,代碼行數:24,代碼來源:ParticleShapeDefinition.java

示例5: hidePlayer

import org.apache.commons.lang.Validate; //導入依賴的package包/類
public void hidePlayer(Player player) {
    Validate.notNull(player, "hidden player cannot be null");
    if (getHandle().playerNetServerHandler == null) return;
    if (equals(player)) return;
    if (hiddenPlayers.contains(player.getUniqueId())) return;
    hiddenPlayers.add(player.getUniqueId());

    //remove this player from the hidden player's EntityTrackerEntry
    net.minecraft.entity.EntityTracker tracker = ((net.minecraft.world.WorldServer) entity.worldObj).theEntityTracker;
    net.minecraft.entity.player.EntityPlayerMP other = ((CraftPlayer) player).getHandle();
    net.minecraft.entity.EntityTrackerEntry entry = (net.minecraft.entity.EntityTrackerEntry) tracker.trackedEntityIDs.lookup(other.getEntityId());
    if (entry != null) {
        entry.removePlayerFromTracker(getHandle());
    }

    //remove the hidden player from this player user list
    getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S38PacketPlayerListItem(player.getPlayerListName(), false, 9999));
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:19,代碼來源:CraftPlayer.java

示例6: createNode

import org.apache.commons.lang.Validate; //導入依賴的package包/類
/**
 * @param email Mail of the new user.
 * @param username Username of the new user.
 * @param first_name First name of the new user.
 * @param last_name Last name of the new user.
 * @param password Password of the new user OPTIONAL. (Leave blank will be generated by the panel randomly)
 * @param root_admin Set the root admin role of the new user.
 * @return if success it return the ID of the new user.
 */
public String createNode(String email, String username, String first_name, String last_name, String password, boolean root_admin){
	Validate.notEmpty(email, "The MAIL is required");
	Validate.notEmpty(username, "The USERNAME is required");
	Validate.notEmpty(first_name, "The FIRST_NAME is required");
	Validate.notEmpty(last_name, "The LAST_NAME is required");
	Validate.notNull(root_admin, "The ROOT_ADMIN Boolean is required");
	int admin = (root_admin) ? 1 : 0;
	return call(main.getMainURL() + Methods.USERS_CREATE_USER.getURL(), 
			"email="+email+
			"&username="+username+
			"&name_first="+first_name+
			"&name_last="+last_name+
			"&password="+password+
			"&root_admin="+admin);
}
 
開發者ID:Axeldu18,項目名稱:Pterodactyl-JAVA-API,代碼行數:25,代碼來源:POSTMethods.java

示例7: addEffects

import org.apache.commons.lang.Validate; //導入依賴的package包/類
public void addEffects(FireworkEffect...effects) {
    Validate.notNull(effects, "Effects cannot be null");
    if (effects.length == 0) {
        return;
    }

    List<FireworkEffect> list = this.effects;
    if (list == null) {
        list = this.effects = new ArrayList<FireworkEffect>();
    }

    for (FireworkEffect effect : effects) {
        Validate.notNull(effect, "Effect cannot be null");
        list.add(effect);
    }
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:17,代碼來源:CraftMetaFirework.java

示例8: getAccessibleMethod

import org.apache.commons.lang.Validate; //導入依賴的package包/類
/**
 * 循環向上轉型, 獲取對象的DeclaredMethod,並強製設置為可訪問.
 * 如向上轉型到Object仍無法找到, 返回null.
 * 匹配函數名+參數類型。
 * <p>
 * 用於方法需要被多次調用的情況. 先使用本函數先取得Method,然後調用Method.invoke(Object obj, Object... args)
 */
public static Method getAccessibleMethod(final Object obj, final String methodName,
                                         final Class<?>... parameterTypes) {
    Validate.notNull(obj, "object can't be null");
    Validate.notEmpty(methodName, "methodName can't be blank");

    for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) {
        try {
            Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
            makeAccessible(method);
            return method;
        } catch (NoSuchMethodException e) {
            // Method不在當前類定義,繼續向上轉型
            continue;// new add
        }
    }
    return null;
}
 
開發者ID:guolf,項目名稱:pds,代碼行數:25,代碼來源:Reflections.java

示例9: removeCustomEffect

import org.apache.commons.lang.Validate; //導入依賴的package包/類
public boolean removeCustomEffect(PotionEffectType type) {
    Validate.notNull(type, "Potion effect type must not be null");

    if (!hasCustomEffects()) {
        return false;
    }

    boolean changed = false;
    Iterator<PotionEffect> iterator = customEffects.iterator();
    while (iterator.hasNext()) {
        PotionEffect effect = iterator.next();
        if (effect.getType() == type) {
            iterator.remove();
            changed = true;
        }
    }
    return changed;
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:19,代碼來源:CraftMetaPotion.java

示例10: addBan

import org.apache.commons.lang.Validate; //導入依賴的package包/類
@Override
public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) {
    Validate.notNull(target, "Ban target cannot be null");

    GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(target);
    if (profile == null) {
        return null;
    }

    UserListBansEntry entry = new UserListBansEntry(profile, new Date(),
            StringUtils.isBlank(source) ? null : source, expires,
            StringUtils.isBlank(reason) ? null : reason);

    list.func_152687_a(entry);

    try {
        list.func_152678_f();
    } catch (IOException ex) {
        MinecraftServer.getLogger().error("Failed to save banned-players.json, " + ex.getMessage());
    }

    return new CraftProfileBanEntry(profile, entry, list);
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:24,代碼來源:CraftProfileBanList.java

示例11: getPlayer

import org.apache.commons.lang.Validate; //導入依賴的package包/類
@Override
@Deprecated
public Player getPlayer(final String name) {
    Validate.notNull(name, "Name cannot be null");

    Player found = null;
    String lowerName = name.toLowerCase();
    int delta = Integer.MAX_VALUE;
    for (Player player : getOnlinePlayers()) {
        if (player.getName().toLowerCase().startsWith(lowerName)) {
            int curDelta = player.getName().length() - lowerName.length();
            if (curDelta < delta) {
                found = player;
                delta = curDelta;
            }
            if (curDelta == 0) break;
        }
    }
    return found;
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:21,代碼來源:CraftServer.java

示例12: matchPlayer

import org.apache.commons.lang.Validate; //導入依賴的package包/類
@Override
@Deprecated
public List<Player> matchPlayer(String partialName) {
    Validate.notNull(partialName, "PartialName cannot be null");

    List<Player> matchedPlayers = new ArrayList<Player>();

    for (Player iterPlayer : this.getOnlinePlayers()) {
        String iterPlayerName = iterPlayer.getName();

        if (partialName.equalsIgnoreCase(iterPlayerName)) {
            // Exact match
            matchedPlayers.clear();
            matchedPlayers.add(iterPlayer);
            break;
        }
        if (iterPlayerName.toLowerCase().contains(partialName.toLowerCase())) {
            // Partial match
            matchedPlayers.add(iterPlayer);
        }
    }

    return matchedPlayers;
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:25,代碼來源:CraftServer.java

示例13: dispatchCommand

import org.apache.commons.lang.Validate; //導入依賴的package包/類
@Override
public boolean dispatchCommand(CommandSender sender, String commandLine) {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(commandLine, "CommandLine cannot be null");

    if (commandMap.dispatch(sender, commandLine)) {
        return true;
    }

    // Cauldron start - handle vanilla commands called from plugins
    if(sender instanceof ConsoleCommandSender) {
        craftCommandMap.setVanillaConsoleSender(this.console);
    }
        
    return this.dispatchVanillaCommand(sender, commandLine);
    // Cauldron end
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:18,代碼來源:CraftServer.java

示例14: applyToBattle

import org.apache.commons.lang.Validate; //導入依賴的package包/類
/**
 * Apply this templates data to an EnderDragonBattle object
 * 
 * @param nmsAbstract an instance of the NMSAbstract interface
 * @param dragon the dragon to modify
 * @param battle the battle to modify
 */
public void applyToBattle(NMSAbstract nmsAbstract, EnderDragon dragon, DragonBattle battle) {
	Validate.notNull(nmsAbstract, "Instance of NMSAbstract cannot be null. See DragonEggDrop#getNMSAbstract()");
	Validate.notNull(dragon, "Ender Dragon cannot be null");
	Validate.notNull(battle, "Instance of DragonBattle cannot be null");
	
	if (name != null) {
		dragon.setCustomName(name);
		battle.setBossBarTitle(name);
	}
	
	battle.setBossBarStyle(barStyle, barColour);
	this.attributes.forEach((a, v) -> {
		AttributeInstance attribute = dragon.getAttribute(a);
		if (attribute != null) {
			attribute.setBaseValue(v);
		}
	});
	
	// Set health... max health attribute doesn't do that for me. -,-
	if (attributes.containsKey(Attribute.GENERIC_MAX_HEALTH)) {
		dragon.setHealth(attributes.get(Attribute.GENERIC_MAX_HEALTH));
	}
}
 
開發者ID:2008Choco,項目名稱:DragonEggDrop,代碼行數:31,代碼來源:DragonTemplate.java

示例15: HandlingEvent

import org.apache.commons.lang.Validate; //導入依賴的package包/類
/**
 * @param cargo            cargo
 * @param completionTime   completion time, the reported time that the event actually happened (e.g. the receive took place).
 * @param registrationTime registration time, the time the message is received
 * @param type             type of event
 * @param location         where the event took place
 */
public HandlingEvent(final Cargo cargo,
                     final Date completionTime,
                     final Date registrationTime,
                     final HandlingEventType type,
                     final Location location) {
    Validate.notNull(cargo, "Cargo is required");
    Validate.notNull(completionTime, "Completion time is required");
    Validate.notNull(registrationTime, "Registration time is required");
    Validate.notNull(type, "Handling event type is required");
    Validate.notNull(location, "Location is required");

    if (type.requiresVoyage()) {
        throw new IllegalArgumentException("Voyage is required for event type " + type);
    }

    this.completionTime = (Date) completionTime.clone();
    this.registrationTime = (Date) registrationTime.clone();
    this.type = type;
    this.location = location;
    this.cargo = cargo;
    this.voyage = null;
}
 
開發者ID:jboz,項目名稱:living-documentation,代碼行數:30,代碼來源:HandlingEvent.java


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