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