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


Java Strings.padStart方法代碼示例

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


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

示例1: doFilter

import com.google.common.base.Strings; //導入方法依賴的package包/類
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
	// retrieve userId and set
	if (request instanceof HttpServletRequest) {
		Principal principal = ((HttpServletRequest) request).getUserPrincipal();
		if (principal != null) {
			String ppal = principal.getName();
			if (hashAlgorithm == null || "none".equalsIgnoreCase(hashAlgorithm)) {
				// no hash
			} else if ("hashcode".equalsIgnoreCase(hashAlgorithm)) {
				// simply hashcode
				ppal = Strings.padStart(Integer.toHexString(ppal.hashCode()), 8, '0');
			} else {
				// hexadecimal hash
				try {
					MessageDigest digest = MessageDigest.getInstance(hashAlgorithm);
					ppal = BaseEncoding.base16().encode(digest.digest(ppal.getBytes()));
				} catch (NoSuchAlgorithmException e) {
					throw new ServletException(e);
				}
			}
			// add to MDC and request attribute
			MDC.put(mdcName, ppal);
			request.setAttribute(attributeName, ppal);
		}
	}

	try {
		chain.doFilter(request, response);
	} finally {
		MDC.remove(mdcName);
	}
}
 
開發者ID:Orange-OpenSource,項目名稱:orange-mathoms-logging,代碼行數:33,代碼來源:PrincipalFilter.java

示例2: pad

import com.google.common.base.Strings; //導入方法依賴的package包/類
private static String pad(int padding) {
    return Strings.padStart("", padding * 4, ' ');
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:4,代碼來源:ModelTypeInitializationException.java

示例3: toUnicodeKeyword

import com.google.common.base.Strings; //導入方法依賴的package包/類
/**
 * Creates lexer rule for given keyword in order to handle JavaScript's unicode masks. E.g.:
 *
 * <pre>
 * If :
 * 	( 'i' | '\\' 'u' '0''0''6''9' )
 * 	( 'f' | '\\' 'u' '0''0''6''6' );
 * </pre>
 *
 * @param keyword
 *            the keyword as string, e.g. 'if'
 * @return the lexer body, e.g.
 *
 *         <pre>
 * ( 'i' | '\\' 'u' '0''0''6''9' ) ( 'f' | '\\' 'u' '0''0''6''6' )
 *         </pre>
 */
public static String toUnicodeKeyword(String keyword) {
	if (keyword.equals("async ")) {
		keyword = "async";
	}
	if (isIdentifier(keyword)) {
		StringBuilder result = new StringBuilder(keyword.length() * 30);
		for (char c : keyword.toCharArray()) {
			result.append("\n\t( '");
			result.append(c);
			result.append("' | '\\\\' 'u' ");
			String unicodeEscape = Strings.padStart(Integer.toHexString(c), 4, '0');
			for (char u : unicodeEscape.toCharArray()) {
				if ('0' <= u && u <= '9') {
					result.append("'");
					result.append(u);
					result.append("'");
				} else {
					result.append("( '");
					result.append(u);
					result.append("' | '");
					result.append(Character.toUpperCase(u));
					result.append("' )");
				}
			}
			result.append(" )");
		}
		return result.toString();
	}
	return "'" + AntlrGrammarGenUtil.toAntlrString(keyword) + "'";
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:48,代碼來源:UnicodeKeywordHelper.java

示例4: getRandomZeroPaddedNumber

import com.google.common.base.Strings; //導入方法依賴的package包/類
private static String getRandomZeroPaddedNumber(int min, int max, int length) {
    return Strings.padStart(
            String.format("%d", random.getRandomInteger(min, max)),
            length,
            '0'
    );
}
 
開發者ID:johan-backstrom,項目名稱:data-cow,代碼行數:8,代碼來源:DataHelper.java

示例5: asZeroPaddedHexString

import com.google.common.base.Strings; //導入方法依賴的package包/類
public String asZeroPaddedHexString(int expectedLength) {
    return Strings.padStart(asHexString(), expectedLength, '0');
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:4,代碼來源:HashValue.java

示例6: formatCell

import com.google.common.base.Strings; //導入方法依賴的package包/類
private static String formatCell(String value, int maxWidth) {
    return Strings.padStart(value, maxWidth + 1, ' ') + " ";
}
 
開發者ID:gchq,項目名稱:stroom-stats,代碼行數:4,代碼來源:QueryApiHelper.java

示例7: sendModuleSummary

import com.google.common.base.Strings; //導入方法依賴的package包/類
/**
 * Sends a module summary (similar to the Maven Reactor Summary)
 */
public void sendModuleSummary() {
    if(logger == null) return;
    List<String> summaryMessages = new ArrayList<>();

    summaryMessages.add(Strings.repeat("-", 75));
    summaryMessages.add("Module Summary: ");
    summaryMessages.add(" ");

    // for averages
    double successCount = 0;
    double totalTime = 0;

    for(Module m : getModules()) {
        String name = Strings.padEnd(m.getName() + " ", 25, '.');
        String state = (m.isEnabled() ? ConsoleColor.GREEN + "SUCCESS" : ConsoleColor.RED + "FAILURE") + ConsoleColor.RESET;
        double time = (double) m.getEnableTime() / 1000;

        // averages
        if(m.isEnabled()) successCount++;
        totalTime += time;

        String timeString = "[ " + Strings.padStart(StringUtil.applyDecimalLength(time, 3), 6, ' ') + " s]";
        String error = m.isEnabled() ? "" : " (" + (m.getErrorReason() != null ? m.getErrorReason().getClass().getSimpleName() : "Not Enabled") + ")";
        summaryMessages.add(name + " " + state + " " + timeString + error);
    }
    summaryMessages.add(" ");

    String totalTimeString = NumberUtil.round(totalTime, 4);
    summaryMessages.add("Total time: " + totalTimeString + "s");

    // success
    double successRate = successCount / getModules().size() * 100;
    String successRateString = (successRate <= 25 ? ConsoleColor.DARK_RED
            : successRate <= 50 ? ConsoleColor.RED
            : successRate <= 75 ? ConsoleColor.GOLD
            : successRate <= 99 ? ConsoleColor.YELLOW
            : ConsoleColor.GREEN
    ) + NumberUtil.round(successRate, 4) + "%" + ConsoleColor.RESET;

    // time and footer
    String averageTimeString = NumberUtil.round(totalTime / getModules().size(), 4);
    summaryMessages.add("Success rate: " + successRateString + " | Average time: " + averageTimeString + "s");
    summaryMessages.add(Strings.repeat("-", 75));

    // send all messages
    summaryMessages.forEach(s -> logger.info(s));
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:51,代碼來源:ModuleRegistry.java

示例8: padFloat

import com.google.common.base.Strings; //導入方法依賴的package包/類
private String padFloat(float f){
    String formatted = format.format(f);
    return Strings.padStart(formatted, 7, ' ');
}
 
開發者ID:DiceTechJobs,項目名稱:RelevancyFeedback,代碼行數:5,代碼來源:RFTerm.java

示例9: padInt

import com.google.common.base.Strings; //導入方法依賴的package包/類
private String padInt(float f){
    String formatted = intFormat.format(f);
    return Strings.padStart(formatted, 5, ' ');
}
 
開發者ID:DiceTechJobs,項目名稱:RelevancyFeedback,代碼行數:5,代碼來源:RFTerm.java

示例10: toHex

import com.google.common.base.Strings; //導入方法依賴的package包/類
/**
 * Converts a long value to hex string; 16 wide and sans 0x.
 *
 * @param value long value
 * @return hex string
 */
public static String toHex(long value) {
    return Strings.padStart(UnsignedLongs.toString(value, 16), 16, '0');
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:10,代碼來源:Tools.java


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