List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:it.cnr.icar.eric.client.ui.common.UIUtility.java
public String formatCollectionString(Collection<?> collection) { String value = collection.toString(); StringBuffer sb3 = new StringBuffer(value); // remove leading straight bracket '[' sb3.deleteCharAt(0); // remove ending straight bracket ']' sb3.deleteCharAt(sb3.length() - 1);/*from w w w. jav a 2 s . c om*/ value = sb3.toString(); StringBuffer sb = new StringBuffer(); String[] tokens = value.split(", "); for (int i = 0; i < tokens.length; i++) { String token = tokens[i]; if (i > 0) { sb.append(", "); } // construct hyperlink if (token.indexOf("://") != -1) { StringBuffer sb2 = new StringBuffer(); sb2.append("<a href=\""); sb2.append(token); sb2.append("\" target=\"_new\">"); sb2.append(token); sb2.append("</a>"); token = sb2.toString(); } sb.append(token); } value = sb.toString(); return value; }
From source file:org.ala.report.CsvReportGenerator.java
private String getDescription(String guid) { StringBuffer sb = new StringBuffer(); if (guid == null) { return ""; }//ww w . j a v a 2s . com try { List<SimpleProperty> l = taxonConceptDao.getTextPropertiesFor(guid); for (int i = 0; i < l.size(); i++) { if (l.get(i).getName().endsWith(Predicates.DESCRIPTIVE_TEXT.getLocalPart())) { sb.append("[ " + l.get(i).getValue() + " ];"); } } //remove last ';' mark if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } } catch (Exception e) { logger.debug("ERROR...Description not found: " + guid); } return sb.toString(); }
From source file:org.wso2.carbon.core.bootup.validator.SystemValidator.java
/** * Helper method to hexify a byte array. * @param bytes/*from ww w .j a v a2 s . c o m*/ * @return hexadecimal representation */ private String hexify(byte bytes[]) { char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; StringBuffer buf = new StringBuffer(bytes.length * 2); // appending : marks to make fingerprint more readable for (int i = 0; i < bytes.length; ++i) { buf.append(hexDigits[(bytes[i] & 0xf0) >> 4]); buf.append(hexDigits[bytes[i] & 0x0f] + ":"); } // removing the last : value from the buffer string buf.deleteCharAt(buf.length() - 1); return buf.toString(); }
From source file:com.wabacus.system.dataset.sqldataset.GetDataSetByStoreProcedure.java
private void addRowgroupColsToParams(ReportBean rbean, StringBuffer systemParamsBuf) { AbsListReportDisplayBean alrdbean = (AbsListReportDisplayBean) rbean.getDbean() .getExtendConfigDataForReportType(AbsListReportType.KEY); if (alrdbean != null && alrdbean.getLstRowgroupColsColumn() != null) { StringBuffer rowGroupColsBuf = new StringBuffer(); for (String rowgroupColTmp : alrdbean.getLstRowgroupColsColumn()) { if (rowgroupColTmp != null && !rowgroupColTmp.trim().equals("")) rowGroupColsBuf.append(rowgroupColTmp).append(","); }/*from w w w . j av a 2s. co m*/ if (rowGroupColsBuf.length() > 0) { if (rowGroupColsBuf.charAt(rowGroupColsBuf.length() - 1) == ',') rowGroupColsBuf.deleteCharAt(rowGroupColsBuf.length() - 1); systemParamsBuf.append("{[(<rowgroup_cols:" + rowGroupColsBuf.toString() + ">)]}"); } } }
From source file:org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter.java
private InterpreterResult buildAggResponseMessage(List<AggWrapper> aggregations) { final InterpreterResult.Type resType = InterpreterResult.Type.TABLE; String resMsg = ""; final Set<String> headerKeys = new HashSet<>(); final List<Map<String, Object>> buckets = new LinkedList<>(); for (final AggWrapper aggregation : aggregations) { final Map<String, Object> bucketMap = JsonFlattener.flattenAsMap(aggregation.getResult()); headerKeys.addAll(bucketMap.keySet()); buckets.add(bucketMap);/*from w w w .ja v a 2s. c o m*/ } final StringBuffer buffer = new StringBuffer(); final String[] keys = headerKeys.toArray(new String[0]); for (final String key : keys) { buffer.append("\t" + key); } buffer.deleteCharAt(0); for (final Map<String, Object> bucket : buckets) { buffer.append("\n"); for (final String key : keys) { buffer.append(bucket.get(key)).append("\t"); } buffer.deleteCharAt(buffer.length() - 1); } resMsg = buffer.toString(); return new InterpreterResult(InterpreterResult.Code.SUCCESS, resType, resMsg); }
From source file:com.hexin.core.dao.BaseDaoSupport.java
private void debugSql(String sql, Object[] args) { if (logger.isDebugEnabled()) { StringBuffer buffer = new StringBuffer(); buffer.append("sql: "); buffer.append(sql);//w ww . j a v a 2s . c o m buffer.append(", args: "); for (Object arg : args) { buffer.append(arg); buffer.append(","); } buffer.deleteCharAt(buffer.length() - 1); logger.debug(buffer.toString()); } }
From source file:org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter.java
private InterpreterResult buildAggResponseMessage(Aggregations aggregations) { // Only the result of the first aggregation is returned //// w w w .ja va 2s . co m final Aggregation agg = aggregations.asList().get(0); InterpreterResult.Type resType = InterpreterResult.Type.TEXT; String resMsg = ""; if (agg instanceof InternalMetricsAggregation) { resMsg = XContentHelper.toString((InternalMetricsAggregation) agg).toString(); } else if (agg instanceof InternalSingleBucketAggregation) { resMsg = XContentHelper.toString((InternalSingleBucketAggregation) agg).toString(); } else if (agg instanceof InternalMultiBucketAggregation) { final Set<String> headerKeys = new HashSet<>(); final List<Map<String, Object>> buckets = new LinkedList<>(); final InternalMultiBucketAggregation multiBucketAgg = (InternalMultiBucketAggregation) agg; for (final MultiBucketsAggregation.Bucket bucket : multiBucketAgg.getBuckets()) { try { final XContentBuilder builder = XContentFactory.jsonBuilder(); bucket.toXContent(builder, null); final Map<String, Object> bucketMap = JsonFlattener.flattenAsMap(builder.string()); headerKeys.addAll(bucketMap.keySet()); buckets.add(bucketMap); } catch (final IOException e) { logger.error("Processing bucket: " + e.getMessage(), e); } } final StringBuffer buffer = new StringBuffer(); final String[] keys = headerKeys.toArray(new String[0]); for (final String key : keys) { buffer.append("\t" + key); } buffer.deleteCharAt(0); for (final Map<String, Object> bucket : buckets) { buffer.append("\n"); for (final String key : keys) { buffer.append(bucket.get(key)).append("\t"); } buffer.deleteCharAt(buffer.length() - 1); } resType = InterpreterResult.Type.TABLE; resMsg = buffer.toString(); } return new InterpreterResult(InterpreterResult.Code.SUCCESS, resType, resMsg); }
From source file:indexer.DocVector.java
String quantize(Cell updatedCell) { StringBuffer buff = new StringBuffer(); System.out.println("Quantization of cell: " + keys[updatedCell.axisId]); keys[updatedCell.axisId] = updatedCell; // e.g. replace 1_8 with 1_8_15 or 1_9_16 with 1_9_16_87 (another offset at a fine-grained level) System.out.println("Updated to: " + keys[updatedCell.axisId]); for (int i = 0; i < keys.length; i++) { buff.append(keys[i]).append(" "); }//from w ww .ja v a 2 s . com buff.deleteCharAt(buff.length() - 1); quantized = buff.toString(); return buff.toString(); }
From source file:net.sourceforge.eclipsetrader.opentick.Feed.java
public void snapshot() { SimpleDateFormat usDateTimeParser = new SimpleDateFormat("MM/dd/yyyy h:mma"); SimpleDateFormat usDateParser = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat usTimeParser = new SimpleDateFormat("h:mma"); NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); // Builds the url for quotes download String host = "quote.yahoo.com"; StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols="); for (Iterator iter = subscribedSecurities.iterator(); iter.hasNext();) { Security security = (Security) iter.next(); url = url.append(security.getCode() + "+"); }//from w w w . j av a 2 s . co m if (url.charAt(url.length() - 1) == '+') url.deleteCharAt(url.length() - 1); url.append("&format=sl1d1t1c1ohgvbap"); // Read the last prices String line = ""; try { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); BundleContext context = OpenTickPlugin.getDefault().getBundle().getBundleContext(); ServiceReference reference = context.getServiceReference(IProxyService.class.getName()); if (reference != null) { IProxyService proxy = (IProxyService) context.getService(reference); IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE); if (data != null) { if (data.getHost() != null) client.getHostConfiguration().setProxy(data.getHost(), data.getPort()); if (data.isRequiresAuthentication()) client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(data.getUserId(), data.getPassword())); } } HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((line = in.readLine()) != null) { String[] item = line.split(","); if (line.indexOf(";") != -1) item = line.split(";"); Double open = null, high = null, low = null, close = null; Quote quote = new Quote(); // 2 = Date // 3 = Time try { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US); usDateTimeParser.setTimeZone(c.getTimeZone()); usDateParser.setTimeZone(c.getTimeZone()); usTimeParser.setTimeZone(c.getTimeZone()); String date = stripQuotes(item[2]); if (date.indexOf("N/A") != -1) date = usDateParser.format(Calendar.getInstance().getTime()); String time = stripQuotes(item[3]); if (time.indexOf("N/A") != -1) time = usTimeParser.format(Calendar.getInstance().getTime()); c.setTime(usDateTimeParser.parse(date + " " + time)); c.setTimeZone(TimeZone.getDefault()); quote.setDate(c.getTime()); } catch (Exception e) { System.out.println(e.getMessage() + ": " + line); } // 1 = Last price or N/A if (item[1].equalsIgnoreCase("N/A") == false) quote.setLast(numberFormat.parse(item[1]).doubleValue()); // 4 = Change // 5 = Open if (item[5].equalsIgnoreCase("N/A") == false) open = new Double(numberFormat.parse(item[5]).doubleValue()); // 6 = Maximum if (item[6].equalsIgnoreCase("N/A") == false) high = new Double(numberFormat.parse(item[6]).doubleValue()); // 7 = Minimum if (item[7].equalsIgnoreCase("N/A") == false) low = new Double(numberFormat.parse(item[7]).doubleValue()); // 8 = Volume if (item[8].equalsIgnoreCase("N/A") == false) quote.setVolume(numberFormat.parse(item[8]).intValue()); // 9 = Bid Price if (item[9].equalsIgnoreCase("N/A") == false) quote.setBid(numberFormat.parse(item[9]).doubleValue()); // 10 = Ask Price if (item[10].equalsIgnoreCase("N/A") == false) quote.setAsk(numberFormat.parse(item[10]).doubleValue()); // 11 = Close Price if (item[11].equalsIgnoreCase("N/A") == false) close = new Double(numberFormat.parse(item[11]).doubleValue()); // 0 = Code String symbol = stripQuotes(item[0]); for (Iterator iter = subscribedSecurities.iterator(); iter.hasNext();) { Security security = (Security) iter.next(); if (symbol.equalsIgnoreCase(security.getCode())) security.setQuote(quote, open, high, low, close); } } in.close(); } catch (Exception e) { System.out.println(e.getMessage() + ": " + line); e.printStackTrace(); } }
From source file:org.latticesoft.util.common.StringUtil.java
/** * Formats a list into string//from w w w .j a va2 s .com * @param l the list to be formatted * @param separator the separator between the elements * @param enclosing to include the enclosing sq brackets or not * @return the formatted string */ public static String formatList(List l, String separator, boolean enclosing) { if (l == null || separator == null) { return null; } StringBuffer sb = new StringBuffer(); if (enclosing) { sb.append("["); } for (int i = 0; i < l.size(); i++) { Object o = l.get(i); if (o != null) { sb.append(o).append(separator); } } int len = separator.length(); if (sb.length() > len) { int startIndex = sb.length() - len; int endIndex = sb.length(); String s = sb.substring(startIndex, endIndex); if (s.equals(separator)) { for (int i = 0; i < len; i++) { sb.deleteCharAt(sb.length() - 1); } } } if (enclosing) { sb.append("]"); } return sb.toString(); }