Example usage for java.lang StringBuilder lastIndexOf

List of usage examples for java.lang StringBuilder lastIndexOf

Introduction

In this page you can find the example usage for java.lang StringBuilder lastIndexOf.

Prototype

@Override
    public int lastIndexOf(String str) 

Source Link

Usage

From source file:com.raja.knowme.FragmentReferences.java

private void setUIData(int count) {
    mHeaderSwitcher.setText(mReferencesDetails.get(count).getHeader());
    StringBuilder sb = new StringBuilder();
    for (int counter = 0; counter < mReferencesDetails.get(count).getDetailsData().size(); counter++)
        sb.insert(sb.lastIndexOf(sb.toString()),
                mReferencesDetails.get(count).getDetailsData().get(counter) + "\n\n");
    mBodySwitcher.setText(sb.toString());
}

From source file:org.egov.egf.web.actions.masters.BankAction.java

public String getBankAccountTypesJSON() {
    final StringBuilder bankAcTypesJson = new StringBuilder(":;");
    for (final BankAccountType value : BankAccountType.values())
        bankAcTypesJson.append(value.name()).append(":").append(value.name()).append(";");
    bankAcTypesJson.deleteCharAt(bankAcTypesJson.lastIndexOf(";"));
    return bankAcTypesJson.toString();
}

From source file:org.jasig.ssp.util.importer.job.staging.PostgresExternalTableUpsertWriter.java

@Override
public void write(List<? extends RawItem> items) throws Exception {

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    List<String> batchedStatements = new ArrayList<String>();

    String fileName = items.get(0).getResource().getFilename();
    String[] fileNameSplit = fileName.split("\\.");
    String tableName = fileNameSplit[0];

    Object batchStart = stepExecution.getExecutionContext().get("batchStart");
    Object batchStop = stepExecution.getExecutionContext().get("batchStop");

    RawItem item = items.get(0);/*from  w  w w.j  ava  2s. c  o  m*/
    if (currentResource == null) {
        this.orderedHeaders = writeHeader(items.get(0));
        this.currentResource = items.get(0).getResource();
    }
    Resource itemResource = item.getResource();
    if (!(this.currentResource.equals(itemResource))) {
        this.orderedHeaders = writeHeader(item);
        this.currentResource = itemResource;
    }
    StringBuilder updateSql = new StringBuilder();
    updateSql.append(" UPDATE " + tableName + " AS target SET ");
    for (String header : this.orderedHeaders) {
        updateSql.append(header + "=source." + header + ",");
    }
    updateSql.deleteCharAt(updateSql.lastIndexOf(","));
    updateSql.append(" FROM stg_" + tableName + " AS source WHERE ");
    List<String> tableKeys = metadataRepository.getRepository().getColumnMetadataRepository()
            .getTableMetadata(new TableReference(tableName)).getTableKeys();

    // There are a few external tables that don't (yet) have natural keys,
    // in these cases we've enforced the key on the staging table
    // so in cases where the external table does not have any keys, we look
    // towards the corresponding staging table for them
    if (tableKeys.isEmpty()) {
        tableKeys = metadataRepository.getRepository().getColumnMetadataRepository()
                .getTableMetadata(new TableReference("stg_" + tableName)).getTableKeys();
    }
    for (String key : tableKeys) {
        updateSql.append(" target." + key + " = source." + key + " AND ");
    }
    updateSql.append(" source.batch_id >= " + batchStart + " and source.batch_id <= " + batchStop + ";");
    batchedStatements.add(updateSql.toString());
    sayQuery(updateSql);

    StringBuilder insertSql = new StringBuilder();
    insertSql.append(" INSERT INTO " + tableName + "(");
    for (String header : this.orderedHeaders) {
        insertSql.append(header + ",");
    }
    insertSql.setLength(insertSql.length() - 1); // trim comma

    insertSql.append(") SELECT ");
    for (String header : this.orderedHeaders) {
        insertSql.append(" source." + header).append(",");
    }
    insertSql.setLength(insertSql.length() - 1); // trim comma
    insertSql.append(" FROM stg_" + tableName + " AS source ");
    insertSql.append(" LEFT OUTER JOIN " + tableName + " AS target ON ");
    for (String key : tableKeys) {
        insertSql.append(" source." + key + " = target." + key + " AND");
    }
    insertSql.setLength(insertSql.length() - 3); // trim comma
    insertSql.append(" WHERE ");
    for (String key : tableKeys) {
        insertSql.append(" target." + key + " IS NULL AND ");
    }
    insertSql.append(" source.batch_id >= " + batchStart + " and source.batch_id <= " + batchStop + "");

    batchedStatements.add(insertSql.toString());
    sayQuery(insertSql);
    try {
        int[] results = jdbcTemplate.batchUpdate(batchedStatements.toArray(new String[] {}));

        Integer numInsertedUpdated = (Integer) stepExecution.getExecutionContext().get("numInsertedUpdated");
        numInsertedUpdated = numInsertedUpdated == null ? 0 : numInsertedUpdated;
        numInsertedUpdated = numInsertedUpdated + results[0] + results[1];
        stepExecution.getExecutionContext().put("numInsertedUpdated", numInsertedUpdated);
    } catch (Exception e) {
        throw new NotSkippableException(e);
    }
}

From source file:org.sufficientlysecure.keychain.gm.GmAccessibilityService.java

private String fixContentDescription(AccessibilityNodeInfo node) {
    String content = node.getContentDescription().toString();

    // NOTE: Unfortunately, line breaks are missing from content description, thus
    // we are reformatting now:

    // TODO: get charset from header?

    // find "hQ", start of pgp message (0x80 byte) and remove everything before
    content = content.replaceFirst(".*hQ", "hQ");

    StringBuilder builder = new StringBuilder(content);

    // re-add -----BEGIN PGP MESSAGE-----
    String header = BEGIN_PGP_MESSAGE + "\n\n";
    builder.insert(0, header);/*from w ww.j  av a 2 s  . c o m*/

    int indexOfEnd = builder.lastIndexOf(END_PGP_MESSAGE);
    // TODO: check if END pgp message is really inside string! if not -> gmail has cut it!
    builder.insert(indexOfEnd, "\n");
    int i = indexOfEnd - CHECKSUM_LENGTH;
    builder.insert(i, "\n");

    // split into 65 character chunks
    int currentIndex = header.length() + 64;
    while (currentIndex < indexOfEnd) {
        builder.insert(currentIndex, "\n");
        currentIndex += 65;

        // stop where checksum starts
        indexOfEnd = builder.lastIndexOf(END_PGP_MESSAGE) - CHECKSUM_LENGTH - 2;
    }

    content = builder.toString();

    if (Constants.DEBUG) {
        // split for long messages
        for (String line : content.split("\n")) {
            Log.d(Constants.TAG, line);
        }
    }

    return content;
}

From source file:net.sourceforge.vulcan.web.ProjectFileServlet.java

private String getFallbackParentPath(HttpServletRequest request, String workDir) {
    final StringBuilder pathInfo = new StringBuilder(request.getPathInfo());

    while (!getFile(workDir, pathInfo.toString(), true).exists()) {
        pathInfo.delete(pathInfo.lastIndexOf("/"), pathInfo.length());
    }/* ww w. ja v  a  2 s .  c o m*/

    final StringBuilder buf = new StringBuilder(request.getContextPath());
    buf.append(request.getServletPath());
    buf.append(pathInfo);
    buf.append("/");

    return buf.toString();
}

From source file:net.duckling.falcon.api.orm.DAOUtils.java

private String format(StringBuilder sb) {
    if (sb.indexOf(",") > 0) {
        sb.deleteCharAt(sb.lastIndexOf(","));
    }/*w w w.j a va2  s.  co  m*/
    return sb.toString();
}

From source file:au.edu.usq.fascinator.harvester.fedora.restclient.FedoraRestClient.java

private void addParam(StringBuilder uri, Properties options, String name) throws IOException {
    String value = options.getProperty(name);
    if (value != null) {
        char sep = '?';
        if (uri.lastIndexOf("?") > -1) {
            sep = '&';
        }//from   w  w w .  j  a va  2  s.  co  m
        uri.append(sep);
        uri.append(URLEncoder.encode(name, "UTF-8"));
        uri.append("=");
        uri.append(URLEncoder.encode(value, "UTF-8"));
    }
}

From source file:sapience.injectors.stax.inject.StringBasedStaxStreamInjector.java

/**
 * Helper method, takes an XML reference with local namespace definitions, and returns the namespaces as QNames
 * @param xml/*from w w w.ja v a  2s  .c om*/
 * @return
 */
private List<QName> extractNamespaces(String xml) {
    List<QName> res = new ArrayList<QName>();

    Matcher nsMatcher = nsPattern.matcher(xml);
    while (nsMatcher.find()) {
        int start = nsMatcher.start();
        int end = nsMatcher.end();
        StringBuilder sbu = new StringBuilder(xml.substring(start, end));
        String prefix = sbu.substring(sbu.indexOf(":") + 1, sbu.lastIndexOf("="));
        String uri = sbu.substring(sbu.indexOf("\"") + 1, sbu.lastIndexOf("\""));
        res.add(new QName(uri, prefix));
    }
    return res;
}

From source file:org.springframework.cloud.stream.config.BindingProperties.java

public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("destination=" + this.destination);
    sb.append(COMMA);//from  w  w  w  . ja v  a2  s .  co  m
    sb.append("group=" + this.group);
    sb.append(COMMA);
    if (this.contentType != null) {
        sb.append("contentType=" + this.contentType);
        sb.append(COMMA);
    }
    if (this.binder != null) {
        sb.append("binder=" + this.binder);
        sb.append(COMMA);
    }
    sb.deleteCharAt(sb.lastIndexOf(COMMA));
    return "BindingProperties{" + sb.toString() + "}";
}

From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java

protected Locale extractLocale(Resource resource, String suffix) {
    String filename = resource.getFilename();

    StringBuilder locale = new StringBuilder(filename);
    // Find the last part that fits the bundle's name
    int basenameIndex = filename.lastIndexOf(MESSAGES_BUNDLENAME);
    int length = MESSAGES_BUNDLENAME.length();

    // Remove everything before the basename, the basename and one more char to eat the '_'
    locale.delete(0, basenameIndex + length + 1);
    int suffixIndex = locale.lastIndexOf(suffix);
    locale.delete(suffixIndex, locale.length());

    return new Locale(locale.toString());
}