本文整理汇总了Java中org.apache.commons.lang3.StringUtils.leftPad方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.leftPad方法的具体用法?Java StringUtils.leftPad怎么用?Java StringUtils.leftPad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.StringUtils
的用法示例。
在下文中一共展示了StringUtils.leftPad方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RequestIdManager
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public RequestIdManager(String serviceId) {
if (serviceId == null) {
serviceIdTag = "9999";
}
if (serviceId.length() > SERVICE_ID_TAG_LENGTH) {
serviceIdTag = StringUtils
.substring(serviceId, serviceId.length() - SERVICE_ID_TAG_LENGTH, serviceId.length() - 1);
} else {
serviceIdTag = StringUtils.leftPad(serviceId, SERVICE_ID_TAG_LENGTH, '0');
}
}
示例2: AbstractCodeWriter
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public AbstractCodeWriter(Appendable appendable, int spaces){
if (appendable == null){
throw new IllegalArgumentException("appendable is null");
}
this.appendable = appendable;
this.spaces = spaces;
this.spacesString = StringUtils.leftPad("", spaces);
}
示例3: describe
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public String describe()
{
if (this.days.size() == 0 || this.times.length == 0)
{
return "NEVER";
}
String description = "";
String s = "";
if (this.days.size() == 7)
{
s = "DAILY";
}
else
{
for (Weekday weekday : this.days)
{
s += (s.isEmpty() ? "" : ", ") + weekday.name();
}
}
description = s;
s = "";
for (int time : this.times)
{
int hour = time / 60;
int minute = time % 60;
s += (s.isEmpty() ? "" : ", ") + StringUtils.leftPad("" + hour, 2, "0") + ":" + StringUtils.leftPad("" + minute, 2, "0");
}
description += " at " + s;
return description;
}
示例4: formatTime
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* @param hoursExpression
* @param minutesExpression
* @param secondsExpression
* @return
*/
public static String formatTime(String hoursExpression, String minutesExpression, String secondsExpression) {
int hour = Integer.parseInt(hoursExpression);
String amPM = hour >= 12 ? I18nMessages.get("time_pm") : I18nMessages.get("time_am");
if (hour > 12) {
hour -= 12;
}
String minute = String.valueOf(Integer.parseInt(minutesExpression));
String second = "";
if (!StringUtils.isEmpty(secondsExpression)) {
second = ":" + StringUtils.leftPad(String.valueOf(Integer.parseInt(secondsExpression)), 2, '0');
}
return MessageFormat.format("{0}:{1}{2} {3}", String.valueOf(hour), StringUtils.leftPad(minute, 2, '0'), second, amPM);
}
示例5: visit
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public void visit(Table table) {
String tableWholeName = table.getName();
String tableOrginName = table.getName();
String index = String.valueOf(MVEL.eval(this.expression, this.param));
String suffix = StringUtils.leftPad(index, 4, "0");
table.setName(tableOrginName + AbstractTableRouter.TABLE_NAME_SLIPTOR + suffix);
tables.add(tableWholeName);
}
示例6: toBinaryString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* 将ip地址转换为二进制字符串
* @param ip 255.255.255.255
* @return
*/
public static final String toBinaryString(String ip) {
if (ip == null || "".equals(ip)) {
return null;
}
String[] ipAddress = StringUtils.split(ip, ".");
StringBuilder builder = new StringBuilder();
for (String ipAdd : ipAddress) {
String binaryString = Integer.toBinaryString(Integer.parseInt(ipAdd));
binaryString = StringUtils.leftPad(binaryString, 8, "0");
builder.append(binaryString);
}
return builder.toString();
}
示例7: transformLongToIpAddress
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* int数字转换为ip地址
* @param ip ip地址
* @return
*/
public static final String transformLongToIpAddress(int intIpAddress){
String binaryString = Integer.toBinaryString(intIpAddress);
binaryString = StringUtils.leftPad(binaryString, 32, "0");
StringBuilder ipAddress=new StringBuilder();
for (int i = 0; i < 4; i++) {
String substring = binaryString.substring(i*8, (i+1)*8);
ipAddress.append(toLong(substring));
if(i<3){
ipAddress.append(".");
}
}
return ipAddress.toString();
}
示例8: digitalClockQuantity
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Format a duration in milliseconds to a digital clock string
*
* @param millis The amount of millis
* @return A string: [hours:]minutes:seconds
*/
public String digitalClockQuantity(long millis) {
Duration duration = new Duration(millis);
Function<Long, String> pad = l -> StringUtils.leftPad(String.valueOf(l), 2, "0");
long hours = duration.getStandardHours();
long minutes = duration.getStandardMinutes() - (hours * 60);
long seconds = duration.getStandardSeconds() - (minutes * 60 + hours * 3600);
if (hours > 0) {
return pad.apply(hours) + ':' + pad.apply(minutes) + ':' + pad.apply(seconds);
}
return pad.apply(minutes) + ':' + pad.apply(seconds);
}
示例9: generateId
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private static String generateId() {
return "T"
+ StringUtils.leftPad(
Long.toString(new DateTime().minus(Period.years(45)).getMillis(), 36).toUpperCase(),
9,
'0');
}
示例10: getDuration
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private String getDuration(int durationInSec) {
int minutes = durationInSec / 60;
int seconds = durationInSec % 60;
String minutesStr = String.valueOf(minutes);
String secondsStr = String.valueOf(seconds);
return StringUtils.leftPad(minutesStr, 2, '0') + ":" + StringUtils.leftPad(secondsStr, 2, '0');
}
示例11: saveSeats
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private Seat saveSeats(int i) {
String credentials = StringUtils.leftPad(String.valueOf(i), 3, "0");
Seat seat = new Seat(credentials, credentials);
// if (i % 2 == 0) {
// s.setFanName("Fan n" + credentials);
// }
// generate random points ranging from 1 to max
// s.setPoints(n.nextInt(max - 1 + 1) + 1);
seat = seatRepository.save(seat);
return seat;
}
示例12: deelsOnbekendeDatumAlsGetalNaarString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Zet een getals representatie van een deels onbekende datum (formaat = yyyy-MM-dd) om naar een tekstuele representatie die dezelfde datum representeert.
* @param datum getalsrepresentatie van een deels onbekende datum
* @return tekstuele representatie van een deels onbekende datum, null indien tekstuele representatie (1) null is, (2) leeg is of (3) een invalide
* formaat heeft
*/
public static String deelsOnbekendeDatumAlsGetalNaarString(final Integer datum) {
final String datumAlsString = String.valueOf(datum);
if (datum != null) {
final boolean lengteValide = datum == 0 || datumAlsString.length() >= LENGTE_JAAR+1 && datumAlsString.length() <= LENGTE_DATUM;
if (lengteValide) {
final StringBuilder deelsOnbekendeDatum = new StringBuilder(StringUtils.leftPad(datumAlsString, LENGTE_DATUM, NUL_ALS_STRING));
deelsOnbekendeDatum.insert(LENGTE_JAAR + LENGTE_MAAND, "-").insert(LENGTE_JAAR, "-");
if (new DeelsOnbekendeDatum(deelsOnbekendeDatum.toString()).isGeldig()) {
return deelsOnbekendeDatum.toString();
}
}
}
return null;
}
示例13: generateMask
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private static String generateMask(int length) {
return StringUtils.leftPad("", length, "*");
}
示例14: describeTime
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public String describeTime()
{
return StringUtils.leftPad("" + (this.start / 60), 2, "0") + ":" + StringUtils.leftPad("" + (this.start % 60), 2, "0") + " - " + StringUtils.leftPad("" + (this.end / 60), 2, "0") + ":" + StringUtils.leftPad("" + (this.end % 60), 2, "0");
}
示例15: padZeroesLeft
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String padZeroesLeft(String s, int n) {
return StringUtils.leftPad(s, n, '0');
}