Example usage for java.lang StringBuilder replace

List of usage examples for java.lang StringBuilder replace

Introduction

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

Prototype

@Override
public StringBuilder replace(int start, int end, String str) 

Source Link

Usage

From source file:capital.scalable.restdocs.constraints.ConstraintAndGroupDescriptionResolver.java

@Override
public String resolveDescription(Constraint constraint) {
    String constraintDescription = trimToEmpty(resolvePlainDescription(constraint));
    if (isBlank(constraintDescription)) {
        constraintDescription = constraint.getName();
    }/*w  w  w .  java2 s . co m*/

    List<Class> groups = getGroups(constraint);
    if (groups.isEmpty()) {
        return constraintDescription;
    }

    StringBuilder result = new StringBuilder();
    for (Class group : groups) {
        result.append(", ");
        result.append(trimToEmpty(resolveGroupDescription(group, constraintDescription)));
    }
    result.replace(0, 2, "");
    return result.toString();
}

From source file:org.piraso.api.sql.SQLViewEntry.java

@JsonIgnore
public String getParameterReplacedSql() {
    if (MapUtils.isEmpty(parameters)) {
        return sql;
    }/*  w ww. j  a  v  a2s.  c  om*/

    List<Integer> sorted = new ArrayList<Integer>(parameters.keySet());
    Collections.sort(sorted);

    StringBuilder buf = new StringBuilder(sql);

    for (Integer key : sorted) {
        SQLParameterEntry parameter = parameters.get(key);

        int index = buf.indexOf("?");
        if (index != -1) {
            buf.replace(index, index + 1, SQLParameterUtils.toPSLiteral(parameter));
        }
    }

    return buf.toString();
}

From source file:chat.ServletLog.java

protected void log(Level l, Object message, Throwable t) {
    if (t == null && message instanceof Throwable) {
        t = (Throwable) message;//from   w w  w.  j a v  a2s . c om
        message = "";
    }

    StringBuilder s = new StringBuilder(format);
    int i = s.indexOf(FORMAT_DATE);
    if (i >= 0)
        s.replace(i, i + FORMAT_DATE.length(), DATE.format(new Date()));
    i = s.indexOf(FORMAT_LEVEL);
    if (i >= 0)
        s.replace(i, i + FORMAT_LEVEL.length(), l.name());
    i = s.indexOf(FORMAT_LOG);
    if (i >= 0)
        s.replace(i, i + FORMAT_LOG.length(), String.valueOf(message));
    i = s.indexOf(FORMAT_CALL);
    if (i >= 0) {
        StackTraceElement[] stack = new Throwable().getStackTrace();
        // Caller is the third element
        String clazz = "unknown";
        String method = "unknown";
        if (stack != null && stack.length > 2) {
            clazz = stack[2].getClassName();
            method = stack[2].getMethodName();
        }
        s.replace(i, i + FORMAT_CALL.length(), clazz + '-' + method);
    }
    if (logger != null)
        logger.log(s.toString(), t);
    else {
        if (t != null) {
            StringWriter ts = new StringWriter(1024);
            PrintWriter tp = new PrintWriter(ts);
            t.printStackTrace(tp);
            tp.close();
            s.append("\n ").append(ts.toString());
        }
        (l.ordinal() <= Level.debug.ordinal() ? System.out : System.err).println(s);
    }
}

From source file:com.l2jfree.status.StatusThread.java

protected final String readLine() throws IOException {
    String line = _in.readLine();
    if (line == null)
        return null;

    StringBuilder sb = new StringBuilder(line);

    for (int index; (index = sb.indexOf("\b")) != -1;)
        sb.replace(index, index + 1, "");

    return sb.toString();
}

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

@Override
public int batchDelete(String uid, int tid, List<Long> rids) {
    if (null == rids || rids.isEmpty()) {
        return 0;
    }/*from www . j a v a 2s.co m*/
    String sql = "delete from a1_starmark where uid=? and tid=? and rid in(";
    StringBuilder sb = new StringBuilder();
    for (long rid : rids) {
        sb.append(rid + ",");
    }
    sb.replace(sb.lastIndexOf(","), sb.length(), ")");
    sql += sb.toString();
    return this.getJdbcTemplate().update(sql, new Object[] { uid, tid });
}

From source file:com.mmdi.gmds.ws.pcs.resource.GeoLocationJsonResource.java

private void locateFromCache(Location location) {
    try {/*from  w w w.jav  a 2 s . com*/
        String pc = location.getPostalCode();
        if (pc != null) {
            StringBuilder builder = new StringBuilder(pc);
            Pattern pattern = Pattern.compile("\\s");
            Matcher matcher = pattern.matcher(pc);

            while (matcher.find()) {
                builder.replace(matcher.start(), matcher.end(), "");
            }

            CacheResource cache = new PostalCodeCacheResource();
            PostalCode postalCode = (PostalCode) cache.getData(builder.toString(), locateCacheRegion);
            if (postalCode != null) {
                location.setLat(postalCode.getLat());
                location.setLng(postalCode.getLong());
            }
        }
    } catch (CacheException ce) {
        logger.error(ce.getMessage());
    }
}

From source file:server.NameGame.java

private String addGuessChar(String guess) {
    StringBuilder gWord = new StringBuilder(guessWord);
    for (int i = 0; i <= guessWord.length() - 1; i++) {
        //Do your stuff here
        if (StringUtils.equalsIgnoreCase(secretWord.substring(i, i + 1), guess.substring(0, 1))) {
            gWord.replace(i, i + 1, guess);
        }//from w w w  .  j av  a 2  s.  c  o  m
    }
    guessWord = gWord.toString();
    return guessWord;
}

From source file:org.drools.guvnor.server.contenthandler.ModelContentHandler.java

private StringBuilder removeImportIfItExists(StringBuilder header, String importLine) {
    if (header.indexOf(importLine) >= 0) {
        int indexOfImportLine = header.indexOf(importLine);
        header = header.replace(indexOfImportLine, indexOfImportLine + importLine.length(), "");
    }//from w ww .j  av  a  2  s.c o m
    return header;
}

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

@Override
public int batchDeleteResourceStar(int tid, int rid, Set<String> uids) {
    if (uids == null || uids.isEmpty()) {
        return 0;
    }//from  w  w  w .j a va 2 s  . c o m
    String sql = "delete from a1_starmark where tid=? and rid=? and uid in (";
    StringBuilder sb = new StringBuilder();
    for (String uid : uids) {
        sb.append("'" + uid + "',");
    }
    sb.replace(sb.lastIndexOf(","), sb.length(), ")");
    sql += sb.toString();
    return getJdbcTemplate().update(sql, tid, rid);
}

From source file:org.pentaho.amazon.AbstractAmazonJobExecutor.java

private String getKeyFromS3StagingDir() throws KettleFileException, FileSystemException {

    String pathToStagingDir = getS3FileObjectPath();
    StringBuilder sb = new StringBuilder(pathToStagingDir);

    sb.replace(0, 1, "");
    if (sb.indexOf("/") == -1) {
        return null;
    }//w w  w.ja  va 2  s  . c  o m
    sb.replace(0, sb.indexOf("/") + 1, "");

    if (sb.length() > 0) {
        return sb.toString();
    } else {
        return null;
    }
}