Example usage for java.lang StringBuilder deleteCharAt

List of usage examples for java.lang StringBuilder deleteCharAt

Introduction

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

Prototype

@Override
public StringBuilder deleteCharAt(int index) 

Source Link

Usage

From source file:com.surveypanel.form.FormHandler.java

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
        throws IOException, ServletException {
    response.setContentType("text/html;charset=UTF-8");
    Map<String, String> values = new HashMap<String, String>();
    Map params = request.getParameterMap();
    try {//from  w w  w  . ja v a2 s .  c o  m
        for (Object key : params.keySet()) {
            Object object = params.get(key);
            if (object instanceof String) {
                values.put((String) key, (String) object);
            } else if (object.getClass().isArray()) {
                StringBuilder sb = new StringBuilder();
                String[] value = (String[]) object;
                for (String content : value) {
                    sb.append(content).append(",");
                }
                sb.deleteCharAt(sb.length() - 1);
                values.put((String) key, sb.toString());
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    if (params.containsKey("quit")) {
        quit = true;
    }
    Form form = null;
    if (!values.containsKey("formId")) {
        form = formFactory.create(surveyId, devMode);
    } else {
        form = formFactory.load(values.get("formId"), surveyId, devMode);
    }
    form.setValues(values);
    form.setDevMode(devMode);
    Result execute;
    try {
        execute = (Result) jsManager.execute(form, "flow.execute(survey); save();");
        System.out.println(execute.getLogs());
        if (execute.hasError()) {
            response.getWriter().write(execute.getError());
        } else {
            response.getWriter().write(execute.getDisplay());
        }
    } catch (Exception e) {
        e.printStackTrace();
        response.getWriter().write(e.getMessage());
    }
    response.flushBuffer();
}

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

/**
 * Renders a textual representation of the provided {@link Table}
 * /*from w  w  w  .jav  a  2s . 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:com.proctorcam.proctorserv.RestRequestClient.java

/**
 *  Creates a URL using url (String) and appending to it the key-value pairs
 *  found in params (HashMap). The resulting String is used to make GET requests
 *  in makeGetRequest, /*from  ww  w  .j  av a2 s  . c  om*/
 */

protected String buildURL(String url, HashMap<String, Object> params) {
    StringBuilder query = new StringBuilder(url).append("?");
    for (String key : params.keySet()) {
        String data = String.valueOf(params.get(key));
        query.append(key).append("=").append(data).append("&");
    }

    query.deleteCharAt(query.length() - 1);
    String queryURL = query.toString();

    return queryURL;
}

From source file:com.ewcms.component.citizen.service.CitizenService.java

public String mainJSON() {
    List<Citizen> citizens = getCitizenAll();
    if (citizens == null || citizens.isEmpty()) {
        return "[]";
    }/*from   w w w. j av  a2s .  co  m*/

    StringBuilder builder = new StringBuilder();
    builder.append("[");
    for (Citizen citizen : citizens) {
        builder.append("{").append("\"id\":\"").append(citizen.getId()).append("\",");
        builder.append("\"name\":\"").append(citizen.getName()).append("\"},");
    }
    builder.deleteCharAt(builder.length() - 1);
    builder.append("]");

    return builder.toString();
}

From source file:com.facebook.presto.accumulo.model.Row.java

@Override
public String toString() {
    if (fields.isEmpty()) {
        return "()";
    } else {//from   w  ww .  j av a 2s. co m
        StringBuilder builder = new StringBuilder("(");
        for (Field f : fields) {
            builder.append(f).append(",");
        }
        builder.deleteCharAt(builder.length() - 1);
        return builder.append(')').toString();
    }
}

From source file:ch.iceage.icedms.persistence.jdbc.query.AbstractGenericQueries.java

@Override
public String getAll(String tableName) {
    StringBuilder sb = new StringBuilder("SELECT ");
    for (String column : schema.getColumNames(tableName)) {
        sb.append(GENERIC_TABLE_ALIAS).append(".").append(column).append(", ");
    }//from ww w. j av  a  2s .  co m
    sb.deleteCharAt(sb.length() - 1);
    sb.append(" FROM ").append(tableName);
    return sb.toString();
}

From source file:com.msopentech.odatajclient.proxy.api.impl.QueryImpl.java

@Override
public Query<T, EC> setOrderBy(final Sort... sort) {
    final StringBuilder builder = new StringBuilder();
    for (Sort sortClause : sort) {
        builder.append(sortClause.getKey()).append(' ').append(sortClause.getValue()).append(',');
    }/*  ww w .j a  v a 2s.c  o m*/
    builder.deleteCharAt(builder.length() - 1);

    this.orderBy = builder.toString();
    return this;
}

From source file:com.expressui.domain.geoplanet.GeoPlanetService.java

public Set<Place> getStates(Set<String> countriesWithStates) {

    String queryStr = "select country, admin1 from geo.states where place in (%1$s) and view='long'";
    StringBuilder countriesBuilder = new StringBuilder();
    for (String countryWithStates : countriesWithStates) {
        countriesBuilder.append("'").append(countryWithStates).append("',");
    }//www .j  a va 2s  .c o  m
    countriesBuilder.deleteCharAt(countriesBuilder.length() - 1);

    Set<Place> places = new HashSet<Place>();
    GeoPlanetResponse geoPlanetResponse = geoPlanetClient
            .getPlaces(String.format(queryStr, countriesBuilder.toString()));
    for (Place place : geoPlanetResponse.places) {
        if (!place.admin1.code.isEmpty()) {
            places.add(place);
        }
    }

    return places;
}

From source file:ca.uhn.fhir.rest.client.apache.ApacheHttpClient.java

private StringBuilder newHeaderBuilder(StringBuilder theUrlBase) {
    StringBuilder b = new StringBuilder();
    b.append(theUrlBase);//from   w ww .  j av  a  2s  .  c  o m
    if (theUrlBase.length() > 0 && theUrlBase.charAt(theUrlBase.length() - 1) == '/') {
        b.deleteCharAt(b.length() - 1);
    }
    return b;
}

From source file:com.mstiles92.plugins.stileslib.commands.CustomCommand.java

@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
        throws CommandException, IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    List<String> completions = null;
    try {// ww w . ja v a 2  s. com
        if (completer != null) {
            completions = completer.onTabComplete(sender, this, alias, args);
        } else if (executor instanceof TabCompleter) {
            completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
        }
    } catch (Exception e) {
        StringBuilder message = new StringBuilder();
        message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
        for (String arg : args) {
            message.append(arg).append(' ');
        }
        message.deleteCharAt(message.length() - 1).append("' in plugin ")
                .append(owningPlugin.getDescription().getFullName());

        throw new CommandException(message.toString(), e);
    }

    if (completions == null) {
        return super.tabComplete(sender, alias, args);
    }

    return completions;
}