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:com.haulmont.cuba.core.DataManagerDistinctResultsTest.java
@Before public void setUp() throws Exception { Transaction tx = cont.persistence().createTransaction(); try {/*w ww. jav a 2 s .com*/ EntityManager em = cont.persistence().getEntityManager(); Group group = new Group(); groupId = group.getId(); group.setName("testGroup"); em.persist(group); Role role1 = new Role(); role1Id = role1.getId(); role1.setName("role1"); em.persist(role1); Role role2 = new Role(); role2Id = role2.getId(); role2.setName("role2"); em.persist(role2); for (int i = 0; i < QTY; i++) { User user = new User(); user.setName("user" + StringUtils.leftPad(String.valueOf(i), 2, '0')); user.setLogin(user.getName()); user.setGroup(group); em.persist(user); UserRole userRole1 = new UserRole(); userRole1.setUser(user); userRole1.setRole(role1); em.persist(userRole1); UserRole userRole2 = new UserRole(); userRole2.setUser(user); userRole2.setRole(role2); em.persist(userRole2); } tx.commit(); } finally { tx.end(); } }
From source file:com.artivisi.iso8583.Message.java
public String getSecondaryBitmapStream() { if (secondaryBitmap == null || BigInteger.ZERO.equals(secondaryBitmap)) { return ""; }//from w w w . jav a 2 s . c o m return StringUtils.leftPad(secondaryBitmap.toString(16).toUpperCase(), 16, "0"); }
From source file:com.haulmont.cuba.core.QueryResultTest.java
private void createEntities() { Transaction tx = cont.persistence().createTransaction(); try {/*from w w w. ja v a2 s . co m*/ EntityManager em = cont.persistence().getEntityManager(); User user; Group group = em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93")); int k = 0; for (String domain : Arrays.asList("@aaa.com", "@bbb.com")) { for (String name : Arrays.asList("A-", "B-")) { for (String firstName : Arrays.asList("C-", "D-")) { for (int i = 0; i < 5; i++) { user = new User(); user.setGroup(group); userIds.add(user.getId()); user.setLogin("user" + StringUtils.leftPad(String.valueOf(k++), 2, '0')); user.setName(name + "User" + i); user.setFirstName(firstName + "User" + i); user.setEmail(user.getLogin() + domain); em.persist(user); } } } } tx.commit(); } finally { tx.end(); } }
From source file:biblivre3.administration.reports.AssetHoldingFullReport.java
@Override protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception { AssetHoldingDto dto = (AssetHoldingDto) reportData; String title = ""; if (this.topographic) { title = this.getText("REPORTS_TOPOGRAPHIC_TITLE"); } else {/*from w w w . java2 s . c o m*/ title = this.getText("REPORTS_ASSET_HOLDING_TITLE"); } Paragraph p1 = new Paragraph(title); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); document.add(new Phrase("\n")); PdfPTable table = new PdfPTable(20); table.setWidthPercentage(100f); createHeader(table); PdfPCell cell; List<String[]> dataList = dto.getData(); Collections.sort(dataList, this); for (String[] data : dataList) { PdfContentByte cb = getWriter().getDirectContent(); String holdingSerial = StringUtils.leftPad(data[0], 10, "0"); Barcode39 code39 = new Barcode39(); code39.setExtended(true); code39.setCode(holdingSerial); code39.setStartStopText(false); Image image39 = code39.createImageWithBarcode(cb, null, null); image39.scalePercent(100f); cell = new PdfPCell(new Paragraph(new Phrase(new Chunk(image39, 0, 0)))); cell.setColspan(6); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[1]))); cell.setColspan(3); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); Paragraph para = new Paragraph(); para.add(new Phrase(this.getSmallFontChunk(data[2] + "\n"))); para.add(new Phrase(this.getSmallFontChunk(data[3] + "\n"))); if (StringUtils.isNotBlank(data[4])) { para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_LOCATION") + ": "))); para.add(new Phrase(this.getSmallFontChunk(data[4] + " "))); } if (StringUtils.isNotBlank(data[5])) { para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_EDITION") + ": "))); para.add(new Phrase(this.getSmallFontChunk(data[5] + " "))); } if (StringUtils.isNotBlank(data[6])) { para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_DATE") + ": "))); para.add(new Phrase(this.getSmallFontChunk(data[6]))); } cell = new PdfPCell(para); cell.setColspan(11); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.setPaddingTop(5f); cell.setPaddingLeft(7f); cell.setPaddingBottom(4f); table.addCell(cell); } document.add(table); }
From source file:com.processpuzzle.fundamental_types.uniqueidentifier.domain.PrefixedIncNumberedIdFactory.java
private UniqueIdentifier createNewIdentifierWithPrefix(String actualPerfix) { UniqueIdentifier identifier = null;/*from w w w. j av a 2s .c om*/ if (applicationContext != null) { LastIdNumberRepository lastIdNumberRepositoryRepository = (LastIdNumberRepository) applicationContext .getRepository(LastIdNumberRepository.class); LastIdNumber lastIdNumber = lastIdNumberRepositoryRepository.findLatestIdByType(idType); if (lastIdNumber != null) { Integer latestNumber = lastIdNumber.getLatestNumber(); String newNumberStr = String.valueOf(latestNumber + 1); String newNumberWithLpadStr = StringUtils.leftPad(newNumberStr, length, LPAD_CHAR); String identifierStr = getIdentifierStr(actualPerfix, separator, newNumberWithLpadStr); identifier = generateUniqueIdentifierByType(idType, identifierStr); lastIdNumberRepositoryRepository.incrementLastIdNumber(idType); } } return identifier; }
From source file:es.emergya.comunications.MessageGenerator.java
/** * /*ww w . ja v a2 s . c o m*/ * @param tipo * @param prioridad * @param cuerpo * @param destino * @return */ @Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public static Outbox sendMessage(Integer codigo, Integer tipo, Integer prioridad, String cuerpo, String destino) throws MessageGeneratingException { if (destino == null) { throw new MessageGeneratingException("Destino nulo."); } if (codigo == null) { throw new MessageGeneratingException("Mensaje sin codigo."); } if (tipo == null) { throw new MessageGeneratingException("Mensaje sin tipo."); } if (prioridad == null) { throw new MessageGeneratingException("Prioridad nula"); } if (cuerpo == null) { cuerpo = ""; } log.info("sendMessage(" + codigo + "," + tipo + "," + prioridad + "," + cuerpo + "," + destino + ")"); try { Integer tipo_tetra = TipoMensajeConsultas.getTipoByCode(codigo).getTipoTetra(); // Limpiamos las comillas: cuerpo = StringUtils.remove(cuerpo, "'"); String datagramaTetra = getDatagrama(codigo, tipo, cuerpo); Outbox out = new Outbox(); out.setMarcaTemporal(Calendar.getInstance().getTime()); out.setDatagramaTetra(datagramaTetra); out.setPrioridad(prioridad); out.setDestino(StringUtils.leftPad(destino, LogicConstants.getInt("LONGITUD_ISSI", 8), '0')); out.setTipo(tipo_tetra); log.info("Enviamos el mensaje " + datagramaTetra + " a " + destino + " con prioridad " + prioridad); out = bandejaSalidaDAO.save(out); log.info("Enviando " + out); return out; } catch (Exception e) { throw new MessageGeneratingException("Error al generar mensaje", e); } }
From source file:net.certiv.authmgr.task.section.model.ReLoadClassifications.java
private void doReload(DocPageList docStructure, File f) { DocPageList dpl = docStructure;//from ww w . j ava2 s. c o m File file = f; int count = 0; int lines = 0; try { BufferedReader in = new BufferedReader(new FileReader(file)); String str; for (int pgIdx = 0; pgIdx < dpl.size(); pgIdx++) { DocPage dp = docStructure.getDocPageAtIdx(pgIdx); for (int ln = 0; ln < dp.size(DocPage.RANK_ORDER); ln++) { DocLine dl = dp.getDocLine(ln, DocPage.RANK_ORDER); if ((str = in.readLine()) != null) { String[] training = str.split("\\s", 2); // pick off category name if (dl.lineSection != DocLine.getSectionIndex(training[0])) { String pgStr = StringUtils.leftPad("" + (pgIdx + 1), 3, "0"); String lnStr = StringUtils.leftPad("" + ln, 2, "0"); Log.warn(this, "[" + pgStr + ":" + lnStr + "] Classed as: " + DocLine.partitions[dl.lineSection] + "; should be: " + training[0]); dl.lineSection = DocLine.getSectionIndex(training[0]); count++; } lines++; } else { Log.warn(this, "Ran out of classification lines."); } } } in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String percent = "" + (((lines - count) * 100) / lines) + "% accuracy"; Log.warn(this, "Correction count: " + count + ":" + lines + " (" + percent + ")"); }
From source file:alma.acs.container.archive.IdentifierJMock.java
/** * This is the only method that's currently implemented * @see alma.xmlstore.IdentifierJ#getNewRange() *//*from ww w .j av a 2 s .c om*/ public IdentifierRange getNewRange() throws NotAvailable { //Create the entity information IdentifierRangeEntityT entityt = new IdentifierRangeEntityT(); //The id of the range is the 0 document id in that range. entityt.setEntityId(createUid()); IdentifierRange range = new IdentifierRange(); range.setIdentifierRangeEntity(entityt); //set the time stamp String ts = IsoDateFormat.formatCurrentDate(); // todo: pass in time externally? range.setCreatedTimeStamp(ts); range.setIsLocked(false); String archiveIdString = Long.toHexString(archiveid); archiveIdString = "X" + StringUtils.leftPad(archiveIdString, archiveIdLength, '0'); range.setArchiveID(archiveIdString); RangeT ranget = new RangeT(); ranget.setRangeID(Long.toHexString(rangeid)); ranget.setBaseDocumentID("1"); range.setRange(ranget); rangeid++; // this.setRangeId(rangeid); return range; }
From source file:edu.wisc.cypress.dao.benstmt.RestBenefitStatementDao.java
@Override public void getBenefitStatement(String emplid, int year, String docId, String mode, ProxyResponse proxyResponse) {/*from ww w.jav a2 s . c o m*/ final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("HRID", emplid); final String yearStr = Integer.toString(year); final String yearCode; if (yearStr.length() > 2) { yearCode = yearStr.substring(2); } else if (yearStr.length() < 2) { yearCode = StringUtils.leftPad(yearStr, 2, '0'); } else { yearCode = yearStr; } this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, yearCode, docId, mode); }
From source file:net.sourceforge.fenixedu.domain.accounting.util.RectoratePaymentCodeGenerator.java
@Override public String generateNewCodeFor(PaymentCodeType paymentCodeType, Person person) { final PaymentCode lastPaymentCode = findLastPaymentCode(); int nextSequentialNumber = lastPaymentCode == null ? 0 : Integer.valueOf(getSequentialNumber(lastPaymentCode)) + 1; String sequentialNumberPadded = StringUtils.leftPad(String.valueOf(nextSequentialNumber), NUM_SEQUENTIAL_NUMBERS, CODE_FILLER); String controDigitsPadded = StringUtils.leftPad(String.valueOf((new Random()).nextInt(99)), NUM_CONTROL_DIGITS, CODE_FILLER); return START + sequentialNumberPadded + controDigitsPadded; }