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


Java StringUtils.leftPad方法代碼示例

本文整理匯總了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;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:21,代碼來源:TableListing.java

示例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;
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:27,代碼來源:UserDtoValidatorTestData.java

示例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);
}
 
開發者ID:baidu,項目名稱:dlock,代碼行數:26,代碼來源:DistributedReentrantLockTest.java

示例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));
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:34,代碼來源:ConfigHelper.java

示例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());
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:47,代碼來源:NodeRefRadixHasher.java

示例6: paddedId

import org.apache.commons.lang.StringUtils; //導入方法依賴的package包/類
public String paddedId () {
	return StringUtils.rightPad( getServiceName(), 25 ) + " " + StringUtils.leftPad(getPort(),6);
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:4,代碼來源:ServiceBase.java

示例7: normalizePart

import org.apache.commons.lang.StringUtils; //導入方法依賴的package包/類
private static String normalizePart(String part) {
  return StringUtils.leftPad(part, 4, '0');
}
 
開發者ID:instalint-org,項目名稱:instalint,代碼行數:4,代碼來源:Version.java

示例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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:69,代碼來源:DurationFormatUtils.java

示例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');
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:7,代碼來源:ManagePathUtils.java

示例10: padLeft

import org.apache.commons.lang.StringUtils; //導入方法依賴的package包/類
public static String padLeft(String s, int n) {
  return StringUtils.leftPad(s, n);
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:4,代碼來源:OraOopUtilities.java

示例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);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:6,代碼來源:LCIndexConstant.java

示例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);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:6,代碼來源:LCIndexConstant.java

示例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);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:6,代碼來源:LCIndexConstant.java

示例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);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:6,代碼來源:LCIndexConstant.java

示例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);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:6,代碼來源:StripeCompactionsPerformanceEvaluation.java


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