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.vake.ArrayUtils.java
/** * ?radix<p/>//from w w w .j av a 2s .co m * bytesnull"null"bytes"[]" * * @param bytes * @param radix2?816 * @return */ public static String toString(byte[] bytes, int radix) { if (2 != radix && 8 != radix && 16 != radix) { final String msg = "radix must be 2, 8 or 16"; throw new IllegalArgumentException(msg); } if (null == bytes) { return "null"; } final StringBuilder builder = new StringBuilder("["); final int len = bytes.length; for (int i = 0; i < len; i++) { final int intValue = bytes[i] & 0xFF; final String string; final String padString; switch (radix) { case 2: string = Integer.toBinaryString(intValue); padString = StringUtils.leftPad(string, 8, '0'); break; case 8: string = Integer.toOctalString(intValue); padString = StringUtils.leftPad(string, 3, '0'); break; default: string = Integer.toHexString(intValue); padString = StringUtils.leftPad(string, 2, '0'); } builder.append(padString.toUpperCase()); if (i < len - 1) { builder.append(", "); } } builder.append("]"); return builder.toString(); }
From source file:com.mmj.app.common.util.SerialNumGenerator.java
private static String getSuffix(Long id) { Long num = 1l;/* ww w . j a v a2 s . c o m*/ if (id != null) { num = id % 100000;// id?? } Random random = new Random(); StringBuffer suffixBuffer = new StringBuffer(); suffixBuffer.append(String.valueOf(num)).append(random.nextInt(1000)); return StringUtils.leftPad(suffixBuffer.toString(), 8, '0'); }
From source file:jp.co.ntts.vhut.util.VhutUtil.java
/** * Vhut????????????./*from w w w .j a va2 s . co m*/ * @param prefix * @param privateId ?ID * @return ? */ public static String createServicePrefix(String prefix, long privateId) { String privateIdString = new Long(privateId).toString(); if (privateIdString.length() > 2) { privateIdString = privateIdString.substring(privateIdString.length() - 3); } String id = StringUtils.leftPad(privateIdString, 3, "0"); return String.format("%s%s", prefix, id); }
From source file:com.pureinfo.studio.db.cmd2srm.ref.impl.OutlayUnitIdRef.java
/** * @see com.pureinfo.importer.ref.IImportorRef#convert(com.pureinfo.dolphin.model.DolphinObject, * com.pureinfo.dolphin.model.DolphinObject, java.lang.String, * java.lang.String, com.pureinfo.dolphin.persister.ISession, * com.pureinfo.dolphin.persister.ISession, * com.pureinfo.dolphin.mapping.EntityMetadata, java.lang.String, * java.lang.String)//from w w w .j a v a 2 s. co m */ public Object convert(DolphinObject _old, DolphinObject _new, String _sFromProperty, String _sToProperty, ISession _fromSession, ISession _toSession, EntityMetadata _metadata, String _sKey, String _sToTable) throws PureException { ZjuOutlayCodeGenerator g = new ZjuOutlayCodeGenerator(); int unitId = g.getIdValue(); g.setCode(unitId + 1); return StringUtils.leftPad("" + unitId, 7, '0'); }
From source file:com.codenjoy.dojo.a2048e.model.LevelImpl.java
public LevelImpl() { settings = new SettingsImpl(); size = settings.addEditBox("Size").type(Integer.class).def(6); newAdd = settings.addEditBox("New numbers").type(Integer.class).def(2); mode = settings.addEditBox("Mode").type(Integer.class).def(1); map = StringUtils.leftPad("", size(), ' '); xy = new LengthToXY(size()); }
From source file:fi.vm.kapa.identification.service.TupasStampIdService.java
public String getTupasStampCounter(int lengthOfTimeStamp) { int len = TUPAS_STAMP_LENGTH - lengthOfTimeStamp; String strTupasStampCounter = Long.toString(updateAndGetCounter()); String tupasStampStr = StringUtils.leftPad(strTupasStampCounter, len, "0"); return tupasStampStr; }
From source file:com.nectify.hornet.HornetImpl.java
public String createAccessToken(String... channels) { long timestamp = Math.round(System.currentTimeMillis() / 1000); String suffix = StringUtils.leftPad("" + timestamp, 10, '0') + StringUtils.leftPad("" + (new Random()).nextInt(10000), 5, '0'); Jedis jedis = pool.getResource();// w ww. ja va 2s. co m String token = null; try { long nextTokenId = jedis.incr("hornet:tokens_id"); Long tokenBase10 = new Long(nextTokenId + suffix); token = HornetUtils.converter(62, tokenBase10); String key = "hornet:token:" + token; for (int i = 0; i < channels.length; i++) { String channel = channels[i]; jedis.sadd(key, channel); } jedis.expire(key, tokenTTL); } finally { pool.returnResource(jedis); } return token; }
From source file:edu.usu.sdl.openstorefront.usecase.PostmanCollection.java
@Test public void generatedPostmanCollection() { String fileName = "c:/temp/postmanCollection.json"; String id = "d4de36f5-d5d6-7512-7490-96155b17972c"; String urlBase = "http://store-dev.usu.di2e.net/openstorefront/api/v1/resource/attributes/attributetypes/DI2E-SVCV4-A/attributecodes/"; PostmanCollectionModel postmanCollectionModel = new PostmanCollectionModel(); postmanCollectionModel.setId(id);//from ww w . ja va 2s . c o m postmanCollectionModel.setName("Bad Code Deletes"); postmanCollectionModel.setTimestamp(TimeUtil.currentDate()); for (int i = 1; i < 380; i++) { String code = StringUtils.leftPad("" + i, 4, "0"); PostmanRequest postmanRequest = new PostmanRequest(); postmanRequest.setCollectionId(postmanCollectionModel.getId()); postmanRequest.setId(UUID.randomUUID().toString()); postmanRequest.setName("Delete: " + code); postmanRequest.setMethod("DELETE"); postmanRequest.setHeaders("Content-Type: application/json"); postmanRequest.setDataMode("params"); postmanRequest.setTimestamp(TimeUtil.currentDate()); postmanRequest.setVersion(2); postmanRequest.setUrl(urlBase + code + "/force"); postmanRequest.setDescription("Remove code: " + code); postmanCollectionModel.getRequests().add(postmanRequest); } try (OutputStream out = new FileOutputStream(fileName)) { StringProcessor.defaultObjectMapper().writeValue(out, postmanCollectionModel); } catch (Exception e) { System.out.println(e); } }
From source file:net.sourceforge.fenixedu.domain.accounting.util.PersonPaymentCodeGenerator.java
@Override public String generateNewCodeFor(final PaymentCodeType paymentCodeType, final Person person) { String baseCode = getPersonCodeDigits(person) + StringUtils .leftPad(Integer.toString(paymentCodeType.getTypeDigit()), TYPE_CODE_LENGTH, CODE_FILLER); baseCode = baseCode + Verhoeff.generateVerhoeff(baseCode); if (baseCode.length() != CODE_LENGTH) { throw new RuntimeException("Unexpected code length for generated code"); }//from ww w . j a v a 2 s.c o m return baseCode; }
From source file:com.codenjoy.dojo.tetris.model.TetrisFigure.java
private void parseRows(String... rows) { this.rows = rows; codes = new int[rows.length]; uncoloredCodes = new int[rows.length]; for (int i = 0; i < rows.length; i++) { String row = rows[i];//from w w w. j a v a 2 s. co m String colorCode = Integer.toBinaryString(type.getColor().ordinal() + 1); String paddedCode = StringUtils.leftPad(colorCode, 3, '0'); codes[i] = Integer.parseInt(row.replace("#", paddedCode).replace(" ", "000"), 2); uncoloredCodes[i] = Integer.parseInt(row.replace("#", "111").replace(" ", "000"), 2); } }