Example usage for java.lang StringBuilder delete

List of usage examples for java.lang StringBuilder delete

Introduction

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

Prototype

@Override
public StringBuilder delete(int start, int end) 

Source Link

Usage

From source file:com.virtusa.akura.staff.controller.SubjectTeacherAssignController.java

/**
 * Once the User selects a Grade from the drop down. findClassesOfGrade will return the classes of the
 * selected grade//from   w w w.j a v  a  2s  .  co  m
 * 
 * @param modelMap of type ModelMap
 * @param request of type HttpServletRequest
 * @return java.lang.String - return string
 * @throws AkuraAppException throw exception if occur.
 */
@ResponseBody
@RequestMapping(value = FINDCLASSES_HTM)
public String findClassesOfGrade(ModelMap modelMap, HttpServletRequest request) throws AkuraAppException {

    StringBuilder allClasses = new StringBuilder();
    String selectedGradeDescription = request.getParameter(SELECTED_VALUE).toString();
    int selectedGradeID = Integer.parseInt(selectedGradeDescription);
    Grade selectedGrade = commonService.findGradeById(selectedGradeID);
    List<ClassGrade> classGrades = commonService.getClassGradeListByGrade(selectedGrade);
    boolean isFirst = true;
    StringBuilder classes = new StringBuilder();

    for (ClassGrade classGrade : classGrades) {
        classes.append(classGrade.getSchoolClass().getDescription());
        classes.append("-");
        classes.append(classGrade.getSchoolClass().getClassId());

        if (isFirst) {
            allClasses.append(classes.toString()); // no comma
            isFirst = false;
        } else {
            allClasses.append(","); // comma
            allClasses.append(classes.toString());
        }
        classes.delete(0, classes.length());
    }
    return allClasses.toString();
}

From source file:com.virtusa.akura.staff.controller.SubjectTeacherAssignController.java

/**
 * Method is to return GradeClass list.//from   w ww . j av  a 2s.com
 * 
 * @param request - HttpServletRequest
 * @param modelMap - ModelMap attribute.
 * @return list of classGrade
 * @throws AkuraAppException - Detailed exception
 */

@ResponseBody
@RequestMapping(value = POPULATE_GRADE_SUBJECT_LIST)
public String populateGradeClass(ModelMap modelMap, HttpServletRequest request) throws AkuraAppException {

    StringBuilder allGradeClass = new StringBuilder();
    int gradeId = Integer.parseInt(request.getParameter(SELECTED_VALUE));
    List<GradeSubject> gradeSubjectList = commonService.getGradeSubjectIdListByGrade(gradeId);
    boolean isFirst = true;
    StringBuilder classes = new StringBuilder();

    for (GradeSubject gradeSubject : gradeSubjectList) {
        classes.append(gradeSubject.getSubject().getDescription());
        classes.append("_");
        classes.append(gradeSubject.getSubject().getSubjectId());

        if (isFirst) {
            allGradeClass.append(classes.toString()); // no comma
            isFirst = false;
        } else {
            allGradeClass.append(","); // comma
            allGradeClass.append(classes.toString());
        }
        classes.delete(0, classes.length());
    }
    return allGradeClass.toString();
}

From source file:net.rptools.maptool.client.functions.StrListFunctions.java

/**
 * <code>listDelete(list, index [,delim])</code>
 * /*w w w.jav a2 s  .  c  om*/
 * @param index
 *            A number from 0 to (list length)-1. Out of range values are ignored.
 * @param delim
 *            An optional list delimiter (default ",")
 * @return A new list with the item at position <code>index</code> deleted.
 */
public Object listDelete(List<Object> parameters, String listStr, String lastParam, List<String> list)
        throws ParameterException {
    Object retval = "";
    String delim = ",";

    int minParams = 2;
    int maxParams = minParams + 1;
    checkVaryingParameters("listDelete()", minParams, maxParams, parameters,
            new Class[] { null, BigDecimal.class, String.class });
    if (parameters.size() == maxParams) {
        delim = lastParam;
    }
    parse(listStr, list, delim);

    int index = ((BigDecimal) parameters.get(1)).intValue();
    StringBuilder sb = new StringBuilder();
    boolean inRange = (index >= 0 && index < list.size());
    for (int i = 0; i < list.size(); i++) {
        if (i != index) {
            sb.append(list.get(i));
            sb.append(delim);
            sb.append(" ");
        }
    }
    if (list.size() > (inRange ? 1 : 0)) {
        // Delete the last delimiter and space
        sb.delete(sb.length() - 1 - delim.length(), sb.length());
    }
    retval = sb.toString();
    return retval;
}

From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClient.java

/**
 * Creates the select query./*from ww w  .  j a  v  a  2 s  . c om*/
 * 
 * @param rowId
 *            the row id
 * @param metadata
 *            the metadata
 * @param tableName
 *            the table name
 * @return the string builder
 */
private StringBuilder createSelectQuery(Object rowId, EntityMetadata metadata, String tableName) {
    MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
            .getMetamodel(metadata.getPersistenceUnit());

    CQLTranslator translator = new CQLTranslator();

    String select_Query = translator.SELECTALL_QUERY;
    select_Query = StringUtils.replace(select_Query, CQLTranslator.COLUMN_FAMILY,
            translator.ensureCase(new StringBuilder(), tableName, false).toString());
    StringBuilder builder = new StringBuilder(select_Query);

    builder.append(CQLTranslator.ADD_WHERE_CLAUSE);
    onWhereClause(metadata, rowId, translator, builder, metaModel, metadata.getIdAttribute());
    builder.delete(builder.lastIndexOf(CQLTranslator.AND_CLAUSE), builder.length());

    return builder;
}

From source file:inti.ws.spring.resource.FilteredWebResource.java

@Override
public void update() throws Exception {
    ExpressionFactory factory;//w  w  w  .  j  av  a  2  s.co  m
    ValueExpression var;
    Object val;
    StringBuilder builder = new StringBuilder(32);
    MessageDigest digest = DIGESTS.get();

    for (WebResource dependency : dependencies) {
        dependency.updateIfNeeded();
    }

    super.update();

    factory = ExpressionFactory.newInstance();
    content = factory.createValueExpression(context, compressedFile, String.class);
    for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
        var = factory.createValueExpression(context, "${" + parameter.getKey() + '}', String.class);
        val = parameter.getValue();
        if (val instanceof WebResource) {
            ((WebResource) val).updateIfNeeded();
            val = ((WebResource) val).getContent().hashCode();
        }
        var.setValue(context, val);
    }
    compressedFile = (String) content.getValue(context);

    digest.reset();
    builder.append(Hex.encodeHexString(digest.digest(compressedFile.getBytes(StandardCharsets.UTF_8))));
    messageDigest = builder.toString();
    builder.delete(0, builder.length());

    DATE_FORMATTER.formatDate(lastModified, builder);
    lastModifiedString = builder.toString();
}

From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.RankerCreationUtil.java

/**
 * Creates a csv string of answer data from a collection of answers by reading the answer ids and
 * feature vectors/* w  w  w.j a v a  2 s  .  com*/
 * 
 * @param answers the collection of CandidatateAnswers to pull data from
 * @return
 */
public static String getCsvAnswerData(Collection<CandidateAnswer> answers, BaseEgaMetaDataAnswerScorer scorer) {

    // Initialize the csv string used to send the answer data for ranking
    StringBuilder csvStringHeader = new StringBuilder();
    StringBuilder csvString = new StringBuilder();

    // Add the answer data to to the csv string
    boolean addHeader = true;
    for (CandidateAnswer answer : answers) {

        // score the answer to add our own features
        if (scorer != null) {
            // answers come from real-time user, not testing phase of the
            // pipeline
            answer = scorer.scoreCandidateAnswer(null, answer);
        }

        // Add header
        if (addHeader) {
            csvStringHeader.append(RetrieveAndRankConstants.ANSWER_ID_HEADER + ",");
        }
        csvString.append(answer.getAnswerLabel());
        csvString.append(",");

        // Build the csvString by adding the feature vectors
        Set<Entry<String, Double>> fvp = answer.getFeatureValuePairs();
        Iterator<Entry<String, Double>> it = fvp.iterator();
        while (it.hasNext()) {
            Entry<String, Double> entry = (Entry<String, Double>) it.next();
            // ignore the added rank and score fields as they are not needed
            // by ranker
            if (!(entry.getKey().equals(PipelineConstants.FEATURE_SEARCH_RANK)
                    || entry.getKey().equals(PipelineConstants.FEATURE_SEARCH_SCORE))) {
                if (addHeader) {
                    csvStringHeader.append(entry.getKey());
                    csvStringHeader.append(",");
                }
                csvString.append(entry.getValue());
                csvString.append(",");
            }
        }

        // delete last comma of the header then begin a new line
        if (addHeader) {
            csvStringHeader.delete(csvStringHeader.length() - 1, csvStringHeader.length());
            csvStringHeader.append("\n");
        }

        // delete trailing comma then begin a new line
        csvString.delete(csvString.length() - 1, csvString.length());
        csvString.append("\n");
        addHeader = false;
    }

    return csvStringHeader.append(csvString).toString();
}

From source file:com.g3net.tool.StringUtils.java

public static String trimLeadingStrings(String str, String[] trimStrings) {
    if (str == null)
        return null;
    // String tempStr=str;
    StringBuilder sb = new StringBuilder(str);

    while (sb.length() > 0) {

        boolean flag = true;// ?false?
        for (int i = 0; i < trimStrings.length; i++) {

            int index = trimStrings[i].length();
            String ss = "";
            if (index <= sb.length()) {
                ss = sb.substring(0, index);
            }//w ww . j a va  2s .  co  m

            if (ss.equals(trimStrings[i])) {
                sb.delete(0, index);
                flag = false;
            }
        }
        // log.info(flag);
        if (flag)
            break;

    }
    return sb.toString();
}

From source file:org.apache.gora.dynamodb.compiler.GoraDynamoDBCompiler.java

/**
 * Creates key getters and setters//from   w  ww.  j  av  a 2  s .c o  m
 *
 * @param pKeySchema The key schema for a specific table
 * @param pIden      Number of spaces used for indentation
 * @throws IOException
 */
private void setKeyMethods(KeySchemaElement pKeySchema, String attType, int pIden) throws IOException {
    StringBuilder strBuilder = new StringBuilder();
    attType = attType.equals("S") ? "String" : "double";
    // hash key
    if (pKeySchema.getKeyType().equals(KeyType.HASH.toString())) {
        strBuilder.append("@DynamoDBHashKey(attributeName=\"" + pKeySchema.getAttributeName() + "\") \n");
        strBuilder.append("    public " + attType + " getHashKey() {  return " + pKeySchema.getAttributeName()
                + "; } \n");
        strBuilder.append("    public void setHashKey(" + attType + " ");
        strBuilder.append(
                "p" + camelCasify(pKeySchema.getAttributeName()) + "){  this." + pKeySchema.getAttributeName());
        strBuilder.append(" = p" + camelCasify(pKeySchema.getAttributeName()) + "; }");
        line(pIden, strBuilder.toString());
    }
    strBuilder.delete(0, strBuilder.length());
    // range key
    if (pKeySchema.getKeyType().equals(KeyType.RANGE.toString())) {
        strBuilder.append("@DynamoDBRangeKey(attributeName=\"" + pKeySchema.getAttributeName() + "\") \n");
        strBuilder.append("    public " + attType + " getRangeKey() { return " + pKeySchema.getAttributeName()
                + "; } \n");
        strBuilder.append("    public void setRangeKey(" + attType + " ");
        strBuilder.append(
                "p" + camelCasify(pKeySchema.getAttributeName()) + "){  this." + pKeySchema.getAttributeName());
        strBuilder.append(" = p" + camelCasify(pKeySchema.getAttributeName()) + "; }");
        line(pIden, strBuilder.toString());
    }
    line(0, "");
}

From source file:com.virtusa.akura.reporting.controller.CRAverageTermMarkClassWiseController.java

/**
 * @return the grade subject list/* w  w  w  .  ja  v a2  s .  c  o  m*/
 * @param request of type HttpServletRequest
 * @throws AkuraAppException AkuraAppException
 */
@RequestMapping(value = GRADE_CLASS_HTM)
@ResponseBody
public String populateGradeSubject(HttpServletRequest request) throws AkuraAppException {

    StringBuilder allGradeSubject = new StringBuilder();
    int gradeId = Integer.parseInt(request.getParameter(SELECTED_VALUE));

    List<GradeSubject> subjectGrades = commonService.getGradeSubjectIdListByGrade(gradeId);

    boolean isFirst = true;

    StringBuilder subjects = new StringBuilder();

    for (GradeSubject subjectGrade : subjectGrades) {
        subjects.append(subjectGrade.getSubject().getDescription());
        subjects.append(AkuraWebConstant.UNDERSCORE_STRING);
        subjects.append(subjectGrade.getGradeSubjectId());

        if (isFirst) {
            allGradeSubject.append(subjects.toString()); // no comma
            isFirst = false;
        } else {
            allGradeSubject.append(AkuraWebConstant.STRING_COMMA); // comma
            allGradeSubject.append(subjects.toString());
        }
        subjects.delete(0, subjects.length());
    }
    return allGradeSubject.toString();
}

From source file:com.haulmont.cuba.gui.data.impl.AbstractCollectionDatasource.java

protected DataLoadContextQuery createDataQuery(DataLoadContext context, Map<String, Object> params) {
    DataLoadContextQuery q = null;//from   ww w.  j  ava  2s  .c  o  m
    if (query != null && queryParameters != null) {
        Map<String, Object> parameters = getQueryParameters(params);
        for (ParameterInfo info : queryParameters) {
            if (ParameterInfo.Type.DATASOURCE.equals(info.getType())) {
                Object value = parameters.get(info.getFlatName());
                if (value == null) {
                    String[] pathElements = info.getPath().split("\\.");
                    if (pathElements.length == 1) {
                        //nothing selected in 'master' datasource, so return null here to clear the 'detail' datasource
                        return null;
                    } else {
                        //The parameter with null value is the path to the datasource item property,
                        //e.g. :ds$User.group.id.
                        //If the 'master' datasource item is not null then do not clear the 'detail' datasource,
                        //a null query parameter value should be processed
                        String dsName = pathElements[0];
                        final Datasource datasource = dsContext.get(dsName);
                        if (datasource == null) {
                            throw new DevelopmentException("Datasource '" + dsName + "' not found in dsContext",
                                    "datasource", dsName);
                        }
                        if (datasource.getState() != State.VALID || datasource.getItem() == null)
                            return null;
                    }
                }
            }
        }

        String queryString = getJPQLQuery(getTemplateParams(params));
        q = context.setQueryString(queryString);
        // Pass only parameters used in the resulting query
        QueryParser parser = QueryTransformerFactory.createParser(queryString);
        Set<String> paramNames = parser.getParamNames();
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            if (paramNames.contains(entry.getKey()))
                q.setParameter(entry.getKey(), entry.getValue());
        }
    } else if (!(context instanceof ValueLoadContext)) {
        Collection<MetaProperty> properties = metadata.getTools().getNamePatternProperties(metaClass);
        if (!properties.isEmpty()) {
            StringBuilder orderBy = new StringBuilder();
            for (MetaProperty metaProperty : properties) {
                if (metaProperty != null && metaProperty.getAnnotatedElement()
                        .getAnnotation(com.haulmont.chile.core.annotations.MetaProperty.class) == null)
                    orderBy.append("e.").append(metaProperty.getName()).append(", ");
            }
            if (orderBy.length() > 0) {
                orderBy.delete(orderBy.length() - 2, orderBy.length());
                orderBy.insert(0, " order by ");
            }
            q = context.setQueryString("select e from " + metaClass.getName() + " e" + orderBy.toString());
        } else
            q = context.setQueryString("select e from " + metaClass.getName() + " e");
    }
    if (q instanceof LoadContext.Query) {
        ((LoadContext.Query) q).setCacheable(isCacheable());
    }
    return q;
}