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:org.oscarehr.PMmodule.exporter.DATISAgencyInformation.java

@Override
protected String exportData() throws ExportException {
    List<IntakeNode> intakeNodes = intake.getNode().getChildren();
    StringBuilder buf = new StringBuilder();

    IntakeNode agInfoNode = null;//w  w  w .  jav  a2s.  co m

    for (IntakeNode inode : intakeNodes) {
        if (inode.getLabelStr().startsWith(FILE_PREFIX)) {
            agInfoNode = inode;
            break;
        }
    }

    Set<IntakeAnswer> answers = intake.getAnswers();

    int counter = 0;
    for (IntakeAnswer ans : answers) {
        if (counter == fields.size()) {
            break;
        }
        if (ans.getNode().getParent().equals(agInfoNode)) {
            final String lbl = ans.getNode().getLabelStr().toUpperCase();
            DATISField found = (DATISField) CollectionUtils.find(fields, new Predicate() {

                public boolean evaluate(Object arg0) {
                    DATISField field = (DATISField) arg0;
                    if (lbl.startsWith(field.getName())) {
                        return true;
                    }
                    return false;
                }

            });

            if (found != null) {
                writeCSV(buf, ans, found);
                //writeData(buf, ans, found);
                counter++;
            }
        }
    }

    if (buf.lastIndexOf(",") == -1) {
        return buf.toString();
    }

    return buf.substring(0, buf.lastIndexOf(",")).toString();
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.dao.UUIDDAOImpl.java

/**
 * process the sequential union clause needed for the multiple barcode/uuid mapping query
 *
 * @param maxParameter    max size of underlying list of arguments
 * @param name            name of element to select, uuid or barcode here
 * @param caseSensitivity lowe, upper or normal
 * @return fully constructed query arguments
 *///from  w  ww  .  j a v a2  s.  co m
protected String processUnionClause(int maxParameter, final String name,
        final StringUtil.CaseSensitivity caseSensitivity) {
    final StringBuilder placeHolderString = new StringBuilder();
    for (int i = 0; i < maxParameter; i++) {

        switch (caseSensitivity) {
        case CASE_SENSITIVE:
            placeHolderString.append("select ? as " + name + " from dual union ");
            break;
        case LOWER_CASE:
            placeHolderString.append("select lower(?) as " + name + " from dual union ");
            break;
        case UPPER_CASE:
            placeHolderString.append("select upper(?) as " + name + " from dual union ");
            break;
        }
    }
    placeHolderString.delete(placeHolderString.lastIndexOf(" union "), placeHolderString.length());
    return placeHolderString.toString();
}

From source file:org.oscarehr.PMmodule.exporter.DATISProgramInformation.java

@Override
protected String exportData() throws ExportException {
    List<IntakeNode> intakeNodes = intake.getNode().getChildren();
    StringBuilder buf = new StringBuilder();

    IntakeNode file4Node = null;//from w  w  w  .j  a  v a2 s  .com

    for (IntakeNode inode : intakeNodes) {
        if (inode.getLabelStr().startsWith(FILE_PREFIX)) {
            file4Node = inode;
            break;
        }
    }

    Set<IntakeAnswer> answers = intake.getAnswers();

    int counter = 0;
    for (IntakeAnswer ans : answers) {
        if (counter == fields.size()) {
            break;
        }
        if (ans.getNode().getGrandParent().equals(file4Node)) {
            final String lbl = ans.getNode().getParent().getLabelStr().toUpperCase();
            DATISField found = (DATISField) CollectionUtils.find(fields, new Predicate() {

                public boolean evaluate(Object arg0) {
                    DATISField field = (DATISField) arg0;
                    if (lbl.startsWith(field.getName())) {
                        return true;
                    }
                    return false;
                }

            });

            if (found != null) {
                writeCSV(buf, ans, found);
                //writeData(buf, ans, found);
                counter++;
            }
        }
    }

    if (buf.lastIndexOf(",") == -1) {
        return buf.toString();
    }

    return buf.substring(0, buf.lastIndexOf(",")).toString();
}

From source file:org.exoplatform.services.ecm.publication.REST.presentation.document.edit.GetEditedDocumentRESTService.java

private List<DocumentNode> getDocumentData(List<Node> lstNode, String noOfItem) throws Exception {
    if (lstNode == null || lstNode.size() == 0)
        return null;
    List<DocumentNode> lstDocNode = new ArrayList<DocumentNode>();
    DocumentNode docNode = null;// w  w  w  . j ava 2s. c  o m
    StringBuilder tags = null;

    Collections.sort(lstNode,
            new PropertyValueComparator(DATE_MODIFIED, PropertyValueComparator.DESCENDING_ORDER));
    ManageableRepository manageableRepository = repositoryService.getCurrentRepository();
    List<DriveData> lstDrive = manageDriveService.getAllDrives();
    for (Node node : lstNode) {
        docNode = new DocumentNode();
        docNode.setName(node.getName());
        docNode.setPath(node.getPath());
        docNode.setLastAuthor(node.getProperty(EXO_OWNER).getString());
        docNode.setLstAuthor(node.getProperty(EXO_OWNER).getString());
        docNode.setDateEdited(getDateFormat(node.getProperty(DATE_MODIFIED).getDate()));
        tags = new StringBuilder(1024);

        List<Node> tagList = newFolksonomyService.getLinkedTagsOfDocumentByScope(NewFolksonomyService.PUBLIC,
                "", node, manageableRepository.getConfiguration().getDefaultWorkspaceName());
        for (Node tag : tagList) {
            tags.append(tag.getName()).append(", ");
        }

        if (tags.lastIndexOf(",") > 0) {
            tags.delete(tags.lastIndexOf(","), tags.length());
        }

        docNode.setTags(tags.toString());
        docNode.setDriveName(getDriveName(lstDrive, node));
        if (lstDocNode.size() < Integer.parseInt(noOfItem))
            lstDocNode.add(docNode);
    }
    return lstDocNode;
}

From source file:DataAn.reportManager.service.impl.ReportServiceImpl.java

@Override
public String getParentFSCatalog(long dirId) {
    List<ReportFileSystem> list = new ArrayList<ReportFileSystem>();
    ReportFileSystem fs = fileDao.get(dirId);
    list.add(fs);//from w w w  .  j  a va 2 s .com
    Long parentId = fs.getParentId();
    while (parentId != null) {
        ReportFileSystem parentFs = fileDao.get(parentId);
        list.add(parentFs);
        parentId = parentFs.getParentId();
    }
    Collections.reverse(list);
    StringBuilder sb = new StringBuilder();
    sb.append("{");
    for (ReportFileSystem f : list) {
        sb.append("\"" + f.getId().toString() + "\"" + ":" + "\"" + f.getFileName() + "\"" + ",");
    }
    if (sb.lastIndexOf(",") != -1) {
        sb.deleteCharAt(sb.lastIndexOf(","));
    }
    sb.append("}");
    return sb.toString();
}

From source file:net.sf.jabref.sql.exporter.DatabaseExporter.java

/**
 * Generates the SQL required to populate the entry_types table with jabref data.
 *
 * @param out  The output (PrintSream or Connection) object to which the DML should be written.
 * @param type//from   w w  w  . ja  v  a2  s. com
 */

private void populateEntryTypesTable(Connection out, BibDatabaseMode type) throws SQLException {
    List<String> fieldRequirement = new ArrayList<>();

    List<String> existentTypes = new ArrayList<>();
    try (Statement sm = out.createStatement();
            ResultSet rs = sm.executeQuery("SELECT label FROM entry_types")) {
        while (rs.next()) {
            existentTypes.add(rs.getString(1));
        }
    }
    for (EntryType val : EntryTypes.getAllValues(type)) {
        StringBuilder querySB = new StringBuilder();

        fieldRequirement.clear();
        for (int i = 0; i < SQLUtil.getAllFields().size(); i++) {
            fieldRequirement.add(i, "gen");
        }
        List<String> reqFields = val.getRequiredFieldsFlat();
        List<String> optFields = val.getOptionalFields();
        List<String> utiFields = Collections.singletonList("search");
        fieldRequirement = SQLUtil.setFieldRequirement(SQLUtil.getAllFields(), reqFields, optFields, utiFields,
                fieldRequirement);
        if (existentTypes.contains(val.getName().toLowerCase())) {
            String[] update = SQLUtil.getFieldStr().split(",");
            querySB.append("UPDATE entry_types SET \n");
            for (int i = 0; i < fieldRequirement.size(); i++) {
                querySB.append(update[i]).append("='").append(fieldRequirement.get(i)).append("',");
            }
            querySB.delete(querySB.lastIndexOf(","), querySB.length());
            querySB.append(" WHERE label='").append(val.getName().toLowerCase()).append("';");
        } else {
            querySB.append("INSERT INTO entry_types (label, ").append(SQLUtil.getFieldStr())
                    .append(") VALUES ('").append(val.getName().toLowerCase()).append('\'');
            for (String aFieldRequirement : fieldRequirement) {
                querySB.append(", '").append(aFieldRequirement).append('\'');
            }
            querySB.append(");");
        }
        SQLUtil.processQuery(out, querySB.toString());
    }
}

From source file:org.dasein.cloud.cloudstack.CSMethod.java

public String buildUrl(String command, Param... params) throws CloudException, InternalException {
    ProviderContext ctx = provider.getContext();

    String apiShared = "";
    String apiSecret = "";
    try {//  w ww .j  a v a  2s .  c  o  m
        List<ContextRequirements.Field> fields = provider.getContextRequirements().getConfigurableValues();
        for (ContextRequirements.Field f : fields) {
            if (f.type.equals(ContextRequirements.FieldType.KEYPAIR)) {
                byte[][] keyPair = (byte[][]) ctx.getConfigurationValue(f);
                apiShared = new String(keyPair[0], "utf-8");
                apiSecret = new String(keyPair[1], "utf-8");
            }
        }
    } catch (UnsupportedEncodingException ignore) {
    }

    if (ctx == null) {
        throw new CloudException("No context was set for this request");
    }
    try {
        StringBuilder str = new StringBuilder();
        String apiKey = apiShared;
        String accessKey = apiSecret;

        StringBuilder newKey = new StringBuilder();
        for (int i = 0; i < apiKey.length(); i++) {
            char c = apiKey.charAt(i);

            if (c != '\r') {
                newKey.append(c);
            }
        }
        apiKey = newKey.toString();
        newKey = new StringBuilder();
        for (int i = 0; i < accessKey.length(); i++) {
            char c = accessKey.charAt(i);

            if (c != '\r') {
                newKey.append(c);
            }
        }
        accessKey = newKey.toString();
        str.append(ctx.getCloud().getEndpoint());

        // Make sure the url ends up exactly as http://x.x.x.x:y/client/api?command=
        // otherwise the server may choke like we've found it does for uploadSslCert command.
        while (str.lastIndexOf("/") == str.length() - 1) {
            str.deleteCharAt(str.length() - 1);
        }
        if (!str.toString().endsWith("/api")) {
            str.append("/api");
        }
        str.append("?command=");
        str.append(command);
        for (Param param : params) {
            str.append("&");
            str.append(param.getKey());
            if (param.getValue() != null) {
                str.append("=");
                str.append(URLEncoder.encode(param.getValue(), "UTF-8").replaceAll("\\+", "%20"));
            }
        }
        str.append("&apiKey=");
        str.append(URLEncoder.encode(apiKey, "UTF-8").replaceAll("\\+", "%20"));
        str.append("&signature=");
        try {
            str.append(URLEncoder.encode(getSignature(command, apiKey, accessKey, params), "UTF-8")
                    .replaceAll("\\+", "%20"));
        } catch (SignatureException e) {
            throw new InternalException(e);
        }
        return str.toString();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new RuntimeException("This cannot happen: " + e.getMessage());
    }
}

From source file:com.safasoft.treeweb.controller.DataControllerKeypro.java

/**
 * Generate table content of column list
 * @param tableName// www  .  ja  v a 2  s .  c o m
 * @param whereClause
 * @param pageNo
 * @return table content object
 */
@RequestMapping(value = "/content", method = RequestMethod.POST)
public @ResponseBody TableContentKeypro getListColumn(@RequestParam("tableName") String tableName,
        @RequestParam("whereClause") String whereClause, @RequestParam("pageNo") Integer pageNo) {
    logger.debug("Received request to get table content");
    //generate column select statement, order by statement (limited to 5 columns only)
    //tranform each column type into character type before execution
    StringBuilder sbColumnSelect = new StringBuilder();
    int orderByLimit = 5;
    StringBuilder sbOrderBy = new StringBuilder();
    SupportService suppServ = new SessionUtil<SupportService>().getAppContext("supportService");
    List<ColumnProp> listColumn = suppServ.getListColumn(tableName);
    for (int idx = 0; idx < orderByLimit; idx++)
        sbOrderBy.append(listColumn.get(idx).getColumnName()).append(COLUMN_DELIMITER);
    for (int idx = 0; idx < listColumn.size(); idx++) {
        String columnName;
        if (listColumn.get(idx).getDataType().equals("DATE"))
            columnName = "TO_CHAR(" + listColumn.get(idx).getColumnName() + ",'DD-MON-YYYY')";
        else if (listColumn.get(idx).getDataType().equals("NUMBER"))
            columnName = "TO_CHAR(" + listColumn.get(idx).getColumnName() + ")";
        else
            columnName = listColumn.get(idx).getColumnName();
        sbColumnSelect.append(columnName).append(" col").append(idx + 1).append(COLUMN_DELIMITER);
    }
    for (int idx = listColumn.size(); idx < MAX_COLUMN_DATA; idx++)
        sbColumnSelect.append("NULL col").append(idx + 1).append(COLUMN_DELIMITER);
    sbColumnSelect.deleteCharAt(sbColumnSelect.lastIndexOf(COLUMN_DELIMITER));
    sbOrderBy.deleteCharAt(sbOrderBy.lastIndexOf(COLUMN_DELIMITER));
    //set table content
    TableContentKeypro tc = new TableContentKeypro();
    tc.setColumns(listColumn);
    tc.setData(suppServ.getListTableValue(tableName, sbColumnSelect.toString(), whereClause,
            sbOrderBy.toString(), pageNo));
    tc.setRecordCount(suppServ.getRecordCount(tableName, whereClause));
    tc.setOrderBy(sbOrderBy.toString());
    return tc;
}

From source file:net.sf.jabref.sql.exporter.DBExporter.java

/**
 * Generates the SQL required to populate the entry_types table with jabref data.
 *
 * @param out The output (PrintSream or Connection) object to which the DML should be written.
 * @param type/*from w w w. j a v  a  2s  .c  o  m*/
 */

private void populateEntryTypesTable(Object out, BibDatabaseMode type) throws SQLException {
    List<String> fieldRequirement = new ArrayList<>();

    List<String> existentTypes = new ArrayList<>();
    if (out instanceof Connection) {
        try (Statement sm = (Statement) SQLUtil.processQueryWithResults(out, "SELECT label FROM entry_types");
                ResultSet rs = sm.getResultSet()) {
            while (rs.next()) {
                existentTypes.add(rs.getString(1));
            }
        }
    }
    for (EntryType val : EntryTypes.getAllValues(type)) {
        StringBuilder querySB = new StringBuilder();

        fieldRequirement.clear();
        for (int i = 0; i < SQLUtil.getAllFields().size(); i++) {
            fieldRequirement.add(i, "gen");
        }
        List<String> reqFields = val.getRequiredFieldsFlat();
        List<String> optFields = val.getOptionalFields();
        List<String> utiFields = Collections.singletonList("search");
        fieldRequirement = SQLUtil.setFieldRequirement(SQLUtil.getAllFields(), reqFields, optFields, utiFields,
                fieldRequirement);
        if (existentTypes.contains(val.getName().toLowerCase())) {
            String[] update = fieldStr.split(",");
            querySB.append("UPDATE entry_types SET \n");
            for (int i = 0; i < fieldRequirement.size(); i++) {
                querySB.append(update[i]).append("='").append(fieldRequirement.get(i)).append("',");
            }
            querySB.delete(querySB.lastIndexOf(","), querySB.length());
            querySB.append(" WHERE label='").append(val.getName().toLowerCase()).append("';");
        } else {
            querySB.append("INSERT INTO entry_types (label, ").append(fieldStr).append(") VALUES ('")
                    .append(val.getName().toLowerCase()).append('\'');
            for (String aFieldRequirement : fieldRequirement) {
                querySB.append(", '").append(aFieldRequirement).append('\'');
            }
            querySB.append(");");
        }
        SQLUtil.processQuery(out, querySB.toString());
    }
}

From source file:org.pentaho.mantle.rebind.EventBusUtilGenerator.java

String addHandlerParamJson(JClassType type) {
    StringBuilder json = new StringBuilder(128);
    json.append('"').append('{');
    JMethod[] methods = type.getMethods();
    for (JMethod eventMethod : methods) {

        if (eventMethod.isPublic() && !eventMethod.isStatic() && (eventMethod.isConstructor() == null)
                && !"void".equalsIgnoreCase(eventMethod.getReturnType().getSimpleSourceName())
                && !eventMethod.getName().equals("getAssociatedType")) {
            // let's add the property to JSON object
            String propertyName = StringUtils.uncapitalize(eventMethod.getName().substring(3));
            String simpleType = type.getField(propertyName).getType().getSimpleSourceName();
            if ("string".equalsIgnoreCase(simpleType)) {
                json.append(//from  www.  j a va 2s  .  co m
                        "\\\"" + propertyName + "\\\":\\\"\" + event." + eventMethod.getName() + "() + \"\\\"");
            } else {
                json.append("\\\"" + propertyName + "\\\":\" + event." + eventMethod.getName() + "() + \"");
            }
            json.append(',');
        }
    }

    int lastIndex = json.lastIndexOf(",");
    if (lastIndex == -1) {
        json.append('}');
    } else {
        json.setCharAt(lastIndex, '}');
    }
    return json.append('"').toString();
}