List of usage examples for org.apache.commons.lang StringUtils leftPad
public static String leftPad(String str, int size, String padStr)
Left pad a String with a specified String.
From source file:id.co.teleanjar.ppobws.isoserver.EchoTest.java
private ISOMsg createSignOnRequest(Instant sekarang) throws ISOException { ISOPackager packager = new TelePackager(); String bit11 = formatterBit11.format(sekarang) .concat(StringUtils.leftPad(random10Digit().toString(), 6, "0")); System.out.println("Bit11 " + bit11); ISOMsg msg = new ISOMsg(); msg.setMTI("2800"); msg.set(7, formatterBit7.format(sekarang)); msg.set(11, bit11);//from w w w. j a v a 2s . c om msg.set(33, "1234577"); msg.set(70, "001"); msg.setPackager(packager); System.out.println("msg send : " + new String(msg.pack())); System.out.println("queue msg sending"); return msg; }
From source file:com.haythem.integration.CustomSerializerDeserializer.java
private String pad(int desiredLength, int length) { return StringUtils.leftPad(Integer.toString(length), desiredLength, '0'); }
From source file:net.big_oh.common.flatfile.FlatFileRecordBuilder.java
/** * Builds a single record (i.e. line) in the flat file using the collection * of {@link FlatFileRecordField} objects. * //from w ww . ja va 2 s. c o m * @param fieldsForRecord * The FlatFileRecordField objects used to construct a single * record for the flat file. * @param fieldDelimiter * An optional character that can be placed between fields in the * flat file record. * @param interFieldPadChar * The character used to fill any spaces that do not correspond * to a field in the flat file record. * @return A single record (i.e. line) to be included in a flat file. * @throws IllegalArgumentException * Thrown if the Collection of FlatFileRecordField objects * overlap. */ public static String buildFlatFileRecord(Collection<FlatFileRecordField> fieldsForRecord, String fieldDelimiter, char interFieldPadChar) throws IllegalArgumentException { StringBuffer recordContent = new StringBuffer(); List<FlatFileRecordField> sortedFieldsForRecord = new ArrayList<FlatFileRecordField>(fieldsForRecord); Collections.sort(sortedFieldsForRecord, new Comparator<FlatFileRecordField>() { public int compare(FlatFileRecordField o1, FlatFileRecordField o2) { return new Integer(o1.getFieldFormat().getFieldStartPosition()) .compareTo(new Integer(o2.getFieldFormat().getFieldStartPosition())); } }); int lastPositionPopulated = 0; for (FlatFileRecordField recordField : sortedFieldsForRecord) { FlatFileFieldFormat fieldFormat = recordField.getFieldFormat(); // add the field delimiter before all fields but the first if (fieldDelimiter != null && lastPositionPopulated > 0) { recordContent.append(fieldDelimiter); } // check to see whether we've encountered two overlapping fields if (lastPositionPopulated >= fieldFormat.getFieldStartPosition()) { throw new IllegalArgumentException( "Field " + fieldFormat.toString() + " overlaps with another field. This is not allowed."); } // add whitespace as needed to fill gap between consecutive fields while (lastPositionPopulated < fieldFormat.getFieldStartPosition() - 1) { recordContent.append(interFieldPadChar); lastPositionPopulated++; } int fieldLength = fieldFormat.getFieldLength(); String fieldValue = recordField.getFieldValue(); // abbreviate values that are too long if (fieldValue.length() > fieldLength) { fieldValue = fieldValue.substring(0, fieldLength); } // pad values that are too short if (fieldFormat.getPaddingType().equals(FlatFileFieldPaddingType.PADDING_ON_LEFT)) { fieldValue = StringUtils.leftPad(fieldValue, fieldLength, fieldFormat.getIntraFieldPaddingChar()); } else if (fieldFormat.getPaddingType().equals(FlatFileFieldPaddingType.PADDING_ON_RIGHT)) { fieldValue = StringUtils.rightPad(fieldValue, fieldLength, fieldFormat.getIntraFieldPaddingChar()); } // add the field value now that it is the proper size for the field recordContent.append(fieldValue); lastPositionPopulated += fieldValue.length(); } return recordContent.toString(); }
From source file:de.tudarmstadt.ukp.dkpro.tc.core.io.ClassificationUnitCasMultiplierTest.java
private void createAndCheckNCases(int n) throws ResourceInitializationException, AnalysisEngineProcessException { String text = StringUtils.leftPad("s", n, 'x'); JCas jCas = createNewJCasWithText(text); for (int i = 0; i < n; i++) { createAnnotationForCas(jCas, i); }// w w w .ja v a 2 s . c o m JCasIterator it = engine.processAndOutputNewCASes(jCas); int i = 0; while (it.hasNext()) { JCas a = it.next(); TextClassificationFocus focus = JCasUtil.selectSingle(a, TextClassificationFocus.class); Collection<TextClassificationOutcome> c = JCasUtil.selectCovered(a, TextClassificationOutcome.class, focus); assertEquals("The CAS should have only one TextClassificationOutcome annotation", c.size(), 1); TextClassificationOutcome out = c.iterator().next(); assertEquals("TextClassificationOutcome is wrong", String.valueOf(i), out.getOutcome()); a.release(); i++; } assertEquals("Expected amount of CASes is wrong", n, i); }
From source file:com.sds.acube.ndisc.mts.xserver.util.XNDiscUtils.java
/** * ? ? // w w w .ja va2s.c o m * * @param status * ? * @return ? ? */ public static String getStatus(int status) { String strstatus = Integer.toString(status); return StringUtils.leftPad(strstatus, 5, "0"); }
From source file:info.magnolia.cms.beans.config.RotatingVirtualURIMapping.java
/** * {@inheritDoc}//from w w w. j a va 2 s . com */ @Override public MappingResult mapURI(String uri) { // delegate the initial processing to RegexpVirtualURIMapping MappingResult mr = super.mapURI(uri); if (mr != null) { if (end > start) { int randomNumber = RandomUtils.nextInt(end - (start - 1)) + start; String randomAsString = StringUtils.leftPad(Integer.toString(randomNumber), padding, '0'); mr.setToURI(StringUtils.replace(mr.getToURI(), RANDOM_PLACEHOLDER, randomAsString)); } else { log.warn("End value must be greater than start value."); } } return mr; }
From source file:gate.corpora.twitter.Population.java
private static Document newDocument(URL url, int counter, int digits) throws ResourceInstantiationException { Document document = Factory.newDocument(""); String code = StringUtils.leftPad(Integer.toString(counter), digits, '0'); String name = StringUtils.stripToEmpty(StringUtils.substring(url.getPath(), 1)) + "_" + code; document.setName(name);/*from w w w . ja v a 2 s .c om*/ document.setSourceUrl(url); document.getFeatures().put(Document.DOCUMENT_MIME_TYPE_PARAMETER_NAME, TweetUtils.MIME_TYPE); document.getFeatures().put("gate.SourceURL", url.toString()); return document; }
From source file:net.sourceforge.fenixedu.domain.accounting.util.PersonRotationPaymentCodeGenerator.java
private static String generateFinalCode(final PaymentCodeType paymentCodeType, final Person person, int digits) { final String finalCode = getCodePrefix(paymentCodeType, person) + StringUtils.leftPad(String.valueOf(digits), CONTROL_DIGITS_LENGTH, CODE_FILLER); if (finalCode.length() != CODE_LENGTH) { throw new RuntimeException("Unexpected code length for generated code"); }//from w ww . ja v a 2 s. c o m return finalCode; }
From source file:com.enioka.jqm.api.ServiceSimple.java
@GET @Path("stdout") @Produces(MediaType.APPLICATION_OCTET_STREAM) public InputStream getLogOut(@QueryParam("id") int id) { res.setHeader("Content-Disposition", "attachment; filename=" + id + ".stdout.txt"); return getFile(FilenameUtils.concat("./logs", StringUtils.leftPad("" + id, 10, "0") + ".stdout.log")); }
From source file:ch.algotrader.option.OptionSymbol.java
/** * Generates the ISIN for the specified {@link ch.algotrader.entity.security.OptionFamily}. *//*ww w . j av a 2 s . com*/ public static String getIsin(OptionFamily family, LocalDate expiration, OptionType type, BigDecimal strike) { String week = family.isWeekly() ? DateTimePatterns.WEEK_OF_MONTH.format(expiration) : ""; String month; if (OptionType.CALL.equals(type)) { month = monthCallEnc[expiration.getMonthValue() - 1]; } else { month = monthPutEnc[expiration.getMonthValue() - 1]; } int yearIndex = expiration.getYear() % 10; String year = yearEnc[yearIndex]; String strike36 = BaseConverterUtil.toBase36(strike.multiply(new BigDecimal(10)).intValue()); String strikeVal = strike.scale() + StringUtils.leftPad(strike36, 4, "0"); StringBuilder buffer = new StringBuilder(); buffer.append("1O"); buffer.append(family.getIsinRoot() != null ? family.getIsinRoot() : family.getSymbolRoot()); buffer.append(week); buffer.append(month); buffer.append(year); buffer.append(strikeVal); return buffer.toString(); }