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:org.gvnix.web.report.roo.addon.addon.ReportMetadata.java

/**
 * Return an string with the following content: <b>{"format1","format2"}</b>
 * as many fromatX as reportFromats values.
 * //from w  w w  . j a va 2 s  . c  o  m
 * @param reportFormats
 * @return
 */
private String getReportFormatsAsArray(String reportFormats) {
    StringBuilder sb = new StringBuilder("{");
    for (String format : reportFormats.split(",")) {
        sb.append("\"").append(format).append("\",");
    }
    sb.deleteCharAt(sb.length() - 1);
    sb.append("}");
    return sb.toString();
}

From source file:org.testmp.datastore.client.DataStoreClient.java

private <T> String convertListToRequestParam(List<T> list) {
    StringBuilder sb = new StringBuilder();
    for (T elem : list) {
        sb.append(elem.toString()).append(",");
    }/* www.j  a v a 2  s  .  c  o  m*/
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:com.hadoopvietnam.cache.memcached.MemcachedCache.java

/**
 * {@inheritDoc}//from  w w  w  .  j a  v a 2  s  .  co  m
 */
public void addToTopOfList(final String inKey, final List<Long> inValue) {
    if (inValue == null) {
        // cannot pass null to memcached
        log.warn("In addToTopOfList, attempting to pass in NULL to memcached for key " + inKey);
        return;
    }

    if (log.isTraceEnabled()) {
        StringBuilder allLongs = new StringBuilder();
        for (Long lng : inValue) {
            allLongs.append(lng.toString());
            allLongs.append(',');
        }

        // trim the last , just for clarity in the log
        if (allLongs.charAt(allLongs.length() - 1) == ',') {
            allLongs.deleteCharAt(allLongs.length() - 1);
        }

        log.trace("Prepending to list '" + inKey + "', values: " + allLongs.toString());
    }

    // NOTE: memcached will NOT create a List if one does
    // not exist already, it will silently fail.
    // THIS IS WHAT WE WANT!

    // try to prepend data, NOTE the cas key is ignored
    // in ASCII protocol which we are using
    byte[] bytesToPrepend;
    try {
        bytesToPrepend = this.getBytesFromList(inValue);
    } catch (IOException e) {
        // problem getting the key .. set a null so the client goes
        // to the database and clear marker so next time we'll try again
        log.error("Unable to prepend LIST key " + inKey + " into memcached.  Exception " + e.getMessage());
        bytesToPrepend = null;
    }

    if (bytesToPrepend != null) {
        client.prepend(0, inKey, bytesToPrepend);
    }
}

From source file:de.raptor2101.GalDroid.WebGallery.Gallery3.Gallery3Imp.java

private List<JSONObject> loadJSONObjectsParallel(String bunchUrl, List<String> urls, int taskCount,
        GalleryProgressListener listener) {
    int objectSize = urls.size();
    ArrayList<JSONArrayLoaderTask> tasks = new ArrayList<JSONArrayLoaderTask>(taskCount);

    ArrayList<JSONObject> jsonObjects = new ArrayList<JSONObject>(objectSize);

    for (int i = 0; i < objectSize;) {
        StringBuilder requstUrl = new StringBuilder(MAX_REQUEST_SIZE);
        JSONArrayLoaderTask task = new JSONArrayLoaderTask();
        tasks.add(task);//from w ww .ja  va2  s  . com
        /*
         * TODO Kommentar anpassen Otherwise the max length of a GET-Request might
         * be exceeded
         */

        for (; i < objectSize; i++) {
            String url = urls.get(i);
            if (url.length() + requstUrl.length() > MAX_REQUEST_SIZE) {
                break;
            }
            requstUrl.append("%22" + url + "%22,");
        }

        requstUrl.deleteCharAt(requstUrl.length() - 1);
        String realUrl = String.format(bunchUrl, requstUrl);

        task.execute(buildRestCall(realUrl, -1));
    }

    for (JSONArrayLoaderTask task : tasks) {
        if (task.getStatus() != Status.FINISHED) {
            try {
                JSONArray jsonArray = task.get();
                for (int i = 0; i < jsonArray.length(); i++) {
                    try {
                        jsonObjects.add(jsonArray.getJSONObject(i));
                        if (listener != null) {
                            listener.handleProgress(jsonObjects.size(), objectSize);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            } catch (InterruptedException e) {

            } catch (ExecutionException e) {

            }
        }
    }

    return jsonObjects;
}

From source file:com.google.ie.web.controller.IdeaController.java

/**
 * Edit the idea//  w w w  .j a  va 2s . c  o m
 * 
 * @param key the key of the idea
 * @param model data map
 * @return View Name
 */
@RequestMapping("/edit/{key}")
public String editIdea(@PathVariable String key, Model model) {
    log.info("Into edit idea. Key is:" + key);
    Idea idea = new Idea();
    idea.setKey(key);
    idea = ideaService.getIdeaDetails(idea);
    Set<String> tagKeys = idea.getTagKeys();
    /*
     * If the idea is associated with one or more tags,create a comma
     * separated string of tag titles and set into idea.tags
     */
    if (tagKeys != null && tagKeys.size() > WebConstants.ZERO) {
        List<Tag> tagList = tagService.getTagsByKeys(idea.getTagKeys());
        StringBuilder tagString = new StringBuilder("");
        for (Tag tag : tagList) {
            if (!StringUtils.isBlank(tag.getTitle())) {
                tagString.append(tag.getTitle());
                tagString.append(",");
            }
        }
        tagString.deleteCharAt(tagString.length() - 1);
        idea.setTags(tagString.toString());
    }

    ViewStatus viewStatus = new ViewStatus();
    viewStatus.addData(WebConstants.IDEA, idea);
    model.addAttribute(viewStatus);
    return "ideas/edit";
}

From source file:com.haulmont.cuba.security.app.EntityLog.java

protected String stringify(Object value) {
    if (value == null)
        return "";
    else if (value instanceof Instance) {
        return ((Instance) value).getInstanceName();
    } else if (value instanceof Date) {
        return Datatypes.getNN(value.getClass()).format(value);
    } else if (value instanceof Iterable) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (Object obj : (Iterable) value) {
            sb.append(stringify(obj)).append(",");
        }/*www.  j a  v  a  2 s  .  c om*/
        if (sb.length() > 1)
            sb.deleteCharAt(sb.length() - 1);
        sb.append("]");
        return sb.toString();
    } else {
        return String.valueOf(value);
    }
}

From source file:org.openspaces.rest.space.ReplicationRESTController.java

protected String tspecToPairsArg(TopologySpec tspec) {
    if (tspec == null)
        return "[]";
    if (tspec.edges == null || tspec.edges.size() == 0)
        return "[]";

    StringBuilder sb = new StringBuilder("[");
    for (TopologyEdge edge : tspec.edges) {
        sb.append("[");
        sb.append("").append(edge.fromSite).append("").append(",");
        sb.append(edge.toSite);// w  w  w . j  a  va  2 s  . c  o  m
        sb.append("],");
    }
    sb.deleteCharAt(sb.length() - 1);
    sb.append("]");
    return sb.toString();
}

From source file:com.wabacus.WabacusFacade.java

private static String assembleOptionsResult(String realSelectboxid,
        List<Map<String, String>> lstOptionsResult) {
    StringBuilder resultBuf = new StringBuilder();
    resultBuf.append(realSelectboxid).append(":[");
    if (lstOptionsResult != null && lstOptionsResult.size() > 0) {
        String labelTmp, valueTmp;
        for (Map<String, String> mItemsTmp : lstOptionsResult) {
            labelTmp = mItemsTmp.get("label");
            valueTmp = mItemsTmp.get("value");
            labelTmp = labelTmp == null ? "" : labelTmp.trim();
            valueTmp = valueTmp == null ? "" : valueTmp.trim();
            resultBuf.append("{label:\"").append(labelTmp).append("\",");
            resultBuf.append("value:\"").append(valueTmp).append("\"},");
        }/*w ww  .  java  2 s .c o  m*/
    }
    if (resultBuf.charAt(resultBuf.length() - 1) == ',')
        resultBuf.deleteCharAt(resultBuf.length() - 1);
    resultBuf.append("],");
    return resultBuf.toString();
}

From source file:com.ewcms.component.interaction.service.InteractionService.java

private String interactionJSON(Integer type) {
    List<Interaction> list = interactionDAO.findInteraction(0, 9, type);
    if (list == null || list.isEmpty()) {
        return "[]";
    }//from   ww w  .  j  a va2  s  . c  om
    StringBuilder builder = new StringBuilder();
    builder.append("[");
    for (Interaction interaction : list) {
        builder.append("{");
        builder.append("\"id\":").append(interaction.getId()).append(",");
        builder.append("\"type\":\"").append(getTypeName(interaction.getType())).append("\",");
        builder.append("\"title\":\"").append(interaction.getTitle()).append("\",");
        builder.append("\"organ\":\"").append(interaction.getOrgan().getName()).append("\",");
        builder.append("\"state\":\"").append(interaction.getState().getTitle()).append("\",");
        builder.append("\"date\":\"").append(format.format(interaction.getDate())).append("\"");
        builder.append("},");
    }
    builder.deleteCharAt(builder.length() - 1);
    builder.append("]");

    return builder.toString();
}

From source file:net.fischboeck.discogs.DatabaseOperations.java

/**
 * Returns a {@link SearchResult} for the given parameters.
 * Note that this operation is only available with an authenticated client
 * @param query The search query to look up
 * @param page The paging parameters//from w ww.j a v  a2  s . c  o  m
 * @param params The type of fields to look for
 * @return A {@link SearchResult}
 * @throws ClientException On any unexpected error
 */
public SearchResult search(String query, PageRequest page, QueryParam... params) throws ClientException {

    if (query == null || query.isEmpty())
        throw new IllegalArgumentException("Search query must not be null or empty");

    if (authorizationStrategy == null || authorizationStrategy instanceof NullAuthorizationStrategy)
        throw new IllegalStateException("This operation requires an authenticated client");

    StringBuilder uriBuilder = new StringBuilder(DEFAULT_BASE_URL).append("/database/search");
    uriBuilder = createPageParameters(uriBuilder, page);

    if (page == null) {
        uriBuilder.append("?q=");
    } else {
        uriBuilder.append("&q=");
    }
    try {
        uriBuilder.append(URLEncoder.encode(query, "UTF-8"));
    } catch (UnsupportedEncodingException ex) {
        throw new ClientException("Failed to encode the query string. Unsupported encoding UTF-8");
    }

    if (params.length > 0) {
        uriBuilder.append("&?");

        for (QueryParam p : params) {
            uriBuilder.append(p).append(",");
        }
        uriBuilder.deleteCharAt(uriBuilder.length() - 1);
    }

    return doGetRequest(uriBuilder.toString(), SearchResult.class);
}