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


Java StringUtils.normalizeSpace方法代碼示例

本文整理匯總了Java中org.apache.commons.lang3.StringUtils.normalizeSpace方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.normalizeSpace方法的具體用法?Java StringUtils.normalizeSpace怎麽用?Java StringUtils.normalizeSpace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang3.StringUtils的用法示例。


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

示例1: makeErrorMessage

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
private String makeErrorMessage(DeferredElementImpl testCaseElem) {
    try {
        Node failureNode = getNodeByTagName(testCaseElem.getChildNodes(), "failure");
        Node messageNode = getNodeByTagName(failureNode.getChildNodes(), "message");
        Node stackTraceNode = getNodeByTagName(failureNode.getChildNodes(), "stack-trace");

        return "Error message: " + StringUtils.normalizeSpace(messageNode.getTextContent()) + " Stack trace: " + StringUtils.normalizeSpace(stackTraceNode.getTextContent());
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:DonutReport,項目名稱:donut-nunit-adapter,代碼行數:12,代碼來源:NUnitAdapter.java

示例2: readFile

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
@Override
public String readFile(final String fileName) {
    try {
        return StringUtils.normalizeSpace(
                IOUtils.toString(
                        this.getClass().getClassLoader().getResourceAsStream(fileName)));
    }
    catch (IOException e) {
        LOGGER.error("File could not be loaded from resource: {}", e.getMessage());
    }
    return null;
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:13,代碼來源:FileReaderServiceImpl.java

示例3: normalizeString

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
public static String normalizeString(String input) {
	// Contain only ASCII letters, digits, or underscore characters (_).
	// Begin with an alphabetic character or underscore character.
	// Subsequent characters may include letters, digits, underscores.
	// Be between 1 and 127 characters in length, not including quotes for
	// delimited identifiers.
	// Contain no quotation marks and no spaces.
	StringBuffer sb = new StringBuffer();
	// To lowercase and remove all extra whitespaces.
	input = StringUtils.normalizeSpace(input.toLowerCase());
	for (char c : input.toCharArray()) {
		if (VALID_CHARS.contains(String.valueOf(c))) {
			if (sb.length() == 0 && INVALID_FIRST_CHARS.contains(String.valueOf(c))) {
				sb.append(REPLACEMENT_CHAR);
			}
			else {
				sb.append(c);
			}
		}
		else {
			sb.append(REPLACEMENT_CHAR);
		}
	}

	String normalizedName = sb.toString();
	// Remove leading and trailing underscore and multiple underscores
	normalizedName = StringUtils.replacePattern(normalizedName, "_{2,}", REPLACEMENT_CHAR);
	normalizedName = StringUtils.strip(normalizedName, REPLACEMENT_CHAR);

	return normalizedName.length() > 127 ? normalizedName.substring(0, 127) : normalizedName;
}
 
開發者ID:ajoabraham,項目名稱:hue,代碼行數:32,代碼來源:CommonUtils.java

示例4: getSmartContract

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
private String getSmartContract(final String contract) {
    try {
        return StringUtils.normalizeSpace(
                IOUtils.toString(
                        this.getClass().getClassLoader().getResourceAsStream(contract)));
    }
    catch (IOException e) {
        LOGGER.error("Failed to serialize contract", e);
    }
    return null;
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:12,代碼來源:SmartContractTest.java

示例5: processChatMessage

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(C01PacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]);
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        this.sendPacket(new S02PacketChat(chatcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            IChatComponent ichatcomponent = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
            this.serverController.getConfigurationManager().sendChatMsgImpl(ichatcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:47,代碼來源:NetHandlerPlayServer.java

示例6: processChatMessage

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(CPacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("chat.cannotSend", new Object[0]);
        textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
        this.sendPacket(new SPacketChat(textcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            ITextComponent itextcomponent = new TextComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
            this.serverController.getPlayerList().sendChatMsgImpl(itextcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getPlayerList().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
開發者ID:NSExceptional,項目名稱:Zombe-Modpack,代碼行數:47,代碼來源:NetHandlerPlayServer.java

示例7: processChatMessage

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
/**
 * Process chat messages (broadcast back to clients) and commands (executes)
 */
public void processChatMessage(CPacketChatMessage packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
    {
        TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("chat.cannotSend", new Object[0]);
        textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
        this.sendPacket(new SPacketChat(textcomponenttranslation));
    }
    else
    {
        this.playerEntity.markPlayerActive();
        String s = packetIn.getMessage();
        s = StringUtils.normalizeSpace(s);

        for (int i = 0; i < s.length(); ++i)
        {
            if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
            {
                this.kickPlayerFromServer("Illegal characters in chat");
                return;
            }
        }

        if (s.startsWith("/"))
        {
            this.handleSlashCommand(s);
        }
        else
        {
            ITextComponent itextcomponent = new TextComponentTranslation("chat.type.text", this.playerEntity.getDisplayName(), net.minecraftforge.common.ForgeHooks.newChatWithLinks(s));
            itextcomponent = net.minecraftforge.common.ForgeHooks.onServerChatEvent(this, s, itextcomponent);
            if (itextcomponent == null) return;
            this.serverController.getPlayerList().sendChatMsgImpl(itextcomponent, false);
        }

        this.chatSpamThresholdCount += 20;

        if (this.chatSpamThresholdCount > 200 && !this.serverController.getPlayerList().canSendCommands(this.playerEntity.getGameProfile()))
        {
            this.kickPlayerFromServer("disconnect.spam");
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:49,代碼來源:NetHandlerPlayServer.java


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