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.sonicle.webtop.calendar.ManagerUtils.java
public static String encodeAsCalendarUid(int calendarId) { return Base58.encode(StringUtils.leftPad(String.valueOf(calendarId), 10, "0").getBytes()); }
From source file:eu.semlibproject.annotationserver.managers.UtilsManager.java
/** * Compute the CRC32 checksum of a String. This can be useful to * short an URL./*from ww w . ja v a 2 s . c om*/ * * @param text the text from which the checksum will be computed * @return the CRC32 checksum */ public String CRC32(String text) { CRC32 checksumer = new CRC32(); checksumer.update(text.getBytes()); String finalhash = Long.toHexString(checksumer.getValue()); // correctly format the finalHash (e.g. number starting with 00 that was stripped) return StringUtils.leftPad(finalhash, 8, "0"); }
From source file:com.youTransactor.uCube.Tools.java
public static byte[] toBCD_double(double value, int length) { NumberFormat formatter = new DecimalFormat("#"); String val = formatter.format(value); return hexStringToByteArray(StringUtils.leftPad(val, length * 2, '0')); }
From source file:io.github.dsheirer.module.decode.ltrstandard.message.LTRStandardMessage.java
public String getChannelFormatted() { return StringUtils.leftPad(String.valueOf(getChannel()), 2, "0"); }
From source file:io.github.dsheirer.module.decode.ltrstandard.message.LTRStandardMessage.java
public String getHomeRepeaterFormatted() { return StringUtils.leftPad(String.valueOf(getHomeRepeater()), 2, "0"); }
From source file:com.omertron.slackbot.functions.scheduler.AbstractBotTask.java
/** * Return an attachment with the status of the BotTask * * @return/*from w w w . j a v a2 s. c om*/ */ @Override public final SlackAttachment getStatus() { SlackAttachment sa = new SlackAttachment(); sa.setTitle(name); StringBuilder time = new StringBuilder(); time.append(StringUtils.leftPad(Integer.toString(targetHour), 2, '0')).append(':') .append(StringUtils.leftPad(Integer.toString(targetMin), 2, '0')); sa.addField("Target Time", time.toString(), true); sa.addField("Remaining Time", formatSeconds(scheduledTask.getDelay(TimeUnit.SECONDS)), true); sa.addField("Channel", channel.getName(), true); sa.addField("Executions", Integer.toString(completedTasks.get()), true); sa.setColor(Constants.ATTACH_COLOUR_GOOD); return sa; }
From source file:de.micromata.genome.db.jpa.tabattr.BaseOpTest.java
/** * Tests if the longValue is returned in the right order *//*from ww w . ja va 2 s. c o m*/ @Test public void testLongDataValues() { final TestTabAttrJpaDAOImpl dao = new TestTabAttrJpaDAOImpl(); TestMasterAttrDO master = FirstTest.createMaster(dao, 0, 1); String longValueKey = "LONGVALUE"; String aString = StringUtils.leftPad("", JpaTabAttrDataBaseDO.DATA_MAXLENGTH, 'A'); String longString = aString; String bString = StringUtils.leftPad("", JpaTabAttrDataBaseDO.DATA_MAXLENGTH, 'B'); longString += bString; String cString = StringUtils.leftPad("", JpaTabAttrDataBaseDO.DATA_MAXLENGTH, 'C'); longString += cString; String dString = StringUtils.leftPad("", JpaTabAttrDataBaseDO.DATA_MAXLENGTH, 'D'); longString += dString; master.putAttribute(longValueKey, longString); dao.insert(master); TestMasterAttrDO testMasterAttrDO = dao.loadByPk(master.getPk()); JpaTabAttrBaseDO<TestMasterAttrDO, Long> testMasterAttrDOJpaTabAttrBaseDO = testMasterAttrDO.getAttributes() .get(longValueKey); List<JpaTabAttrDataBaseDO<?, Long>> data = testMasterAttrDOJpaTabAttrBaseDO.getData(); Assert.assertEquals(3, data.size()); Assert.assertEquals(0, data.get(0).getDatarow()); Assert.assertEquals(1, data.get(1).getDatarow()); Assert.assertEquals(2, data.get(2).getDatarow()); JpaTabAttrDataBaseDO<?, Long> jpaTabAttrDataBaseDO = data.get(0); String attrData1 = jpaTabAttrDataBaseDO.getData(); Assert.assertEquals(bString, attrData1); JpaTabAttrDataBaseDO<?, Long> jpaTabAttrDataBaseDO2 = data.get(2); String attrData2 = jpaTabAttrDataBaseDO2.getData(); Assert.assertEquals(dString, attrData2); String attribute = testMasterAttrDO.getAttribute(longValueKey, String.class); Assert.assertEquals(longString, attribute); }
From source file:com.autentia.bcbp.elements.ConditionalItemsRepeated.java
private ConditionalItemsRepeated(String airlineNumericCode, String serialNumber, String selecteeIndicator, String internationalDocumentVerification, String marketingCarrierDesignator, String frecuentFlyerAirlineDesignator, String frecuentFlyerNumber, String iDADIndicator, String freeBaggageAllowance, String fastTrack) { Stack<Item> items = new Stack<Item>(); items.push(new Item(airlineNumericCode, airlineNumericCodeLength, 142, PaddingType.Number)); items.push(new Item(serialNumber, serialNumberLength, 143, PaddingType.Number)); items.push(new Item(selecteeIndicator, selecteeIndicatorLength, 18, PaddingType.String)); items.push(new Item(internationalDocumentVerification, internationalDocumentVerificationLength, 108, PaddingType.String)); items.push(new Item(marketingCarrierDesignator, marketingCarrierDesignatorLength, 19, PaddingType.String)); items.push(new Item(frecuentFlyerAirlineDesignator, frecuentFlyerAirlineDesignatorLength, 20, PaddingType.String)); items.push(new Item(frecuentFlyerNumber, frecuentFlyerNumberLength, 236, PaddingType.String)); items.push(new Item(iDADIndicator, IDADIndicatorLength, 89, PaddingType.String)); items.push(new Item(freeBaggageAllowance, freeBaggageAllowanceLength, 118, PaddingType.String)); items.push(new Item(fastTrack, fastTrackLength, 254, PaddingType.String)); final StringBuilder codeBuilder = new StringBuilder(); boolean starting = true; while (!items.isEmpty()) { Item item = items.pop();// www. jav a 2s. c om if (starting && StringUtils.isNotBlank(item.getEncoded()) || !removeEndingEmptyElements) starting = false; if (!starting) codeBuilder.insert(0, item.getEncoded()); } final String baseCode = codeBuilder.toString(); if (StringUtils.isBlank(baseCode)) { code = ""; } else { code = StringUtils.leftPad(Integer.toHexString(baseCode.length()), variableSizeLength, "0") .toUpperCase() + baseCode; } }
From source file:com.cisco.dbds.utils.logging.LogHandler.java
/** * Prints the scenario name.//w w w .j ava 2s . c o m * * @param scenarioTags the scenario tags * @param testCaseName the test case name * @param status the status */ public static void printScenarioName(String scenarioTags, String testCaseName, String status) { String formattedLine = ""; String formattedScenarioTags = "> Scenario tags : " + scenarioTags; String formattedScenarioName = "> Scenario Name : " + testCaseName.toUpperCase(); String formattedStatus = "> Scenario Status : " + status; if (formattedScenarioTags.length() > formattedScenarioName.length()) { formattedLine = StringUtils.leftPad("", formattedScenarioTags.length() + 2, '='); formattedScenarioTags = StringUtils.rightPad(formattedScenarioTags, (formattedScenarioTags.length() + 1), " ") + "<"; formattedScenarioName = StringUtils.rightPad(formattedScenarioName, (formattedScenarioTags.length() - 1), " ") + "<"; formattedStatus = StringUtils.rightPad(formattedStatus, (formattedScenarioTags.length() - 1), " ") + "<"; } else { formattedLine = StringUtils.leftPad("", formattedScenarioName.length() + 2, '='); formattedScenarioTags = StringUtils.rightPad(formattedScenarioTags, (formattedScenarioName.length() + 1), " ") + "<"; formattedScenarioName = StringUtils.rightPad(formattedScenarioName, (formattedScenarioName.length() + 1), " ") + "<"; formattedStatus = StringUtils.rightPad(formattedStatus, (formattedScenarioName.length() - 1), " ") + "<"; } if (isLoggingEnabled) { log.info(formattedLine); log.info(formattedScenarioTags); log.info(formattedScenarioName); log.info(formattedStatus); log.info(formattedLine); } printToConsole(formattedLine + "\n" + formattedScenarioTags + "\n" + formattedScenarioName + "\n" + formattedStatus + "\n" + formattedLine); }
From source file:com.stratio.cassandra.index.schema.ColumnMapperBigInteger.java
/** {@inheritDoc} */ @Override// w ww. ja v a 2s .c o m public String indexValue(String name, Object value) { // Check not null if (value == null) { return null; } // Parse big decimal String svalue = value.toString(); BigInteger bi; try { bi = new BigInteger(svalue); } catch (NumberFormatException e) { String message = String.format("Field %s requires a base 10 integer, but found \"%s\"", name, svalue); throw new IllegalArgumentException(message); } // Check size if (bi.abs().toString().length() > digits) { throw new IllegalArgumentException("Value has more than " + digits + " digits"); } // Map bi = bi.add(complement); String bis = encode(bi); return StringUtils.leftPad(bis, hexDigits + 1, '0'); }