List of usage examples for org.apache.commons.lang StringUtils reverse
public static String reverse(String str)
Reverses a String as per StrBuilder#reverse() .
From source file:com.univocity.examples.Tutorial001_1Autodetection.java
@Test(dependsOnMethods = "example001AutodetectMappings") public void example002ApplyReadersAndFunctionsToMultipleMappings() { //Obtains the configured engine instance DataIntegrationEngine engine = Univocity.getEngine(engineName); //Removes the mappings between the csv and fixed-width data stores. engine.removeMapping("csvDataStore", "originalSchema"); //Let's map everything again DataStoreMapping mapping = engine.map("csvDataStore", "originalSchema"); mapping.configurePersistenceDefaults().notUsingMetadata().deleteAll().insertNewRows(); //Let's autodetect again. mapping.autodetectMappings();/* www . j av a2 s. c om*/ //##CODE_START //We can manipulate the rows of multiple mappings at once. //This RowReader lowercases all strings in all rows processed by all entity mappings: mapping.addInputRowReader(new RowReader() { @Override public void processRow(Object[] inputRow, Object[] outputRow, RowMappingContext context) { for (int i = 0; i < inputRow.length; i++) { if (inputRow[i] instanceof String) { inputRow[i] = inputRow[i].toString().toLowerCase(); } } } }); //We can also associate specific functions with fields of source entities in existing mappings. //This function reverses strings engine.addFunction(EngineScope.STATELESS, "reverse", new FunctionCall<String, String>() { @Override public String execute(String input) { return StringUtils.reverse(input); } }); //Here, we associate the "reverse" function with 2 fields of source entity "FOOD_DES" mapping.getMapping("FOOD_DES", "FOOD_DES").transformFields("reverse", "long_desc", "SHRT_DESC"); //Let's execute a mapping cycle. We expect to have all data in lower case, in all tables. //We also expect to have reversed descriptions in FOOD_DES engine.executeCycle(); //##CODE_END print(readFoodGroupTable()); print(readFoodDescriptionTable()); printAndValidate(); }
From source file:com.impetus.ankush.common.utils.PasswordUtil.java
/** * Gets the random password.//from w ww . jav a 2 s. c o m * * @param length the length * @param smallChars the small chars * @param capsChars the caps chars * @param digits the digits * @param specialChars the special chars * @return the random password */ private static String getRandomPassword(int length, char[] smallChars, char[] capsChars, char[] digits, char[] specialChars) { char[][] charsArrArr = { smallChars, capsChars, digits, specialChars }; String password = null; final int charSetCategories = 4; StringBuilder passwordGenBuff = new StringBuilder(); Random r = new Random(); int arrIdx[] = new int[charSetCategories]; for (int pos = 0; pos < charSetCategories; ++pos) { arrIdx[pos] = 0; } while (passwordGenBuff.length() < length) { int setIdx = r.nextInt(charSetCategories); char[] chArr = charsArrArr[setIdx]; if ((chArr == null) || (chArr.length == 0)) { continue; } else { int generatedPasswordLength = passwordGenBuff.length(); int untouchedSetCount = 0; if (generatedPasswordLength > 0) { for (int idx = 0; idx < charSetCategories; idx++) { char[] currArr = charsArrArr[idx]; if ((currArr != null) && (currArr.length > 0)) { if (arrIdx[idx] == 0) { ++untouchedSetCount; } } } if ((untouchedSetCount >= (length - generatedPasswordLength)) && (arrIdx[setIdx] > 0)) { continue; } } passwordGenBuff.append(RandomStringUtils.random(1, chArr)); ++arrIdx[setIdx]; } } password = passwordGenBuff.toString(); if (r.nextInt() % 2 == 0) { password = StringUtils.reverse(password); } return passwordGenBuff.toString(); }
From source file:com.fujitsu.dc.common.auth.token.UnitLocalUnitUserToken.java
/** * issuer???Cell????.//from w ww. j a v a2s .c om * @param token Token String * @param issuer Cell Root URL * @return ??CellLocalToken * @throws AbstractOAuth2Token.TokenParseException ???????? */ public static UnitLocalUnitUserToken parse(final String token, final String issuer) throws AbstractOAuth2Token.TokenParseException { if (!token.startsWith(PREFIX_UNIT_LOCAL_UNIT_USER) || issuer == null) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } String[] frag = doParse(token.substring(PREFIX_UNIT_LOCAL_UNIT_USER.length()), issuer, IDX_COUNT); try { UnitLocalUnitUserToken ret = new UnitLocalUnitUserToken( Long.valueOf(StringUtils.reverse(frag[IDX_ISSUED_AT])), Long.valueOf(frag[IDX_LIFESPAN]), frag[IDX_SUBJECT], frag[IDX_ISSUER]); return ret; } catch (Exception e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } }
From source file:io.personium.common.auth.token.CellLocalAccessToken.java
String doCreateCodeString(final String[] contents) { StringBuilder raw = new StringBuilder(); // ?Epoch????????????? String iaS = Long.toString(this.issuedAt); String iaSr = StringUtils.reverse(iaS); raw.append(iaSr);/*from w ww.ja v a 2 s . com*/ raw.append(SEPARATOR); raw.append("CODE"); raw.append(SEPARATOR); raw.append(Long.toString(this.lifespan)); raw.append(SEPARATOR); raw.append(this.subject); raw.append(SEPARATOR); if (this.schema != null) { raw.append(this.schema); } if (contents != null) { for (String cont : contents) { raw.append(SEPARATOR); if (cont != null) { raw.append(cont); } } } raw.append(SEPARATOR); raw.append(this.issuer); return encode(raw.toString(), getIvBytes(issuer)); }
From source file:gov.jgi.meta.pig.aggregate.BLAT.java
/** * Method invoked on every tuple during foreach evaluation * @param input tuple; assumed to be a sequence tuple of the form (id, direction, sequence) * @exception java.io.IOException/*from www. jav a2s. com*/ */ public Tuple exec(Tuple input) throws IOException { DataBag values = (DataBag) input.get(0); if (values.size() == 0) return null; if (values.size() != 2) { ExecException newE = new ExecException("Error: can't merge more than 2 pairs "); throw newE; } Iterator<Tuple> it = values.iterator(); Tuple seqPair1 = it.next(); Tuple seqPair2 = it.next(); if (!arePairedSequences(seqPair1, seqPair2)) { ExecException newE = new ExecException("Error: sequences are not pairs"); throw newE; } Tuple t = TupleFactory.getInstance().newTuple(3); t.set(0, seqPair1.get(0)); t.set(1, "0"); String seq1 = seqPair1.get(2).toString(); String seq2 = seqPair2.get(2).toString(); t.set(2, (seq1 + StringUtils.reverse(seq2))); return t; }
From source file:com.fujitsu.dc.common.auth.token.TransCellRefreshToken.java
/** * issuer???Cell????.//from w w w . java2s .c o m * @param token Token String * @param issuer Cell Root URL * @return ??CellLocalToken * @throws AbstractOAuth2Token.TokenParseException ???????? */ public static TransCellRefreshToken parse(final String token, final String issuer) throws AbstractOAuth2Token.TokenParseException { if (!token.startsWith(PREFIX_TC_REFRESH) || issuer == null) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } String[] frag = LocalToken.doParse(token.substring(PREFIX_TC_REFRESH.length()), issuer, IDX_COUNT); try { TransCellRefreshToken ret = new TransCellRefreshToken(frag[IDX_ID], Long.valueOf(StringUtils.reverse(frag[IDX_ISSUED_AT])), Long.valueOf(frag[IDX_LIFESPAN]), frag[IDX_ISSUER], frag[IDX_SUBJECT], frag[IDX_ORIG_ISSUER], AbstractOAuth2Token.parseRolesString(frag[IDX_ORIG_ROLE_LIST]), frag[IDX_SCHEMA]); return ret; } catch (MalformedURLException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } catch (IllegalStateException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.tags.MMXDeviceTagsResourceTest.java
private static DeviceEntity createRandomDeviceEntity(AppEntity appEntity, int index) { DeviceEntity deviceEntity = new DeviceEntity(); deviceEntity.setAppId(appEntity.getAppId()); deviceEntity.setName(RandomStringUtils.randomAlphabetic(5) + " " + RandomStringUtils.randomAlphabetic(5)); deviceEntity.setOsType(OSType.ANDROID); deviceEntity.setCreated(new Date()); deviceEntity.setOwnerId(appEntity.getOwnerId()); deviceEntity.setStatus(DeviceStatus.ACTIVE); deviceEntity.setDeviceId("mmxdevicetagsresourcetestdevice" + "_" + index); deviceEntity.setPhoneNumber("+213" + RandomStringUtils.randomNumeric(7)); deviceEntity.setPhoneNumberRev(StringUtils.reverse(deviceEntity.getPhoneNumber())); DBTestUtil.getDeviceDAO().persist(deviceEntity); return deviceEntity; }
From source file:io.personium.common.auth.token.CellLocalAccessToken.java
public static CellLocalAccessToken parseCode(String code, String issuer) throws AbstractOAuth2Token.TokenParseException { if (!code.startsWith(PREFIX_CODE) || issuer == null) { throw AbstractOAuth2Token.PARSE_EXCEPTION; }/*from ww w . j av a 2 s . c o m*/ String[] frag = LocalToken.doParse(code.substring(PREFIX_CODE.length()), issuer, IDX_COUNT + 1); try { CellLocalAccessToken ret = new CellLocalAccessToken( Long.valueOf(StringUtils.reverse(frag[IDX_ISSUED_AT])), Long.valueOf(frag[IDX_LIFESPAN + 1]), frag[IDX_ISSUER + 1], frag[IDX_SUBJECT + 1], AbstractOAuth2Token.parseRolesString(frag[IDX_ROLE_LIST + 1]), frag[IDX_SCHEMA + 1]); return ret; } catch (MalformedURLException e) { throw new TokenParseException(e.getMessage(), e); } catch (IllegalStateException e) { throw new TokenParseException(e.getMessage(), e); } }
From source file:edu.monash.merc.system.version.DSVCombination.java
public static List<TLVersionTrack> createTLVersionTracks(List<DSVersionTrack> nxVersionTracks, List<DSVersionTrack> gpmVersionTracks, DSVersion gpmPstyDsVersion, DSVersion gpmLysDsVersion, DSVersion gpmNtaDsVersion, List<DSVersionTrack> hpaVersionTracks, List<DSVersionTrack> bcVersionTracks, DSVersion bcHgu133aDsVersion, DSVersion bcHgu133p2DsVersion) { List<TLVersionTrack> tlVersionTracks = new ArrayList<TLVersionTrack>(); for (DSVersionTrack nxvtrack : nxVersionTracks) { DSVersion nxDsVersion = nxvtrack.getDsVersion(); String nxTrackToken = nxvtrack.getTrackToken(); for (DSVersionTrack gpmtrack : gpmVersionTracks) { DSVersion gpmDsVersion = gpmtrack.getDsVersion(); String gpmTrackToken = gpmtrack.getTrackToken(); for (DSVersionTrack hpatrack : hpaVersionTracks) { DSVersion hpaDsVersion = hpatrack.getDsVersion(); String hpaTrackToken = hpatrack.getTrackToken(); for (DSVersionTrack bctrack : bcVersionTracks) { String bcTrackToken = bctrack.getTrackToken(); String combinatedToken = nxTrackToken + gpmTrackToken + hpaTrackToken + bcTrackToken; int tokenNum = Integer.valueOf(StringUtils.reverse(combinatedToken)); if (tokenNum != 0) { //create a new TLVersionTrack TLVersionTrack tlVersionTrack = new TLVersionTrack(); //set the DSVersions for this TLVersionTrack if (nxTrackToken.equals(DS_TRACK_TOKEN_AVAILABLE)) { tlVersionTrack.setNxDsVersion(nxDsVersion); tlVersionTrack.setNxDsIncluded(true); }/*from w w w . j ava2 s . com*/ if (gpmTrackToken.equals(DS_TRACK_TOKEN_AVAILABLE)) { tlVersionTrack.setGpmDsVersion(gpmDsVersion); tlVersionTrack.setGpmPstyDsVersion(gpmPstyDsVersion); tlVersionTrack.setGpmLysDsVersion(gpmLysDsVersion); tlVersionTrack.setGpmNtaDsVersion(gpmNtaDsVersion); tlVersionTrack.setGpmDsIncluded(true); } if (hpaTrackToken.equals(DS_TRACK_TOKEN_AVAILABLE)) { tlVersionTrack.setHpaDsVersion(hpaDsVersion); tlVersionTrack.setHpaDsIncluded(true); } if (bcTrackToken.equals(DS_TRACK_TOKEN_AVAILABLE)) { tlVersionTrack.setBcHgu133aDsVersion(bcHgu133aDsVersion); tlVersionTrack.setBcHgu133p2DsVersion(bcHgu133p2DsVersion); tlVersionTrack.setBcDsIncluded(true); } tlVersionTrack.setTrackToken(tokenNum); //add this TLVersionTrack into the list tlVersionTracks.add(tlVersionTrack); } } } } } //sort the TLVersionTrack in ascend order Collections.sort(tlVersionTracks, new TLVComparator()); return tlVersionTracks; }
From source file:gov.jgi.meta.sequence.SequenceString.java
static public byte[] merge(byte[] seq1, byte[] seq2) { // reverse the second sequence and merge String s1 = byteArrayToSequence(seq1); String s2 = byteArrayToSequence(seq2); String s3 = s1 + StringUtils.reverse(s2); return sequenceToByteArray(s3); }