当前位置: 首页>>代码示例>>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;未经允许,请勿转载。