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:de.fiz.ddb.aas.utils.LDAPEngineUtility.java

public StringBuilder normalizeKommataString(StringBuilder pKommataStr) {
    if ((pKommataStr != null) && (pKommataStr.length() > 0)) {
        if (pKommataStr.indexOf(",") > 0) {
            String[] vStrLst = pKommataStr.toString().split(",");
            pKommataStr.delete(0, pKommataStr.length());
            for (int i = 0; i < vStrLst.length; i++) {
                if (pKommataStr.length() > 0) {
                    pKommataStr.append(",");
                }/*from   w  ww .jav  a 2  s . com*/
                pKommataStr.append(vStrLst[i].trim());
            }
        }
    }
    return pKommataStr;
}

From source file:com.cloud.utils.db.SqlGenerator.java

public Pair<StringBuilder, Attribute[]> buildSelectSql(Attribute[] attrs) {
    StringBuilder sql = new StringBuilder("SELECT ");

    for (Attribute attr : attrs) {
        sql.append(attr.table).append(".").append(attr.columnName).append(", ");
    }// www . j av a2s .c o m

    if (attrs.length > 0) {
        sql.delete(sql.length() - 2, sql.length());
    }

    sql.append(" FROM ").append(buildTableReferences());

    sql.append(" WHERE ");

    sql.append(buildDiscriminatorClause().first());

    return new Pair<StringBuilder, Attribute[]>(sql, attrs);
}

From source file:net.duckling.ddl.service.resource.dao.ResourceDAOImpl.java

@Override
public PaginationBean<Resource> getResourceByFileType(int tid, String type, int offset, int size, String order,
        String keyWord) {//from w  ww  .j  a  v a  2 s.c  o  m
    String where = " where tid=:tid and item_type=:itemType  ";
    String[] types = TeamQueryUtil.convertType(type);
    if (types.length > 1) {
        StringBuilder sb = new StringBuilder(" and (");
        for (int i = 1; i < types.length; i++) {
            sb.append("file_type like '%" + types[i] + "%' or ");
        }
        sb.delete(sb.length() - 4, sb.length());
        sb.append(")");
        where = where + sb.toString();
    }
    Map<String, Object> queryParam = new HashMap<String, Object>();
    queryParam.put("tid", tid);
    queryParam.put("itemType", types[0]);
    if (StringUtils.isNotEmpty(keyWord)) {
        String s = ResourceQueryKeywordUtil.getKeyWordString(keyWord, queryParam, "");
        where = where + s;
    }
    where = where + " and status='" + LynxConstants.STATUS_AVAILABLE + "'";
    Integer total = getNamedParameterJdbcTemplate().queryForObject("select count(rid) from a1_resource" + where,
            queryParam, Integer.class);
    String querySql = "select * from a1_resource " + where + ResourceOrderUtils.buildOrderSql("", order)
            + ResourceOrderUtils.buildDivPageSql(offset, size);
    List<Resource> resources = getNamedParameterJdbcTemplate().query(querySql, queryParam, resourceRowMapper);
    PaginationBean<Resource> result = new PaginationBean<Resource>();
    result.setData(resources);
    result.setBegin(offset);
    result.setEnd(offset + size);
    result.setSize(size);
    result.setTotal(total == null ? 0 : total);
    return result;
}

From source file:com.cloud.utils.db.SqlGenerator.java

protected String buildDeleteSql(String table, ArrayList<Attribute> attrs) {
    StringBuilder sql = new StringBuilder("DELETE FROM ");
    sql.append(table).append(" WHERE ");
    for (Attribute attr : attrs) {
        sql.append(table).append(".").append(attr.columnName).append("= ? AND ");
    }/*from w  w w.  j a v  a2 s  . c  o  m*/
    sql.delete(sql.length() - 5, sql.length());
    return sql.toString();
}

From source file:org.matsim.pt.counts.obsolete.PtCountSimComparisonKMLWriter.java

/**
 * Creates a placemark/* w w  w.  j  a va  2 s. c o  m*/
 *
 * @param stopid
 * @param csc
 * @param relativeError
 * @param timestep
 * @return the Placemark instance with description and name set
 */
private PlacemarkType createPlacemark(final String stopid, final CountSimComparison csc,
        final double relativeError, final int timestep, PtCountsType type) {
    StringBuilder stringBuffer = new StringBuilder();
    PlacemarkType placemark = kmlObjectFactory.createPlacemarkType();
    stringBuffer.delete(0, stringBuffer.length());
    stringBuffer.append(STOP);
    stringBuffer.append(stopid);
    //      placemark.setName(stringBuffer.toString()) ; // adds "name" to icon in image.  not so useful
    placemark.setDescription(createPlacemarkDescription(stopid, csc, relativeError, timestep, type));
    return placemark;
}

From source file:org.nabucco.alfresco.enhScriptEnv.common.script.locator.AbstractScriptLocator.java

/**
 * Resolves a relative location value against the reference location provided by the currently exectued script.
 * //from   ww w  .  jav  a2  s  .co m
 * @param locationValue
 *            The relative location value to resolve
 * @param referenceValue
 *            The reference location to resolve against. This parameter is primarily used in an informative capacity (e.g. for logging)
 *            while the pathBuilder is the work-item.
 * @param pathBuilder
 *            A builder for the final path that should be manipulated during the resolution. The instance passed should be
 *            pre-initialized with the base path determined from the reference location.
 */
@SuppressWarnings("static-method")
protected void resolveRelativeLocation(final String locationValue, final String referenceValue,
        final StringBuilder pathBuilder) {
    LOGGER.debug("Resolving relativ classpath location {} from reference {}", locationValue, referenceValue);
    int lastSlash = -1;
    int nextSlash = locationValue.indexOf("/");
    boolean descending = false;
    while (nextSlash != -1) {
        final String fragment = locationValue.substring(lastSlash + 1, nextSlash);

        if (fragment.length() != 0) {

            if (fragment.equalsIgnoreCase("..")) {
                if (!descending) {
                    // ascend
                    final int deleteFrom = pathBuilder.lastIndexOf("/");
                    if (deleteFrom == -1) {
                        if (pathBuilder.length() > 0) {
                            pathBuilder.delete(0, pathBuilder.length());
                        } else {
                            LOGGER.warn("Resolving {} from reference {} caused ascension beyond root",
                                    locationValue, referenceValue);
                            // nowhere to ascend to
                            throw new ScriptImportException(
                                    "Unable to ascend out of classpath - context location: [{0}], script location: [{1}]",
                                    new Object[] { referenceValue, locationValue });
                        }
                    } else {
                        pathBuilder.delete(deleteFrom, pathBuilder.length());
                    }
                } else {
                    LOGGER.warn("Cannot ascend after descending in resolution of {} from reference {}",
                            locationValue, referenceValue);
                    // no re-ascension
                    throw new ScriptImportException(
                            "Unable to ascend after already descending - context location: [{0}], script location: [{1}]",
                            new Object[] { referenceValue, locationValue });
                }
            } else if (fragment.equalsIgnoreCase(".")) {
                descending = true;
            } else {
                descending = true;
                pathBuilder.append("/").append(fragment);
            }
        }

        lastSlash = nextSlash;
        nextSlash = locationValue.indexOf('/', lastSlash + 1);
    }

    if (nextSlash == -1 && lastSlash == -1) {
        // no slash found at all
        pathBuilder.append("/");
    }

    pathBuilder.append(lastSlash != -1 ? locationValue.substring(lastSlash) : locationValue);

    LOGGER.debug("Resolved classpath location {} by relative path {} from reference {}",
            new Object[] { pathBuilder, locationValue, referenceValue });
}

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

public void update() throws Exception {
    StringBuilder builder = new StringBuilder(32);
    MessageDigest digest = DIGESTS.get();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    InputStream inputStream = resource.getInputStream();

    try {// ww  w . ja v a  2s  .c  o m
        lastModified = resource.lastModified();
        IOUtils.copyLarge(inputStream, outputStream);
        compressedFile = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
    } finally {
        inputStream.close();
    }

    if (minify) {
        compressedFile = minifier.minify(compressedFile);
    }

    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();
    bytes = null;
}

From source file:at.beris.virtualfile.shell.Shell.java

private boolean commandArgumentsValid(Pair<Command, List<String>> cmd) {
    StringBuilder sb = new StringBuilder();
    Command cmdOp = cmd.getLeft();//  w  w w  . j a  v a 2 s.c o m
    int[] expectedArgCounts = cmdOp.getArgumentCounts();
    List<String> actualArgs = cmd.getRight();

    sb.append("Wrong number of arguments for Command ").append(cmdOp.toString().toLowerCase())
            .append(". Expected ");

    boolean argCountMatches = false;
    for (int expectedArgCount : expectedArgCounts) {
        if (expectedArgCount == actualArgs.size())
            argCountMatches = true;
        sb.append(expectedArgCount).append(" or ");
    }
    sb.delete(sb.length() - 4, sb.length()).append(".");

    if (!argCountMatches)
        System.out.println(sb.toString());

    return argCountMatches;
}

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

/**
 * Method is to return GradeClass list./*  ww w  .java 2  s  .  c om*/
 *
 * @param request - HttpServletRequest
 * @param modelMap - ModelMap attribute.
 * @return list of classGrade
 * @throws AkuraAppException - Detailed exception
 */

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

    StringBuilder allGradeClass = new StringBuilder();
    int gradeId = Integer.parseInt(request.getParameter(SELECTED_VALUE));
    Grade grade = commonService.findGradeById(gradeId);
    List<ClassGrade> classGrades = SortUtil.sortClassGradeList(commonService.getClassGradeListByGrade(grade));
    boolean isFirst = true;
    StringBuilder classes = new StringBuilder();

    for (ClassGrade classGrade : classGrades) {
        classes.append(classGrade.getDescription());
        classes.append("_");
        classes.append(classGrade.getClassGradeId());

        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:com.mirth.connect.util.MessageImporter.java

private void importMessagesFromInputStream(InputStream inputStream, MessageWriter messageWriter, int[] result)
        throws IOException, InterruptedException {
    BufferedReader reader = null;

    try {/*from www  .ja v  a 2  s  . com*/
        reader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        StringBuilder serializedMessage = new StringBuilder();
        boolean enteredMessage = true;
        int depth = 0;

        while ((line = reader.readLine()) != null) {
            ThreadUtils.checkInterruptedStatus();

            if (StringUtils.contains(line, OPEN_ELEMENT)) {
                depth++;
                enteredMessage = true;
            }

            if (enteredMessage) {
                serializedMessage.append(line);

                if (StringUtils.contains(line, CLOSE_ELEMENT)) {
                    if (depth == 1) {
                        Message message = serializer.deserialize(serializedMessage.toString(), Message.class);
                        serializedMessage.delete(0, serializedMessage.length());
                        enteredMessage = false;
                        result[0]++;

                        try {
                            if (messageWriter.write(message)) {
                                result[1]++;
                            }
                        } catch (MessageWriterException e) {
                            logger.error("Failed to write message", e);
                        }
                    }

                    depth--;
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(reader);
    }
}