List of usage examples for org.apache.commons.lang3 StringUtils leftPad
public static String leftPad(final String str, final int size, String padStr)
Left pad a String with a specified String.
Pad to a size of size .
StringUtils.leftPad(null, *, *) = null StringUtils.leftPad("", 3, "z") = "zzz" StringUtils.leftPad("bat", 3, "yz") = "bat" StringUtils.leftPad("bat", 5, "yz") = "yzbat" StringUtils.leftPad("bat", 8, "yz") = "yzyzybat" StringUtils.leftPad("bat", 1, "yz") = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null) = " bat" StringUtils.leftPad("bat", 5, "") = " bat"
From source file:com.qtplaf.library.util.NumberUtils.java
/** * Converts a byte to an HEX string of two bytes (FF). * /* ww w. j a v a2 s. c o m*/ * @param b The byte to convert. * @return The HEX string. */ public static String toHexString(byte b) { return StringUtils.leftPad(Integer.toHexString(b & 0xff).toUpperCase(), 2, "0"); }
From source file:com.github.robozonky.strategy.natural.conditions.LongStoryConditionTest.java
@Test void longerOk() { final Wrapper<?> l = mock(Wrapper.class); final String story = StringUtils.leftPad("", AbstractStoryCondition.LONG_STORY_THRESHOLD + 1, '*'); when(l.getStory()).thenReturn(story); assertThat(new LongStoryCondition().test(l)).isTrue(); }
From source file:com.github.robozonky.strategy.natural.conditions.ShortStoryConditionTest.java
@Test void longerNotOk() { final Wrapper<?> l = mock(Wrapper.class); final String story = StringUtils.leftPad("", AbstractStoryCondition.SHORT_STORY_THRESHOLD + 1, '*'); when(l.getStory()).thenReturn(story); assertThat(new ShortStoryCondition().test(l)).isFalse(); }
From source file:com.github.robozonky.strategy.natural.conditions.VeryShortStoryConditionTest.java
@Test void longerNotOk() { final Wrapper<?> l = mock(Wrapper.class); final String story = StringUtils.leftPad("", AbstractStoryCondition.VERY_SHORT_STORY_THRESHOLD, '*'); when(l.getStory()).thenReturn(story); assertThat(new VeryShortStoryCondition().test(l)).isFalse(); }
From source file:egovframework.com.utl.wed.filter.DirectoryPathManager.java
/** * 2012/12/22/// w w w .j a v a 2s.c om * @param dateType * @return * @throws InvalidArgumentException */ public static String getDirectoryPathByDateType(DIR_DATE_TYPE policy) { Calendar calendar = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); sb.append(calendar.get(Calendar.YEAR)).append(File.separator); if (policy.ordinal() <= DIR_DATE_TYPE.DATE_POLICY_YYYY_MM.ordinal()) { sb.append(StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH)), 2, '0')) .append(File.separator); } if (policy.ordinal() <= DIR_DATE_TYPE.DATE_POLICY_YYYY_MM_DD.ordinal()) { sb.append(StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)), 2, '0')) .append(File.separator); } return sb.toString(); }
From source file:com.github.robozonky.strategy.natural.conditions.AverageStoryConditionTest.java
@Test void longerNotOk() { final Wrapper<?> l = mock(Wrapper.class); final String story = StringUtils.leftPad("", AbstractStoryCondition.LONG_STORY_THRESHOLD + 1, '*'); when(l.getStory()).thenReturn(story); assertThat(new AverageStoryCondition().test(l)).isFalse(); }
From source file:com.github.devnied.emvnfccard.iso7816emv.EmvTerminal.java
/** * Method used to construct value from tag and length * * @param pTagAndLength/* ww w. java2 s . com*/ * tag and length value * @return tag value in byte */ public static byte[] constructValue(final TagAndLength pTagAndLength) { byte ret[] = new byte[pTagAndLength.getLength()]; byte val[] = null; if (pTagAndLength.getTag() == EmvTags.TERMINAL_TRANSACTION_QUALIFIERS) { TerminalTransactionQualifiers terminalQual = new TerminalTransactionQualifiers(); terminalQual.setContactlessEMVmodeSupported(true); terminalQual.setReaderIsOfflineOnly(true); val = terminalQual.getBytes(); } else if (pTagAndLength.getTag() == EmvTags.TERMINAL_COUNTRY_CODE) { val = BytesUtils.fromString(StringUtils.leftPad(String.valueOf(CountryCodeEnum.FR.getNumeric()), pTagAndLength.getLength() * 2, "0")); } else if (pTagAndLength.getTag() == EmvTags.TRANSACTION_CURRENCY_CODE) { val = BytesUtils.fromString(StringUtils.leftPad(String.valueOf(CurrencyEnum.EUR.getISOCodeNumeric()), pTagAndLength.getLength() * 2, "0")); } else if (pTagAndLength.getTag() == EmvTags.TRANSACTION_DATE) { SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd"); val = BytesUtils.fromString(sdf.format(new Date())); } else if (pTagAndLength.getTag() == EmvTags.TRANSACTION_TYPE) { val = new byte[] { (byte) TransactionTypeEnum.PURCHASE.getKey() }; } else if (pTagAndLength.getTag() == EmvTags.AMOUNT_AUTHORISED_NUMERIC) { val = BytesUtils.fromString("00"); } else if (pTagAndLength.getTag() == EmvTags.TERMINAL_TYPE) { val = new byte[] { 0x22 }; } else if (pTagAndLength.getTag() == EmvTags.TERMINAL_CAPABILITIES) { val = new byte[] { (byte) 0xE0, (byte) 0xA0, 0x00 }; } else if (pTagAndLength.getTag() == EmvTags.ADDITIONAL_TERMINAL_CAPABILITIES) { val = new byte[] { (byte) 0x8e, (byte) 0, (byte) 0xb0, 0x50, 0x05 }; } else if (pTagAndLength.getTag() == EmvTags.DS_REQUESTED_OPERATOR_ID) { val = BytesUtils.fromString("7345123215904501"); } else if (pTagAndLength.getTag() == EmvTags.UNPREDICTABLE_NUMBER) { random.nextBytes(ret); } if (val != null) { System.arraycopy(val, 0, ret, 0, Math.min(val.length, ret.length)); } return ret; }
From source file:com.daraf.projectdarafprotocol.appdb.ingresos.IngresoFacturaRQ.java
public void setTotal(String total) { this.total = StringUtils.leftPad(total, 10, "0"); }
From source file:de.wbuecke.codec.HexInput.java
@Override public String encode(String plaintext) { byte[] bytes = encodeBinary(plaintext); if (bytes == null) return null; StringBuilder hex = new StringBuilder(); for (int pos = 0; pos < bytes.length; pos++) hex.append(StringUtils.leftPad(Integer.toHexString(0x000000FF & bytes[pos]).toUpperCase(), 2, "0")); return hex.toString(); }
From source file:ec.edu.espe.distribuidas.facturacion.socket.estrucMsj.ValidadorFormato.java
public static String completarEntero(String numero, int longitud) { String numeroTxt = numero + ""; String enteroTxt = StringUtils.splitByWholeSeparator(numeroTxt, ".")[0]; enteroTxt = StringUtils.leftPad(enteroTxt, longitud, "0"); return enteroTxt; }