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

The following are Jave code examples for showing how to use leftPad() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: eds   File: RequestIdManager.java   View Source Code Vote up 5 votes
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');
  }
}
 
Example 2
Project: GitHub   File: AbstractCodeWriter.java   View Source Code Vote up 5 votes
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);
}
 
Example 3
Project: NoMoreOversleeps   File: CustomEvent.java   View Source Code Vote up 5 votes
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;
}
 
Example 4
Project: sentry   File: DateAndTimeUtils.java   View Source Code Vote up 5 votes
/**
 * @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);
}
 
Example 5
Project: sharding-quickstart   File: TablesNamesFinder.java   View Source Code Vote up 5 votes
@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);
}
 
Example 6
Project: mumu   File: IPAddressUtil.java   View Source Code Vote up 5 votes
/**
 * 将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();
}
 
Example 7
Project: mumu   File: IPAddressUtil.java   View Source Code Vote up 5 votes
/**
 * 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();
}
 
Example 8
Project: Biliomi   File: TimeFormatter.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 9
Project: cloud-s4-sdk-examples   File: CostCenterServiceIntegrationTest.java   View Source Code Vote up 5 votes
private static String generateId() {
    return "T"
            + StringUtils.leftPad(
            Long.toString(new DateTime().minus(Period.years(45)).getMillis(), 36).toUpperCase(),
            9,
            '0');
}
 
Example 10
Project: vkmusic   File: AudioTableModel.java   View Source Code Vote up 5 votes
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');
}
 
Example 11
Project: hockey-game   File: ApplicationStartup.java   View Source Code Vote up 5 votes
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;
	}
 
Example 12
Project: OperatieBRP   File: DatumFormatterUtil.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 13
Project: hue   File: CommonUtils.java   View Source Code Vote up 4 votes
private static String generateMask(int length) {
	return StringUtils.leftPad("", length, "*");
}
 
Example 14
Project: NoMoreOversleeps   File: SleepEntry.java   View Source Code Vote up 4 votes
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");
}
 
Example 15
Project: rskj   File: TestUtils.java   View Source Code Vote up 4 votes
public static String padZeroesLeft(String s, int n) {
    return StringUtils.leftPad(s, n, '0');
}
 
Example 16
Project: featurea   File: StreamUtils.java   View Source Code Vote up 4 votes
public static String toHex(long l) {
    return StringUtils.leftPad(Long.toHexString(l), 16, '0');
}
 
Example 17
Project: featurea   File: StreamUtils.java   View Source Code Vote up 4 votes
public static String toHex(byte b) {
    return StringUtils.leftPad(Integer.toHexString(b & 0xff), 2, '0');
}
 
Example 18
Project: strqlbuilder   File: Aliases.java   View Source Code Vote up 4 votes
private String nextIndexSuffix(int i) {
return StringUtils.leftPad(i + "", 2, '0');
   }
 
Example 19
Project: OperatieBRP   File: BerichtStamgegevenWriter.java   View Source Code Vote up 4 votes
private static String stringNaarStringMetVoorloopnullen(final String string, final int stringLengte) {
    return StringUtils.leftPad(string, stringLengte, BerichtConstants.PADDING_WAARDE_0);
}
 
Example 20
Project: featurea   File: StreamUtils.java   View Source Code Vote up 4 votes
public static String toHex(int i) {
    return StringUtils.leftPad(Integer.toHexString(i), 8, '0');
}