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.googlecode.wickedcharts.highcharts.jackson.CssStyleSerializer.java

@Override
public void serialize(final CssStyle value, final JsonGenerator jgen, final SerializerProvider provider)
        throws IOException, JsonProcessingException {

    StringBuilder cssStyleBuilder = new StringBuilder();
    cssStyleBuilder.append("{");

    for (Entry<String, String> property : value.getProperties().entrySet()) {
        cssStyleBuilder.append("\"" + property.getKey() + "\": \"" + property.getValue() + "\",");
    }//from  w  ww  . j a  va2  s .  c o m

    int lastCommaPosition = cssStyleBuilder.lastIndexOf(",");
    if (lastCommaPosition != -1) {
        cssStyleBuilder.deleteCharAt(lastCommaPosition);
    }
    cssStyleBuilder.append(" }");

    jgen.writeRawValue(cssStyleBuilder.toString());

}

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 ww w. jav a2s  . co  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.springframework.boot.actuate.metrics.influxdb.InfluxDBGaugeWriter.java

/**
 * Flush the buffer without waiting for it to fill any further.
 *///  w ww  . java  2  s .  c  o m
@SuppressWarnings("rawtypes")
public void flush() {
    List<InfluxDBData> snapshot = getBufferSnapshot();
    if (snapshot.isEmpty()) {
        return;
    }
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(this.mediaType));
    headers.setContentType(this.mediaType);
    StringBuilder stringBuilder = new StringBuilder();
    for (InfluxDBData data : snapshot) {
        stringBuilder.append(data.toString()).append("\n");
    }
    stringBuilder.deleteCharAt(stringBuilder.lastIndexOf("\n"));
    ResponseEntity<Map> response = this.restTemplate.postForEntity(this.url,
            new HttpEntity<String>(stringBuilder.toString(), headers), Map.class);
    if (!response.getStatusCode().is2xxSuccessful()) {
        logger.warn("Cannot write metrics (discarded " + snapshot.size() + " values): " + response.getBody());
    }
}

From source file:org.springframework.xd.shell.util.UiUtils.java

/**
 * Renders a textual representation of the provided {@link Table}
 * //from  w  w  w  .  j a v  a2s . co m
 * @param table Table data {@link Table}
 * @return The rendered table representation as String
 */
public static String renderTextTable(Table table, boolean withHeader) {

    table.calculateColumnWidths();

    final String padding = "  ";
    final String headerBorder = getHeaderBorder(table.getHeaders());
    final StringBuilder textTable = new StringBuilder();

    if (withHeader) {
        final StringBuilder headerline = new StringBuilder();
        for (TableHeader header : table.getHeaders().values()) {

            if (header.getName().length() > header.getWidth()) {
                Iterable<String> chunks = Splitter.fixedLength(header.getWidth()).split(header.getName());
                int length = headerline.length();
                boolean first = true;
                for (String chunk : chunks) {
                    final String lineToAppend;
                    if (first) {
                        lineToAppend = padding + CommonUtils.padRight(chunk, header.getWidth());
                    } else {
                        lineToAppend = StringUtils.leftPad("", length) + padding
                                + CommonUtils.padRight(chunk, header.getWidth());
                    }
                    first = false;
                    headerline.append(lineToAppend);
                    headerline.append("\n");
                }
                headerline.deleteCharAt(headerline.lastIndexOf("\n"));
            } else {
                String lineToAppend = padding + CommonUtils.padRight(header.getName(), header.getWidth());
                headerline.append(lineToAppend);
            }
        }
        textTable.append(org.springframework.util.StringUtils.trimTrailingWhitespace(headerline.toString()));
        textTable.append("\n");
    }

    textTable.append(headerBorder);

    for (TableRow row : table.getRows()) {
        StringBuilder rowLine = new StringBuilder();
        for (Entry<Integer, TableHeader> entry : table.getHeaders().entrySet()) {
            String value = row.getValue(entry.getKey());
            if (null != value && (value.length() > entry.getValue().getWidth())) {
                Iterable<String> chunks = Splitter.fixedLength(entry.getValue().getWidth()).split(value);
                int length = rowLine.length();
                boolean first = true;
                for (String chunk : chunks) {
                    final String lineToAppend;
                    if (first) {
                        lineToAppend = padding + CommonUtils.padRight(chunk, entry.getValue().getWidth());
                    } else {
                        lineToAppend = StringUtils.leftPad("", length) + padding
                                + CommonUtils.padRight(chunk, entry.getValue().getWidth());
                    }
                    first = false;
                    rowLine.append(lineToAppend);
                    rowLine.append("\n");
                }
                rowLine.deleteCharAt(rowLine.lastIndexOf("\n"));
            } else {
                String lineToAppend = padding + CommonUtils.padRight(value, entry.getValue().getWidth());
                rowLine.append(lineToAppend);
            }
        }
        textTable.append(org.springframework.util.StringUtils.trimTrailingWhitespace(rowLine.toString()));
        textTable.append("\n");
    }

    if (!withHeader) {
        textTable.append(headerBorder);
    }

    return textTable.toString();
}

From source file:com.jhr.jarvis.table.TableRenderer.java

/**
 * Renders a textual representation of the provided {@link Table}
 * //from  w w  w . ja v  a2 s. c o  m
 * @param table
 *            Table data {@link Table}
 * @return The rendered table representation as String
 */
public static String renderTextTable(Table table, boolean withHeader) {

    table.calculateColumnWidths();

    final String padding = "  ";
    final String headerBorder = getHeaderBorder(table.getHeaders());
    final StringBuilder textTable = new StringBuilder();

    if (withHeader) {
        final StringBuilder headerline = new StringBuilder();
        for (TableHeader header : table.getHeaders().values()) {

            if (header.getName().length() > header.getWidth()) {
                Iterable<String> chunks = Splitter.fixedLength(header.getWidth()).split(header.getName());
                int length = headerline.length();
                boolean first = true;
                for (String chunk : chunks) {
                    final String lineToAppend;
                    if (first) {
                        lineToAppend = padding + StringUtils.padRight(chunk, header.getWidth());
                    } else {
                        lineToAppend = StringUtils.padLeft("", length) + padding
                                + StringUtils.padRight(chunk, header.getWidth());
                    }
                    first = false;
                    headerline.append(lineToAppend);
                    headerline.append("\n");
                }
                headerline.deleteCharAt(headerline.lastIndexOf("\n"));
            } else {
                String lineToAppend = padding + StringUtils.padRight(header.getName(), header.getWidth());
                headerline.append(lineToAppend);
            }
        }
        textTable.append(org.springframework.util.StringUtils.trimTrailingWhitespace(headerline.toString()));
        textTable.append("\n");
    }

    textTable.append(headerBorder);

    for (TableRow row : table.getRows()) {
        StringBuilder rowLine = new StringBuilder();
        for (Entry<Integer, TableHeader> entry : table.getHeaders().entrySet()) {
            String value = row.getValue(entry.getKey());
            if (value.length() > entry.getValue().getWidth()) {
                Iterable<String> chunks = Splitter.fixedLength(entry.getValue().getWidth()).split(value);
                int length = rowLine.length();
                boolean first = true;
                for (String chunk : chunks) {
                    final String lineToAppend;
                    if (first) {
                        lineToAppend = padding + StringUtils.padRight(chunk, entry.getValue().getWidth());
                    } else {
                        lineToAppend = StringUtils.padLeft("", length) + padding
                                + StringUtils.padRight(chunk, entry.getValue().getWidth());
                    }
                    first = false;
                    rowLine.append(lineToAppend);
                    rowLine.append("\n");
                }
                rowLine.deleteCharAt(rowLine.lastIndexOf("\n"));
            } else {
                String lineToAppend = padding + StringUtils.padRight(value, entry.getValue().getWidth());
                rowLine.append(lineToAppend);
            }
        }
        textTable.append(org.springframework.util.StringUtils.trimTrailingWhitespace(rowLine.toString()));
        textTable.append("\n");
    }

    if (!withHeader) {
        textTable.append(headerBorder);
    }

    return textTable.toString();
}

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

@Override
public List<Starmark> getStarmarkOfRids(String uid, int tid, List<Long> rids) {
    List<Starmark> results = new ArrayList<Starmark>();
    if (null != rids && !rids.isEmpty()) {
        String sql = "select * from a1_starmark where uid=? and tid=? and rid in (";
        StringBuilder sb = new StringBuilder();
        for (long rid : rids) {
            sb.append(rid + ",");
        }// w ww  .  ja v a  2  s  . com
        sb.replace(sb.lastIndexOf(","), sb.length(), ")");
        sql += sb.toString();
        results = this.getJdbcTemplate().query(sql, new Object[] { uid, tid }, starmarkRowMapper);
    }
    return results;
}

From source file:net.freechoice.dao.impl.DaoTemplate.java

public final String bracketIds(final List<Integer> ls) {

    StringBuilder builder = new StringBuilder(32);
    builder.append("(");
    for (Integer v : ls) {
        builder.append(v + ",");
    }/*w w w .  j a  v  a2  s . c om*/
    builder.setCharAt(builder.lastIndexOf(","), ')');
    return builder.toString();
}

From source file:com.googlecode.wickedcharts.highcharts.jackson.DateTimeLabelFormatSerializer.java

@Override
public void serialize(final DateTimeLabelFormat value, final JsonGenerator jgen,
        final SerializerProvider provider) throws IOException, JsonProcessingException {

    StringBuilder dateTimeFormatBuilder = new StringBuilder();
    dateTimeFormatBuilder.append("{");

    for (Entry<DateTimeProperties, String> property : value.getProperties().entrySet()) {
        dateTimeFormatBuilder.append(" " + property.getKey().toCode() + ": '" + property.getValue() + "',");
    }//from   w  w  w.j ava  2  s  . c o  m

    int lastCommaPosition = dateTimeFormatBuilder.lastIndexOf(",");
    if (lastCommaPosition != -1) {
        dateTimeFormatBuilder.deleteCharAt(lastCommaPosition);
    }
    dateTimeFormatBuilder.append(" }");

    jgen.writeRawValue(dateTimeFormatBuilder.toString());
}

From source file:net.freechoice.dao.impl.DaoTemplate.java

public final <E extends FC_Model> String bracketModelIds(final List<E> ls) {

    StringBuilder builder = new StringBuilder(32);
    builder.append("(");
    for (FC_Model v : ls) {
        builder.append(v.getId() + ",");
    }//from  w w  w  .  j  a va  2s .co m
    builder.setCharAt(builder.lastIndexOf(","), ')');
    return builder.toString();
}

From source file:gov.nih.nci.nbia.customserieslist.FileGenerator.java

/**
 * generate comma separate string from the series instance uid list
 * @param seriesItems/*w  w  w. j a  v a2  s . com*/
 */
public String generate(List<BasketSeriesItemBean> seriesItems) {
    StringBuilder sb = new StringBuilder();
    int size = seriesItems.size();
    for (int i = 0; i < size; i++) {
        BasketSeriesItemBean bsib = seriesItems.get(i);
        sb.append(bsib.getSeriesId());
        sb.append(",");
        sb.append("\n");
    }
    int lastComma = sb.lastIndexOf(",");

    //System.out.println("char at length - 1: " + sb.charAt(sb.length() - 1) +  " length: " + sb.length() + " lastComma: " + lastComma);
    sb.replace(lastComma, lastComma, "");
    sb.trimToSize();
    //System.out.println("length: " + sb.length());
    return sb.toString();
}