List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:io.milton.servlet.ServletRequest.java
@Override public void parseRequestParameters(Map<String, String> params, Map<String, io.milton.http.FileItem> files) throws RequestParseException { try {/*from www . ja v a 2 s . com*/ if (isMultiPart()) { log.trace("parseRequestParameters: isMultiPart"); UploadListener listener = new UploadListener(); MonitoredDiskFileItemFactory factory = new MonitoredDiskFileItemFactory(listener); ServletFileUpload upload = new ServletFileUpload(factory); List items = upload.parseRequest(request); parseQueryString(params); for (Object o : items) { FileItem item = (FileItem) o; if (item.isFormField()) { params.put(item.getFieldName(), item.getString()); } else { // See http://jira.ettrema.com:8080/browse/MIL-118 - ServletRequest#parseRequestParameters overwrites multiple file uploads when using input type="file" multiple="multiple" String itemKey = item.getFieldName(); if (files.containsKey(itemKey)) { int count = 1; while (files.containsKey(itemKey + count)) { count++; } itemKey = itemKey + count; } files.put(itemKey, new FileItemWrapper(item)); } } } else { for (Enumeration en = request.getParameterNames(); en.hasMoreElements();) { String nm = (String) en.nextElement(); String[] vals = request.getParameterValues(nm); if (vals.length == 1) { params.put(nm, vals[0]); } else { StringBuilder sb = new StringBuilder(); for (String s : vals) { sb.append(s).append(","); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); // remove last comma } params.put(nm, sb.toString()); } } } } catch (FileUploadException ex) { throw new RequestParseException("FileUploadException", ex); } catch (Throwable ex) { throw new RequestParseException(ex.getMessage(), ex); } }
From source file:com.shopzilla.publisher.web.HomeController.java
@PerfTimed @RequestMapping(value = "filter", method = RequestMethod.GET) public String filter(HttpServletRequest request, Model uiModel) { StringBuilder query = new StringBuilder(); Enumeration requestEnum = request.getParameterNames(); while (requestEnum.hasMoreElements()) { String key = (String) requestEnum.nextElement(); for (String str : request.getParameterValues(key)) { query.append(key);//www. j ava 2 s . c o m query.append(":"); query.append(str); query.append(";"); } } query.deleteCharAt(query.length() - 1); String queryStr = query.toString(); this.offers.clear(); this.products.clear(); List<Category> categoryList = categoryProviderService.fetchCategories(); for (Category category : categoryList) { CatalogResponse response = categorySearchService.attributeSearch(category.getId(), 10, queryStr); this.offers.addAll(response.getOffers()); this.products.addAll(response.getProducts()); } uiModel.addAttribute("offers", this.offers); uiModel.addAttribute("products", this.products); uiModel.addAttribute("attributes", this.attributes); return "index"; }
From source file:net.sourceforge.fenixedu.domain.accounting.PaymentCode.java
public String getFormattedCode() { final StringBuilder result = new StringBuilder(); int i = 1;//from ww w . j a va2 s. c o m for (char character : getCode().toCharArray()) { result.append(character); if (i % 3 == 0) { result.append(" "); } i++; } return result.charAt(result.length() - 1) == ' ' ? result.deleteCharAt(result.length() - 1).toString() : result.toString(); }
From source file:com.openteach.diamond.network.waverider.master.MasterState.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{id:"); sb.append(id);/*from w w w.ja v a2 s . com*/ sb.append(", ip:"); sb.append(ip); sb.append(", port:"); sb.append(port); sb.append(", sessionStateList:{"); for (SessionState sessionState : sessionStateList) { sb.append("sessionState:"); sb.append(sessionState); sb.append(","); } if (sb.charAt(sb.length() - 1) == ',') { sb.deleteCharAt(sb.length() - 1); } sb.append("}"); sb.append("}"); return sb.toString(); }
From source file:eu.edisonproject.rest.FolderWatcherRunnable.java
private void convertMRResultToCSV(File mrPartPath, String outputPath, boolean calculateAvg) throws IOException { Map<String, Map<String, Double>> map = new HashMap<>(); Map<String, Double> catSimMap; Map<String, List<Double>> avgMap = new HashMap<>(); try (BufferedReader br = new BufferedReader(new FileReader(mrPartPath))) { String line;//w ww .j a v a 2 s . c om int count = 0; while ((line = br.readLine()) != null) { String[] kv = line.split("\t"); String fileName = kv[0]; String cat = kv[1]; String sim = kv[2]; catSimMap = map.get(fileName); if (catSimMap == null) { catSimMap = new HashMap<>(); } catSimMap.put(cat, Double.valueOf(sim)); map.put(fileName, catSimMap); List<Double> list = avgMap.get(cat); if (list == null) { list = new ArrayList<>(); } list.add(Double.valueOf(sim)); avgMap.put(cat, list); } } Set<String> fileNames = map.keySet(); StringBuilder header = new StringBuilder(); header.append("JobId").append(","); for (Map<String, Double> m : map.values()) { for (String c : m.keySet()) { header.append(c).append(","); } break; } header.deleteCharAt(header.length() - 1); header.setLength(header.length()); File csvFile = new File(outputPath); try (PrintWriter out = new PrintWriter(csvFile)) { out.println(header); for (String fName : fileNames) { StringBuilder csvLine = new StringBuilder(); csvLine.append(fName).append(","); catSimMap = map.get(fName); for (String cat : catSimMap.keySet()) { Double sim = catSimMap.get(cat); csvLine.append(sim).append(","); } csvLine.deleteCharAt(csvLine.length() - 1); csvLine.setLength(csvLine.length()); out.println(csvLine.toString()); } } if (calculateAvg) { csvFile = new File(mrPartPath.getParent() + File.separator + CSV_AVG_FILENAME); try (PrintWriter out = new PrintWriter(csvFile)) { Set<String> keys = avgMap.keySet(); for (String k : keys) { List<Double> list = avgMap.get(k); Double sum = 0d; for (Double val : list) { if (!val.isNaN()) { sum += val; } } Double avg = sum / (list.size()); out.println(k + "," + String.valueOf(avg)); } } } }
From source file:com.sun.socialsite.business.DefaultURLStrategy.java
public DefaultURLStrategy() { StringBuilder sb = new StringBuilder(Config.getProperty("socialsite.base.url")); while (sb.toString().endsWith("/")) { sb.deleteCharAt(baseURL.length() - 1); }/* ww w . jav a 2 s .co m*/ baseURL = sb.toString(); log.info("Using base URL " + baseURL); StringBuilder sb1 = new StringBuilder(Config.getProperty("socialsite.profile.url")); while (sb1.toString().endsWith("/")) { sb1.deleteCharAt(baseURL.length() - 1); } profileURL = sb1.toString(); log.info("Using profile URL " + profileURL); StringBuilder sb2 = new StringBuilder(Config.getProperty("socialsite.group.url")); while (sb2.toString().endsWith("/")) { sb2.deleteCharAt(baseURL.length() - 1); } groupURL = sb2.toString(); log.info("Using group URL " + groupURL); StringBuilder sb3 = new StringBuilder(Config.getProperty("socialsite.dashboard.url")); while (sb3.toString().endsWith("/")) { sb3.deleteCharAt(baseURL.length() - 1); } dashboardURL = sb3.toString(); log.info("Using group URL " + dashboardURL); }
From source file:eu.edisonproject.training.wsd.WikipediaOnline.java
private String getReferToTitles(String g) throws UnsupportedEncodingException { String[] titlesArray = g.split("\n"); StringBuilder titles = new StringBuilder(); for (String t : titlesArray) { if (!t.toLowerCase().contains("may refer to:")) { t = URLEncoder.encode(t.split(",")[0], "UTF-8"); if (t.length() > 0) { titles.append(t).append("|"); }/*from ww w .j a va 2s . c o m*/ } } if (titles.length() > 1) { titles.deleteCharAt(titles.length() - 1); titles.setLength(titles.length()); } return titles.toString(); }
From source file:com.ewcms.component.online.service.OnlineService.java
public String mainJSON() { List<Working> workings = workingDAO.getRootChildren(); if (workings.isEmpty()) { return "[]"; }//from w w w. java 2 s. c o m workings = workings.size() > 3 ? workings.subList(0, 3) : workings; for (Working working : workings) { Integer id = working.getId(); List<Working> children = workingDAO.getChildren(id); working.setChildren(children); } StringBuilder builder = new StringBuilder(); builder.append("["); for (Working working : workings) { builder.append("{"); builder.append("\"id\":").append(working.getId()).append(","); builder.append("\"name\":\"").append(working.getName()).append("\","); builder.append("\"children\":").append(childrenJSON(working.getChildren())); builder.append("},"); } builder.deleteCharAt(builder.length() - 1); builder.append("]"); return builder.toString(); }
From source file:com.evolveum.midpoint.prism.ItemDefinition.java
public String debugFlags() { StringBuilder sb = new StringBuilder(); debugFlags(sb);//from w ww . java 2 s . co m // This starts with a collon, we do not want it here if (sb.length() > 0) { sb.deleteCharAt(0); } return sb.toString(); }
From source file:com.hanuor.sapphire.utils.intentation.IntentationPrime.java
public String intentToJSON(Context con, Intent intent) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); String getContextName = null; String getClassName = null;/*from w w w .j ava 2 s . c om*/ try { getClassName = intent.getComponent().getClassName(); getContextName = con.getPackageName(); } catch (Exception e) { e.printStackTrace(); } HashMap<String, String> makeInsideJsonArray = new HashMap<String, String>(); HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("className", getClassName); hashMap.put("context", getContextName); Bundle bundle = intent.getExtras(); if (bundle != null) { Set<String> keys = bundle.keySet(); Iterator<String> it = keys.iterator(); Log.d("SappsnoopDog", "" + keys.size()); while (it.hasNext()) { String key = it.next(); Log.d("Sapptagdog", "TYPE " + bundle.get(key).toString()); Log.d("NERVE", "" + bundle.get(key).getClass().getAnnotations()); String type = bundle.get(key).getClass().getSimpleName(); Log.d("SappDogTAG", key + " OF TYPE " + type); switch (type) { case "String": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "String[]": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString().replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "Integer": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "Double": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "double[]": double[] newDouble = (double[]) bundle.get(key); String fromDouble = Arrays.toString(newDouble); makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromDouble.replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "int[]": int[] newArray = (int[]) bundle.get(key); String fromArray = Arrays.toString(newArray); makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromArray.replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "Boolean": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "boolean[]": boolean[] newBool = (boolean[]) bundle.get(key); String fromBool = Arrays.toString(newBool); makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromBool.replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "Char": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "char[]": char[] newChar = (char[]) bundle.get(key); String fromChar = Arrays.toString(newChar); makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromChar.replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "CharSequence": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "charsequence[]": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString().replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "Byte": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "byte[]": byte[] newByte = (byte[]) bundle.get(key); String fromByte = Arrays.toString(newByte); makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromByte.replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "Float": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "float[]": float[] newFloat = (float[]) bundle.get(key); String fromFloat = Arrays.toString(newFloat); makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromFloat.replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "Short": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "short[]": short[] newShort = (short[]) bundle.get(key); String fromShort = Arrays.toString(newShort); fromShort = fromShort.replace(" ", ""); makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromShort.replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "Long": makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString()); Log.d("SappDogTAG", "bool array"); break; case "long[]": long[] newLong = (long[]) bundle.get(key); String fromLong = Arrays.toString(newLong); makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString().replace(" ", "")); Log.d("SappDogTAG", "bool array"); break; case "ArrayList": ArrayList<Object> obj = (ArrayList<Object>) bundle.get(key); Object[] objArr = obj.toArray(); if (objArr[0] instanceof Integer) { ArrayList<Integer> newIntegerArray = bundle.getIntegerArrayList(key); makeInsideJsonArray.put(key, type + "Integer" + LibraryDatabase.JSONSEPERATOR + newIntegerArray.toString().replace(" ", "")); } else if (objArr[0] instanceof String) { ArrayList<String> newStringArray = bundle.getStringArrayList(key); makeInsideJsonArray.put(key, type + "String" + LibraryDatabase.JSONSEPERATOR + newStringArray.toString().replace(" ", "")); } break; default: // whatever } hashMap.put(key, bundle.get(key).toString()); } } String passArray = mapper.writeValueAsString(makeInsideJsonArray); hashMap.put("intentExtras", passArray); Log.d("GOGTAD", "" + passArray); String intentString = mapper.writeValueAsString(intent); Log.d("IntentString", "" + mapper.writeValueAsString(hashMap)); StringBuilder a1S = new StringBuilder(mapper.writeValueAsString(hashMap)); a1S.deleteCharAt(mapper.writeValueAsString(hashMap).length() - 1); a1S.append(","); String s1t = a1S.toString(); StringBuilder sb = new StringBuilder(intentString); sb.deleteCharAt(0); String retrString = sb.toString(); StringBuilder newS = new StringBuilder(); newS.append(s1t); newS.append(retrString); Log.d("Insnsns", newS.toString()); return newS.toString(); }