Java Code Examples for org.apache.commons.lang.StringUtils.leftPad()

The following are Jave code examples for showing how to use leftPad() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hadoop-oss   File: TableListing.java   Source Code and License Vote up 7 votes
/**
 * 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;
}
 
Example 2
Project: hadoop   File: TableListing.java   Source Code and License Vote up 7 votes
/**
 * 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;
}
 
Example 3
Project: osc-core   File: UserDtoValidatorTestData.java   Source Code and License Vote up 6 votes
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;
}
 
Example 4
Project: dlock   File: DistributedReentrantLockTest.java   Source Code and License Vote up 6 votes
/**
 * 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);
}
 
Example 5
Project: otter-G   File: ConfigHelper.java   Source Code and License Vote up 5 votes
/**
 * 解析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));
    }
}
 
Example 6
Project: alfresco-repository   File: NodeRefRadixHasher.java   Source Code and License Vote up 4 votes
@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());
}
 
Example 7
Project: csap-core   File: ServiceBase.java   Source Code and License Vote up 4 votes
public String paddedId () {
	return StringUtils.rightPad( getServiceName(), 25 ) + " " + StringUtils.leftPad(getPort(),6);
}
 
Example 8
Project: instalint   File: Version.java   Source Code and License Vote up 4 votes
private static String normalizePart(String part) {
  return StringUtils.leftPad(part, 4, '0');
}
 
Example 9
Project: lams   File: DurationFormatUtils.java   Source Code and License Vote up 4 votes
/**
 * <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();
}
 
Example 10
Project: otter-G   File: ManagePathUtils.java   Source Code and License Vote up 4 votes
/**
 * 将processId转化为zookeeper中的node名称
 */
public static String getProcessNode(Long processId) {
    return StringUtils.leftPad(String.valueOf(processId.intValue()), 10, '0');
}
 
Example 11
Project: aliyun-maxcompute-data-collectors   File: OraOopUtilities.java   Source Code and License Vote up 4 votes
public static String padLeft(String s, int n) {
  return StringUtils.leftPad(s, n);
}
 
Example 12
Project: ditb   File: LCIndexConstant.java   Source Code and License Vote up 4 votes
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);
}
 
Example 13
Project: ditb   File: LCIndexConstant.java   Source Code and License Vote up 4 votes
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);
}
 
Example 14
Project: ditb   File: LCIndexConstant.java   Source Code and License Vote up 4 votes
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);
}
 
Example 15
Project: ditb   File: LCIndexConstant.java   Source Code and License Vote up 4 votes
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);
}
 
Example 16
Project: ditb   File: StripeCompactionsPerformanceEvaluation.java   Source Code and License Vote up 4 votes
@Override
public byte[] getDeterministicUniqueKey(long keyBase) {
  String num = StringUtils.leftPad(String.valueOf(keyBase), PAD_TO, "0");
  return Bytes.toBytes(getPrefix(keyBase) + num);
}
 
Example 17
Project: ditb   File: StripeCompactionsPerformanceEvaluation.java   Source Code and License Vote up 4 votes
private String getPrefix(long i) {
  return StringUtils.leftPad(String.valueOf((int)(i % numPartitions)), PREFIX_PAD_TO, "0");
}
 
Example 18
Project: ditb   File: RegionSplitter.java   Source Code and License Vote up 2 votes
/**
 * Returns the bytes corresponding to the BigInteger
 *
 * @param bigInteger number to convert
 * @param pad padding length
 * @return byte corresponding to input BigInteger
 */
public static byte[] convertToByte(BigInteger bigInteger, int pad) {
  String bigIntegerString = bigInteger.toString(16);
  bigIntegerString = StringUtils.leftPad(bigIntegerString, pad, '0');
  return Bytes.toBytes(bigIntegerString);
}