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.counter.counter.api.MainController.java

@RequestMapping(value = "/search", method = { RequestMethod.POST })
public ResponseEntity<String> searchText(@RequestParam List<String> searchText)
        throws JsonProcessingException, JSONException {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.add("Content-Type", "application/json;charset=utf-8");

    String rVal = "";
    //System.out.println("searchText-> " + searchText.size());
    List<String> tempList = new ArrayList();
    Map<String, Integer> map;
    JSONObject jsonMap = new JSONObject();
    for (String st : searchText) {
        Integer occurence = 0;//from   w ww. j  av a  2  s  .  c om
        map = new HashMap();
        for (int i = sourceText.indexOf(st); i >= 0; i = sourceText.indexOf(st, i + 1))
            occurence++;
        map.put(st, occurence);
        jsonMap.put(st, occurence);
        String json = new ObjectMapper().writeValueAsString(map);
        System.out.println(json);
        tempList.add(json);
    }

    StringBuilder sb = new StringBuilder();
    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonMap);

    System.out.println(jsonArray.toString());
    for (String s : tempList) {
        sb.append(s);
        sb.append(",");
    }
    sb.deleteCharAt(sb.lastIndexOf(","));

    //String json = new ObjectMapper().writeValueAsString(map);
    //System.out.println(json);
    return new ResponseEntity<>("[" + sb.toString() + "]", httpHeaders, HttpStatus.OK);
}

From source file:com.hp.autonomy.aci.content.printfields.PrintFields.java

/**
 * A {@code String} representation of the databases, suitable for use in a <tt>query</tt> or <tt>getcontent</tt>
 * action.//from   w ww  . ja v  a 2 s  . c  om
 *
 * @return The string representation
 */
@Override
public String toString() {
    final StringBuilder builder = new StringBuilder();

    for (final String value : this) {
        // Oddly, this doesn't need URL encoding
        builder.append(value).append('+');
    }

    if (builder.length() != 0) {
        builder.deleteCharAt(builder.length() - 1);
    }

    return builder.toString();
}

From source file:net.netheos.pcsapi.oauth.OAuth2SessionManager.java

/**
 * Converts scope (list of permissions) to string for building OAuth authorization URL.
 * <p/>//from w w w  .j  av  a 2s  . c om
 * Some providers separate permissions with spaces, other with comma... Other do not support scope at all.
 *
 * @return string for building OAuth authorization URL
 */
String getScopeForAuthorization() {
    if (!scopeInAuthorization) {
        return null;
    }

    StringBuilder sb = new StringBuilder();
    for (String perm : appInfo.getScope()) {
        sb.append(perm).append(scopePermsSeparator);
    }

    return new String(sb.deleteCharAt(sb.length() - 1));
}

From source file:android.databinding.tool.LayoutXmlProcessor.java

/**
 * Generates a string identifier that can uniquely identify the given layout bundle.
 * This identifier can be used when we need to export data about this layout bundle.
 *///from   www  .  j av a 2 s  .c o  m
public String generateExportFileName(ResourceBundle.LayoutFileBundle layout) {
    StringBuilder name = new StringBuilder(layout.getFileName());
    name.append('-').append(layout.getDirectory());
    for (int i = name.length() - 1; i >= 0; i--) {
        char c = name.charAt(i);
        if (c == '-') {
            name.deleteCharAt(i);
            c = Character.toUpperCase(name.charAt(i));
            name.setCharAt(i, c);
        }
    }
    return name.toString();
}

From source file:FormatTest.java

public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
        throws BadLocationException {
    StringBuilder builder = new StringBuilder(string);
    for (int i = builder.length() - 1; i >= 0; i--) {
        int cp = builder.codePointAt(i);
        if (!Character.isDigit(cp) && cp != '-') {
            builder.deleteCharAt(i);
            if (Character.isSupplementaryCodePoint(cp)) {
                i--;/*from w w  w .j a v a2 s.co  m*/
                builder.deleteCharAt(i);
            }
        }
    }
    super.insertString(fb, offset, builder.toString(), attr);
}

From source file:org.fao.fenix.wds.web.rest.faostat.FAOSTATDownloadNotes.java

@GET
@Produces(MediaType.TEXT_HTML)//w  w w  .  ja va 2 s. c o  m
@Path("{domainCode}/{lang}")
public Response createTable(@PathParam("domainCode") final String domainCode,
        @PathParam("lang") final String language) {

    // Initiate the stream
    StreamingOutput stream = new StreamingOutput() {

        @Override
        public void write(OutputStream os) throws IOException, WebApplicationException {

            // compute result
            Writer writer = new BufferedWriter(new OutputStreamWriter(os));
            Gson g = new Gson();

            // Query
            String script = "SELECT html FROM Metadata_Domain_Text[M] WHERE M.lang = '" + language
                    + "' AND M.name = 'Description' AND M.domain = '" + domainCode + "' ";
            SQLBean sql = new SQLBean(script);
            DatasourceBean db = datasourcePool.getDatasource(DATASOURCE.FAOSTATPROD.name());

            // Fetch data
            JDBCIterable it = new JDBCIterable();

            try {

                // Query DB
                it.query(db, sql.getQuery());

            } catch (IllegalAccessException e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'createJSON' thrown an error: " + e.getMessage()));
            } catch (InstantiationException e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'createJSON' thrown an error: " + e.getMessage()));
            } catch (SQLException e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'createJSON' thrown an error: " + e.getMessage()));
            } catch (ClassNotFoundException e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'createJSON' thrown an error: " + e.getMessage()));
            } catch (Exception e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'getDomains' thrown an error: " + e.getMessage()));
            }

            // Build the output
            StringBuilder sb = new StringBuilder();
            sb.append("[");
            while (it.hasNext())
                sb.append(g.toJson(it.next())).append(",");
            sb.deleteCharAt(sb.length() - 1);
            sb.append("]");
            writer.write(sb.toString());

            // Convert and write the output on the stream
            writer.flush();

        }

    };

    /* Stream result */
    return Response.status(200).entity(stream).build();

}

From source file:com.zhumeng.dream.orm.hibernate.HibernateDao.java

/**
 * order by? :order by o.email desc , o.username asc
 * @author: lizhong/*from   w  ww  .j  a va  2  s  .c  o  m*/
 * @param orderBy key , valuedesc/asc.:
 * orderBy.put("email", "desc");
 * orderBy.put("username", "asc");
 * ?sql?order by o.email desc,o.username asc
 * @return
 */

public static String buildOrderby(LinkedHashMap<String, String> orderBy) {
    StringBuilder order = new StringBuilder();
    if (orderBy != null && orderBy.size() > 0) {
        order.append(" order by ");
        for (Entry<String, String> entry : orderBy.entrySet()) {
            order.append(" o.").append(entry.getKey()).append(" ").append(entry.getValue()).append(",");
        }
        order.deleteCharAt(order.length() - 1);
    }
    return order.toString();
}

From source file:com.counter.counter.api.MainController.java

private List<Word> findTopWords() {
    Map<String, Word> countMap = new HashMap<String, Word>();
    StringBuilder tempSource = new StringBuilder(sourceText.toString());
    StringBuilder tempSource1 = new StringBuilder();
    StringBuilder tempSource2 = new StringBuilder();
    for (int i = tempSource.indexOf("."); i >= 0; i = tempSource.indexOf(".", i + 1))
        tempSource1 = tempSource.deleteCharAt(i);
    for (int i = tempSource1.indexOf(","); i >= 0; i = tempSource1.indexOf(",", i + 1))
        tempSource2 = tempSource1.deleteCharAt(i);
    String line = tempSource2.toString();
    //while ((line = reader.readLine()) != null) {
    String[] words = line.split(" ");
    for (String word : words) {

        word = word.toLowerCase();//  w  w  w  . j a  v a 2  s.c  o  m
        if ("".equals(word)) {
            continue;
        }

        Word wordObj = countMap.get(word);
        if (wordObj == null) {
            wordObj = new Word();
            wordObj.word = word;
            wordObj.count = 0;
            countMap.put(word, wordObj);
        }

        wordObj.count++;
    }
    //SortedSet<Word> sortedWords = new TreeSet<Word>(countMap.values());
    List<Word> l = new ArrayList<>(countMap.values());
    Collections.sort(l);
    return l;
}

From source file:com.github.parisoft.resty.utils.CookieUtils.java

public static String toString(HttpCookie... cookies) {
    if (isEmpty(cookies)) {
        return null;
    }//from  ww w  . jav  a  2  s .c  om

    final StringBuilder cookieBuilder = new StringBuilder();

    for (HttpCookie cookie : cookies) {
        cookieBuilder.append(cookie.getName()).append("=").append(cookie.getValue());

        if (cookie.getComment() != null) {
            cookieBuilder.append(";").append("Comment=").append(cookie.getComment());
        }

        if (cookie.getDomain() != null) {
            cookieBuilder.append(";").append("Domain=").append(cookie.getDomain());
        }

        if (cookie.getPath() != null) {
            cookieBuilder.append(";").append("Path=").append(cookie.getPath());
        }

        if (cookie.getSecure()) {
            cookieBuilder.append(";").append("Secure");
        }

        if (cookie.isHttpOnly()) {
            cookieBuilder.append(";").append("HttpOnly");
        }

        if (cookie.getVersion() > 0) {
            cookieBuilder.append(";").append("Version=").append(cookie.getVersion());
        }

        if (cookie.hasExpired()) {
            cookieBuilder.append(";").append("Max-Age=0");
        } else {
            cookieBuilder.append(";").append("Max-Age=").append(cookie.getMaxAge());
        }

        cookieBuilder.append(", ");
    }

    return cookieBuilder.deleteCharAt(cookieBuilder.length() - 1).toString();
}

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() + "\",");
    }//ww w .j  a va  2s.  c  o  m

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

    jgen.writeRawValue(cssStyleBuilder.toString());

}