本文整理汇总了Java中org.apache.commons.lang.StringUtils.leftPad方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.leftPad方法的具体用法?Java StringUtils.leftPad怎么用?Java StringUtils.leftPad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.StringUtils
的用法示例。
在下文中一共展示了StringUtils.leftPad方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRow
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* Return the ith row of the column as a set of wrapped strings, each at
* most wrapWidth in length.
*/
String[] getRow(int idx) {
String raw = rows.get(idx);
// Line-wrap if it's too long
String[] lines = new String[] {raw};
if (wrap) {
lines = WordUtils.wrap(lines[0], wrapWidth, "\n", true).split("\n");
}
for (int i=0; i<lines.length; i++) {
if (justification == Justification.LEFT) {
lines[i] = StringUtils.rightPad(lines[i], maxWidth);
} else if (justification == Justification.RIGHT) {
lines[i] = StringUtils.leftPad(lines[i], maxWidth);
}
}
return lines;
}
示例2: getInvalidEmailTestData
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
static List<Object[]> getInvalidEmailTestData() {
String[] invalidEmails = new String[]{"email",
"email.com",
"[email protected]@email.com",
"email_mail",
"@email.com",
"[email protected]",
"email.email",
"email [email protected]",
StringUtils.leftPad("[email protected]", 156, "e")};
List<Object[]> result = new ArrayList<Object[]>();
String invalidEmaielMessage = "Email: {0} has invalid format.";
for(String invalidEmail : invalidEmails) {
UserDto user = createUserDto();
user.setEmail(invalidEmail);
String errorMessage = invalidEmail.length() > 155 ?
"Email " + INVALID_FIELD_LENGTH_ERROR_MESSAGE :
MessageFormat.format(invalidEmaielMessage, invalidEmail);
result.add(new Object[] {user, errorMessage});
}
return result;
}
示例3: launchSingleServer
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* Launch threads on a single server
*
* @param totalThread
* @param serverName
* @param lock
* @param maxWorkElapsed
*/
private static void launchSingleServer(int totalThread, String serverName, Lock lock, int maxWorkElapsed) {
List<Thread> threads = new ArrayList<>(totalThread);
for (int i = 0; i < totalThread; i++) {
String tName = serverName + "-t" + StringUtils.leftPad(i + "", 2, "0");
threads.add(i, new RedisTestThread(tName, lock, maxWorkElapsed));
}
threads.forEach(t -> t.start());
threads.forEach(t -> {
try {
t.join();
} catch (InterruptedException e) {
}
});
System.out.println("**** All Done **** " + serverName);
}
示例4: parseMode
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* 解析DataMedia中的namespace和name,支持offer[1-128]分库的定义
*/
public static ModeValue parseMode(String value) {
PatternMatcher matcher = new Perl5Matcher();
if (matcher.matches(value, patterns.get(MODE_PATTERN))) {
MatchResult matchResult = matcher.getMatch();
String prefix = matchResult.group(1);
String startStr = matchResult.group(3);
String ednStr = matchResult.group(4);
int start = Integer.valueOf(startStr);
int end = Integer.valueOf(ednStr);
String postfix = matchResult.group(5);
List<String> values = new ArrayList<String>();
for (int i = start; i <= end; i++) {
StringBuilder builder = new StringBuilder(value.length());
String str = String.valueOf(i);
// 处理0001类型
if (startStr.length() == ednStr.length() && startStr.startsWith("0")) {
str = StringUtils.leftPad(String.valueOf(i), startStr.length(), '0');
}
builder.append(prefix).append(str).append(postfix);
values.add(builder.toString());
}
return new ModeValue(Mode.MULTI, values);
} else if (isWildCard(value)) {// 通配符支持
return new ModeValue(Mode.WILDCARD, Arrays.asList(value));
} else {
return new ModeValue(Mode.SINGLE, Arrays.asList(value));
}
}
示例5: lookup
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
@Override
public NodeRef lookup(Pair<String, String> hash)
{
String storeHash = hash.getFirst();
String storeProtocolHash = storeHash.substring(0,
1);
String storeIdHash = storeHash.substring(1,
2);
String storeProtocol = storeProtocolStore.lookup(storeProtocolHash);
String storeId = storeIdStore.lookup(storeIdHash);
if (storeProtocol == null || storeId == null)
{
throw new RuntimeException("Lookup found no protocol or id for " + storeHash);
}
BigInteger nodeId = new BigInteger(hash.getSecond(),
radix);
String nodeIdHexa = nodeId.toString(16);
nodeIdHexa = StringUtils.leftPad(nodeIdHexa,
32,
"0");
int leadZeros = 32 - nodeIdHexa.length();
if (leadZeros > 0)
{
}
String groups[] = new String[5];
groups[0] = nodeIdHexa.substring(0,
8);
groups[1] = nodeIdHexa.substring(8,
12);
groups[2] = nodeIdHexa.substring(12,
16);
groups[3] = nodeIdHexa.substring(16,
20);
groups[4] = nodeIdHexa.substring(20,
32);
StringBuilder idBuilder = new StringBuilder(groups[0]);
for (int i = 1; i < groups.length; i++)
{
idBuilder.append("-");
idBuilder.append(groups[i]);
}
return new NodeRef(storeProtocol,
storeId,
idBuilder.toString());
}
示例6: paddedId
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public String paddedId () {
return StringUtils.rightPad( getServiceName(), 25 ) + " " + StringUtils.leftPad(getPort(),6);
}
示例7: normalizePart
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private static String normalizePart(String part) {
return StringUtils.leftPad(part, 4, '0');
}
示例8: format
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* <p>The internal method to do the formatting.</p>
*
* @param tokens the tokens
* @param years the number of years
* @param months the number of months
* @param days the number of days
* @param hours the number of hours
* @param minutes the number of minutes
* @param seconds the number of seconds
* @param milliseconds the number of millis
* @param padWithZeros whether to pad
* @return the formatted string
*/
static String format(Token[] tokens, int years, int months, int days, int hours, int minutes, int seconds,
int milliseconds, boolean padWithZeros) {
StrBuilder buffer = new StrBuilder();
boolean lastOutputSeconds = false;
int sz = tokens.length;
for (int i = 0; i < sz; i++) {
Token token = tokens[i];
Object value = token.getValue();
int count = token.getCount();
if (value instanceof StringBuffer) {
buffer.append(value.toString());
} else {
if (value == y) {
buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(years), count, '0') : Integer
.toString(years));
lastOutputSeconds = false;
} else if (value == M) {
buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(months), count, '0') : Integer
.toString(months));
lastOutputSeconds = false;
} else if (value == d) {
buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(days), count, '0') : Integer
.toString(days));
lastOutputSeconds = false;
} else if (value == H) {
buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(hours), count, '0') : Integer
.toString(hours));
lastOutputSeconds = false;
} else if (value == m) {
buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(minutes), count, '0') : Integer
.toString(minutes));
lastOutputSeconds = false;
} else if (value == s) {
buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(seconds), count, '0') : Integer
.toString(seconds));
lastOutputSeconds = true;
} else if (value == S) {
if (lastOutputSeconds) {
milliseconds += 1000;
String str = padWithZeros
? StringUtils.leftPad(Integer.toString(milliseconds), count, '0')
: Integer.toString(milliseconds);
buffer.append(str.substring(1));
} else {
buffer.append(padWithZeros
? StringUtils.leftPad(Integer.toString(milliseconds), count, '0')
: Integer.toString(milliseconds));
}
lastOutputSeconds = false;
}
}
}
return buffer.toString();
}
示例9: getProcessNode
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
* 将processId转化为zookeeper中的node名称
*/
public static String getProcessNode(Long processId) {
return StringUtils.leftPad(String.valueOf(processId.intValue()), 10, '0');
}
示例10: padLeft
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String padLeft(String s, int n) {
return StringUtils.leftPad(s, n);
}
示例11: paddedStringInt
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String paddedStringInt(int i) {
return StringUtils
.leftPad(String.format(FORMAT_INT_STR, i), LCCINDEX_PREFIX_ROWKEY_LENGTH, FORMAT_ZERO_STR);
// return String.valueOf(i);
}
示例12: paddedStringLong
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String paddedStringLong(long d) {
return StringUtils
.leftPad(String.format(FORMAT_INT_STR, d), LCCINDEX_PREFIX_ROWKEY_LENGTH, FORMAT_ZERO_STR);
// return String.valueOf(d);
}
示例13: paddedStringShort
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String paddedStringShort(short d) {
return StringUtils
.leftPad(String.format(FORMAT_INT_STR, d), LCCINDEX_PREFIX_ROWKEY_LENGTH, FORMAT_ZERO_STR);
// return String.valueOf(b);
}
示例14: paddedStringDouble
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String paddedStringDouble(double d) {
return StringUtils.leftPad(String.format(FORMAT_DOUBLE_STR, d), LCCINDEX_PREFIX_ROWKEY_LENGTH,
FORMAT_ZERO_STR);
// return String.valueOf(d);
}
示例15: getDeterministicUniqueKey
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
@Override
public byte[] getDeterministicUniqueKey(long keyBase) {
String num = StringUtils.leftPad(String.valueOf(keyBase), PAD_TO, "0");
return Bytes.toBytes(getPrefix(keyBase) + num);
}