Example usage for org.apache.commons.lang StringUtils reverse

List of usage examples for org.apache.commons.lang StringUtils reverse

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils reverse.

Prototype

public static String reverse(String str) 

Source Link

Document

Reverses a String as per StrBuilder#reverse() .

Usage

From source file:com.flexive.tests.embedded.WorkflowTest.java

/**
 * Tests if workflows are updated properly.
 *
 * @throws Exception if an error occured
 *///www  . j av  a2  s .c o  m
@Test
public void updateWorkflow() throws Exception {
    long workflowId = createTestWorkflow();
    try {
        WorkflowEdit editWorkflow = new WorkflowEdit(getEnvironment().getWorkflow(workflowId));
        editWorkflow.setName(StringUtils.reverse(WORKFLOW_NAME));
        editWorkflow.setDescription(StringUtils.reverse(WORKFLOW_DESCRIPTION));
        editWorkflow.getSteps().add(new StepEdit(
                new Step(-1, StepDefinition.EDIT_STEP_ID, editWorkflow.getId(), myWorkflowACL.getId())));
        editWorkflow.getSteps().add(new StepEdit(
                new Step(-2, StepDefinition.LIVE_STEP_ID, editWorkflow.getId(), myWorkflowACL.getId())));
        editWorkflow.getRoutes().add(new Route(-1, UserGroup.GROUP_EVERYONE, -1, -2));
        workflowEngine.update(editWorkflow);

        // revert step order
        editWorkflow = getEnvironment().getWorkflow(editWorkflow.getId()).asEditable();
        final List<StepEdit> steps = Lists.newArrayList();
        for (Step step : editWorkflow.getSteps()) {
            steps.add(step.asEditable());
        }

        Assert.assertEquals(steps.size(), 2);
        Collections.reverse(steps);
        assertStepOrder(steps, editWorkflow.getSteps(), false);

        // update workflow
        editWorkflow.setSteps(steps);
        workflowEngine.update(editWorkflow);

        editWorkflow = getEnvironment().getWorkflow(editWorkflow.getId()).asEditable();
        // order should have been preserved
        assertStepOrder(editWorkflow.getSteps(), steps, true);

        // remove and add edit step
        for (Step step : editWorkflow.getSteps()) {
            if (step.getStepDefinitionId() == StepDefinition.EDIT_STEP_ID) {
                editWorkflow.getSteps().remove(step);
                break;
            }
        }
        // route from/to new step (created after this statement) to remaining live step
        editWorkflow.getRoutes()
                .add(new Route(-1, UserGroup.GROUP_OWNER, -1, editWorkflow.getSteps().get(0).getId()));
        editWorkflow.getRoutes()
                .add(new Route(-2, UserGroup.GROUP_OWNER, editWorkflow.getSteps().get(0).getId(), -1));
        // create step for route
        editWorkflow.getSteps().add(new StepEdit(
                new Step(-1, StepDefinition.EDIT_STEP_ID, editWorkflow.getId(), myWorkflowACL.getId())));
        workflowEngine.update(editWorkflow);

        Workflow workflow = getEnvironment().getWorkflow(workflowId);
        Assert.assertTrue(getUserTicket().isInRole(Role.WorkflowManagement),
                "User is not in role workflow management - call should have failed.");
        Assert.assertTrue(StringUtils.reverse(WORKFLOW_NAME).equals(workflow.getName()),
                "Workflow name not updated properly.");
        Assert.assertTrue(StringUtils.reverse(WORKFLOW_DESCRIPTION).equals(workflow.getDescription()),
                "Workflow description not updated properly.");
        Assert.assertTrue(workflow.getSteps().size() == 2,
                "Unexpected number of workflow steps: " + workflow.getSteps().size());
        Assert.assertTrue(workflow.getRoutes().size() == 3,
                "Unexpected number of workflow routes: " + workflow.getRoutes());
    } finally {
        // cleanup
        workflowEngine.remove(workflowId);
    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.db.TagDAOImplTest.java

private static DeviceEntity createRandomDeviceEntity(AppEntity appEntity, String 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(DEVICE_ID_PREFIX + "_" + index);
    deviceEntity.setPhoneNumber("+213" + RandomStringUtils.randomNumeric(7));
    deviceEntity.setPhoneNumberRev(StringUtils.reverse(deviceEntity.getPhoneNumber()));
    DBTestUtil.getDeviceDAO().persist(deviceEntity);
    deviceEntityList.add(deviceEntity);/*from w  w  w  .  j a  v a  2s  . com*/
    return deviceEntity;
}

From source file:aldenjava.opticalmapping.Cigar.java

public static String reverse(String cigar) {
    String precigar = Cigar.convertpreCIGAR(cigar);
    precigar = StringUtils.reverse(precigar);
    return Cigar.convertCIGAR(precigar);
}

From source file:gov.jgi.meta.sequence.SequenceStringCompress.java

/**
 * Merge two bytearrays into one// w w w.j a  va 2  s.c  o m
 * --lanhin
 */
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);
}

From source file:edu.monash.merc.dto.tl.TLSearchBean.java

private int combinateDBSToken() {
    String ds_selected = "1";
    String none_ds_selected = "0";
    String token = none_ds_selected;

    if (this.nxDbSelected) {
        token = ds_selected;/*from  ww w. j ava 2s  .  c  o m*/
    }

    if (this.gpmDbSelected) {
        token = token + ds_selected;
    } else {
        token = token + none_ds_selected;
    }
    if (this.hpaDbSelected) {
        token = token + ds_selected;
    } else {
        token = token + none_ds_selected;
    }
    if (this.bcDbSelected) {
        token = token + ds_selected;
    } else {
        token = token + none_ds_selected;
    }

    return Integer.valueOf(StringUtils.reverse(token));
}

From source file:at.pagu.soldockr.core.query.CriteriaTest.java

@Test
public void testRegisterAlternateConverter() {
    Criteria criteria = new Criteria("field_1").is(100);
    criteria.registerConverter(new Converter<Number, String>() {

        @Override//from w  w  w  . ja v  a 2s .  c om
        public String convert(Number arg0) {
            return StringUtils.reverse(arg0.toString());
        }

    });
    Assert.assertEquals("field_1:001", criteria.createQueryString());
}

From source file:mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer.java

private Set<String> unrollWildcard(String string, boolean reverse) throws IOException {
    Scanner termTableScan = getScanner(ConfigUtils.getFreeTextTermTablename(conf));

    Set<String> unrolledTerms = new HashSet<String>();

    Text queryTerm;/*  w w w  .  j ava  2  s.c o m*/
    if (reverse) {
        String t = StringUtils.removeStart(string, "*").toLowerCase();
        queryTerm = ColumnPrefixes.getRevTermListColFam(t);
    } else {
        String t = StringUtils.removeEnd(string, "*").toLowerCase();
        queryTerm = ColumnPrefixes.getTermListColFam(t);
    }

    // perform query and read results
    termTableScan.setRange(Range.prefix(queryTerm));

    for (Entry<Key, Value> e : termTableScan) {
        String term = ColumnPrefixes.removePrefix(e.getKey().getRow()).toString();
        if (reverse) {
            unrolledTerms.add(StringUtils.reverse(term));
        } else {
            unrolledTerms.add(term);
        }
    }

    if (unrolledTerms.isEmpty()) {
        // put in a placeholder term that will never be in the index.
        unrolledTerms.add("\1\1\1");
    }

    return unrolledTerms;
}

From source file:com.flexive.tests.embedded.WorkflowTest.java

/**
 * Tests step definition updates//from  w  ww .  j  a va2  s .co m
 *
 * @throws FxApplicationException if an error occured
 */
@Test
public void updateStepDefinition() throws FxApplicationException {
    long stepDefinitionId = -1;
    try {
        stepDefinitionId = createStepDefinition(null);
        Assert.assertTrue(stepDefinitionId != -1, "Failed to create step definition");
        StepDefinition stepDefinition = getEnvironment().getStepDefinition(stepDefinitionId);
        Assert.assertTrue(new FxString(STEPDEF_NAME).equals(stepDefinition.getLabel()),
                "Invalid label: " + stepDefinition.getLabel());
        Assert.assertTrue(STEPDEF_NAME.equals(stepDefinition.getName()),
                "Invalid name: " + stepDefinition.getName());
        StepDefinitionEdit definitionEdit = new StepDefinitionEdit(stepDefinition);
        definitionEdit.setName(StringUtils.reverse(stepDefinition.getName()));
        FxString label = new FxString(STEPDEF_NAME);
        label.setTranslation(label.getDefaultLanguage(), StringUtils.reverse(label.getDefaultTranslation()));
        definitionEdit.setLabel(label);
        stepDefinitionEngine.update(definitionEdit);
        stepDefinition = getEnvironment().getStepDefinition(stepDefinitionId);
        Assert.assertTrue(StringUtils.reverse(STEPDEF_NAME).equals(stepDefinition.getName()),
                "Invalid name: " + stepDefinition.getName());
        Assert.assertTrue(label.equals(stepDefinition.getLabel()),
                "Invalid label: " + stepDefinition.getLabel());
    } finally {
        if (stepDefinitionId != -1) {
            stepDefinitionEngine.remove(stepDefinitionId);
        }
    }
}

From source file:aldenjava.opticalmapping.data.mappingresult.OptMapResultNode.java

private void trimResult(int step) {
    String precigar = cigar.getPrecigar();
    if (step == 0) {
        // updateMSP();
        return;//w w w .  j  ava2  s .  c o  m
    } else if (step < 0) // right to left trim, according to ref
        precigar = StringUtils.reverse(precigar);
    if (precigar.length() == 1) // will trim to nothing, cannot trim anymore
        return;
    String removed = precigar.substring(0, precigar.indexOf('M', 1));
    ;
    int m = 0;
    int i = 0;
    int d = 0;
    for (char c : removed.toCharArray())
        switch (c) {
        case 'M':
            m++;
            break;
        case 'I':
            i++;
            break;
        case 'D':
            d++;
            break;
        default:
            break;
        }
    if (step > 0) {
        subrefstart += m + d;
        if (mappedstrand == -1)
            subfragstart -= m + i; // + or -
        else
            subfragstart += m + i;
    } else {
        subrefstop -= m + d; // + or -
        if (mappedstrand == -1)
            subfragstop += m + i;
        else
            subfragstop -= m + i; // + or -
    }
    String newprecigar = precigar.substring(precigar.indexOf('M', 1), precigar.length());
    if (step < 0)
        newprecigar = StringUtils.reverse(newprecigar);
    this.cigar = new Cigar(newprecigar);
    trimResult(step - Math.abs(step) / step);
}

From source file:org.apache.accumulo.examples.wikisearch.ingest.WikipediaMapper.java

@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    Article article = extractor//from w ww .  j a  v  a 2  s  .  com
            .extract(new InputStreamReader(new ByteArrayInputStream(value.getBytes()), UTF8));
    String NULL_BYTE = "\u0000";
    String colfPrefix = language + NULL_BYTE;
    String indexPrefix = "fi" + NULL_BYTE;
    if (article != null) {
        int groupId = WikipediaMapper.getPartitionId(article, numGroups);
        if (groupId != myGroup)
            return;
        Text partitionId = new Text(Integer.toString(WikipediaMapper.getPartitionId(article, numPartitions)));

        // Create the mutations for the document.
        // Row is partition id, colf is language0articleid, colq is fieldName\0fieldValue
        Mutation m = new Mutation(partitionId);
        for (Entry<String, Object> entry : article.getFieldValues().entrySet()) {
            m.put(colfPrefix + article.getId(), entry.getKey() + NULL_BYTE + entry.getValue().toString(), cv,
                    article.getTimestamp(), NULL_VALUE);
            // Create mutations for the metadata table.
            String metadataKey = entry.getKey() + METADATA_EVENT_COLUMN_FAMILY + language;
            if (!metadataSent.contains(metadataKey)) {
                Mutation mm = new Mutation(entry.getKey());
                mm.put(METADATA_EVENT_COLUMN_FAMILY, language, cv, article.getTimestamp(), NULL_VALUE);
                context.write(metadataTableName, mm);
                metadataSent.add(metadataKey);
            }
        }

        // Tokenize the content
        Set<String> tokens = getTokens(article);

        // We are going to put the fields to be indexed into a multimap. This allows us to iterate
        // over the entire set once.
        Multimap<String, String> indexFields = HashMultimap.create();
        // Add the normalized field values
        LcNoDiacriticsNormalizer normalizer = new LcNoDiacriticsNormalizer();
        for (Entry<String, String> index : article.getNormalizedFieldValues().entrySet())
            indexFields.put(index.getKey(), index.getValue());
        // Add the tokens
        for (String token : tokens)
            indexFields.put(TOKENS_FIELD_NAME, normalizer.normalizeFieldValue("", token));

        for (Entry<String, String> index : indexFields.entries()) {
            // Create mutations for the in partition index
            // Row is partition id, colf is 'fi'\0fieldName, colq is fieldValue\0language\0article id
            m.put(indexPrefix + index.getKey(), index.getValue() + NULL_BYTE + colfPrefix + article.getId(), cv,
                    article.getTimestamp(), NULL_VALUE);

            // Create mutations for the global index
            // Create a UID object for the Value
            Builder uidBuilder = Uid.List.newBuilder();
            uidBuilder.setIGNORE(false);
            uidBuilder.setCOUNT(1);
            uidBuilder.addUID(Integer.toString(article.getId()));
            Uid.List uidList = uidBuilder.build();
            Value val = new Value(uidList.toByteArray());

            // Create mutations for the global index
            // Row is field value, colf is field name, colq is partitionid\0language, value is Uid.List object
            Mutation gm = new Mutation(index.getValue());
            gm.put(index.getKey(), partitionId + NULL_BYTE + language, cv, article.getTimestamp(), val);
            context.write(indexTableName, gm);

            // Create mutations for the global reverse index
            Mutation grm = new Mutation(StringUtils.reverse(index.getValue()));
            grm.put(index.getKey(), partitionId + NULL_BYTE + language, cv, article.getTimestamp(), val);
            context.write(reverseIndexTableName, grm);

            // Create mutations for the metadata table.
            String metadataKey = index.getKey() + METADATA_INDEX_COLUMN_FAMILY + language;
            if (!metadataSent.contains(metadataKey)) {
                Mutation mm = new Mutation(index.getKey());
                mm.put(METADATA_INDEX_COLUMN_FAMILY,
                        language + NULL_BYTE + LcNoDiacriticsNormalizer.class.getName(), cv,
                        article.getTimestamp(), NULL_VALUE);
                context.write(metadataTableName, mm);
                metadataSent.add(metadataKey);
            }
        }
        // Add the entire text to the document section of the table.
        // row is the partition, colf is 'd', colq is language\0articleid, value is Base64 encoded GZIP'd document
        m.put(DOCUMENT_COLUMN_FAMILY, colfPrefix + article.getId(), cv, article.getTimestamp(),
                new Value(Base64.encodeBase64(article.getText().getBytes())));
        context.write(tablename, m);

    } else {
        context.getCounter("wikipedia", "invalid articles").increment(1);
    }
    context.progress();
}