List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:com.viadee.acceptancetests.roo.addon.AcceptanceTestsOperations.java
private String methodNameFromStory(String story) { String[] words = story.split(" "); StringBuilder methodName = new StringBuilder(); methodName.append(Character.toLowerCase(words[0].charAt(0))); for (String word : words) { methodName.append(Character.toUpperCase(word.charAt(0))); methodName.append(word.substring(1)); }//from w ww.j av a 2s . co m methodName.deleteCharAt(1); return methodName.toString(); }
From source file:name.chenyuelin.aopAdvisor.DebugLoggerAdvisor.java
@Override public void before(Method method, Object[] args, Object target) throws Throwable { if (LOG.isDebugEnabled()) { Log log = getLog(target);/*from ww w . j a va 2 s . c o m*/ if (log != null && log.isDebugEnabled()) { StringBuilder debugMessage = new StringBuilder(50); debugMessage.append(method.getName()).append(" start.\nParameters:\n"); for (Object arg : args) { Class<?> argClass = arg.getClass(); debugMessage.append(argClass.getSimpleName()).append(":").append(arg).append("\n"); } if (debugMessage.length() > 0) { debugMessage.deleteCharAt(debugMessage.length() - 1); } log.debug(debugMessage); } } }
From source file:com.taobao.tddl.common.sync.RowBasedReplicationExecutor.java
private static SqlArgs buildSlaveUpdateSql(RowBasedReplicationContext context, Map<String, Object> masterRow, SlaveInfo slave) {//from ww w .j a v a 2 s . c o m StringBuilder sql = new StringBuilder("update ").append(slave.getName()).append(" set "); List<Object> args = new ArrayList<Object>(); List<String> argnames = new ArrayList<String>(); String[] cols = slave.getColumns(); Collection<String> colomnNames = cols != null && cols.length != 0 ? Arrays.asList(cols) : masterRow.keySet(); for (String columnName : colomnNames) { sql.append(columnName).append("=? ,"); args.add(slave.changeToDefaultOnNull(columnName, masterRow.get(columnName))); argnames.add(columnName); } sql.deleteCharAt(sql.length() - 1); sql.append(" where ").append(context.getPrimaryKeyColumn()).append(" = ?"); args.add(masterRow.get(context.getPrimaryKeyColumn())); argnames.add(context.getPrimaryKeyColumn()); if (slave.getDatabaseShardColumn() != null && !slave.getDatabaseShardColumn().equalsIgnoreCase(context.getPrimaryKeyColumn())) { sql.append(" and ").append(slave.getDatabaseShardColumn()).append(" = ?"); args.add(masterRow.get(slave.getDatabaseShardColumn())); argnames.add(slave.getDatabaseShardColumn()); } if (slave.getTableShardColumn() != null && !slave.getTableShardColumn().equalsIgnoreCase(context.getPrimaryKeyColumn()) && !slave.getTableShardColumn().equalsIgnoreCase(slave.getDatabaseShardColumn())) { sql.append(" and ").append(slave.getTableShardColumn()).append(" = ?"); args.add(masterRow.get(slave.getTableShardColumn())); argnames.add(slave.getTableShardColumn()); } if (!slave.isNoSyncVersion()) { switch (slave.getDbType()) { case MYSQL: sql.append(" and ifnull("); break; case ORACLE: sql.append(" and nvl("); break; default: throw new RuntimeException("dbType"); } sql.append(SyncConstants.SYNC_VERSION_COLUMN_NAME).append(", ?)").append(" < ?"); args.add(SyncConstants.SYNC_VERSION_DEFAULT_VALUE); argnames.add(SyncConstants.SYNC_VERSION_COLUMN_NAME); args.add(masterRow.get(SyncConstants.SYNC_VERSION_COLUMN_NAME)); argnames.add(SyncConstants.SYNC_VERSION_COLUMN_NAME); } return new SqlArgs(sql.toString(), args, argnames); }
From source file:net.duckling.falcon.api.orm.DAOUtils.java
private String format(StringBuilder sb) { if (sb.indexOf(",") > 0) { sb.deleteCharAt(sb.lastIndexOf(",")); }//w ww . j a v a 2s. c o m return sb.toString(); }
From source file:com.mnt.base.util.HttpUtil.java
public static String processGetRequest2Text(String url, Map<String, Object> parameters, Map<String, String> headerValue) { HttpURLConnection connection = null; StringBuilder sb = new StringBuilder(url); if (!CommonUtil.isEmpty(parameters)) { if (url.contains("?")) { sb.append("&"); } else {/*from w ww .j a va 2 s .co m*/ sb.append("?"); } Object value = null; for (String key : parameters.keySet()) { value = parameters.get(key); if (value instanceof Collection<?> || value instanceof Map<?, ?>) { try { value = JSONTool.convertObjectToJson(value); } catch (Exception e) { log.error("error while convert object to json, " + value); value = null; } } if (value != null) { try {// encode the parameters sb.append(URLEncoder.encode(key, "utf8")).append("=") .append(URLEncoder.encode(value.toString(), "utf8")); } catch (UnsupportedEncodingException e) { // skip it } sb.append("&"); } } sb.deleteCharAt(sb.length() - 1); } try { connection = (HttpURLConnection) new URL(sb.toString()).openConnection(); } catch (IOException e) { log.error("Error while process http get request.", e); } if (connection != null) { try { connection.setRequestMethod("GET"); } catch (ProtocolException e) { log.error("should not happen to get error while set the request method as GET.", e); } setTimeout(connection); if (!CommonUtil.isEmpty(headerValue)) { for (String key : headerValue.keySet()) { connection.setRequestProperty(key, headerValue.get(key)); } } String resultStr = null; try { connection.connect(); resultStr = readData(connection.getInputStream()); } catch (IOException e) { log.error("fail to connect to url: " + sb, e); } finally { connection.disconnect(); } return resultStr; } return null; }
From source file:com.ewcms.component.online.service.OnlineService.java
private String childrenJSON(List<Working> workings) { if (workings.isEmpty()) { return "[]"; }/*from w w w . j av a 2s . c om*/ 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("},"); } builder.deleteCharAt(builder.length() - 1); builder.append("]"); return builder.toString(); }
From source file:org.apache.spark.streaming.amqp.JavaAMQPBrokerStreamSuite.java
@Test public void testAMQPReceiveMapBody() { Function converter = new JavaAMQPJsonFunction(); Map<Object, Object> map = new HashMap<>(); map.put("field_a", "a string"); map.put("field_b", 1); JavaReceiverInputDStream<String> receiveStream = AMQPUtils.createStream(this.jssc, this.amqpTestUtils.host(), this.amqpTestUtils.port(), this.address, converter, StorageLevel.MEMORY_ONLY()); JavaDStream<String> mapStream = receiveStream.map(jsonMsg -> { ObjectMapper mapper = new ObjectMapper(); List<String> listFinal = new ArrayList<>(); // get an itarator on all fields of "section" that is actually a map Iterator<Entry<String, JsonNode>> iterator = mapper.readTree(jsonMsg).get("body").get("section") .fields();//from w ww . j ava2s . c o m while (iterator.hasNext()) { Entry<String, JsonNode> entry = iterator.next(); listFinal.add(entry.getKey() + "=" + entry.getValue().asText()); } return StringUtils.join(listFinal, ','); }); List<String> receivedMessage = new ArrayList<>(); mapStream.foreachRDD(rdd -> { if (!rdd.isEmpty()) { receivedMessage.add(rdd.first()); } }); jssc.start(); this.amqpTestUtils.sendComplexMessage(address, map); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } StringBuilder sbuilder = new StringBuilder(); for (Entry<Object, Object> entry : map.entrySet()) { sbuilder.append(entry.getKey() + "=" + entry.getValue() + ","); } sbuilder.deleteCharAt(sbuilder.length() - 1); assert (receivedMessage.get(0).equals(sbuilder.toString())); jssc.stop(); }
From source file:com.msopentech.odatajclient.engine.uri.AbstractURIBuilder.java
@Override public URIBuilder appendKeySegment(final Map<String, Object> segmentValues) { if (!getConfiguration().isKeyAsSegment()) { final StringBuilder keyBuilder = new StringBuilder().append('('); for (Map.Entry<String, Object> entry : segmentValues.entrySet()) { keyBuilder.append(entry.getKey()).append('=').append(URIUtils.escape(entry.getValue())); keyBuilder.append(','); }//from w w w. j ava2 s .c o m keyBuilder.deleteCharAt(keyBuilder.length() - 1).append(')'); segments.add(new URIBuilder.Segment(SegmentType.KEY, keyBuilder.toString())); } return this; }
From source file:fr.ribesg.bukkit.api.chat.Chat.java
private static void appendItemDisplay(final StringBuilder builder, final ItemMeta meta) { builder.append("display{"); if (meta.hasDisplayName()) { builder.append("Name:"); builder.append(Chat.escapeString(meta.getDisplayName())); builder.append(','); }/* w w w . j a va 2s. c o m*/ if (meta.hasLore()) { builder.append("Lore:["); final Iterator<String> it = meta.getLore().iterator(); while (it.hasNext()) { builder.append(Chat.escapeString(it.next())); if (it.hasNext()) { builder.append(','); } } builder.append("],"); } if (meta instanceof LeatherArmorMeta) { final LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta; builder.append("color:").append(leatherArmorMeta.getColor().asRGB()); } if (builder.charAt(builder.length() - 1) == ',') { builder.deleteCharAt(builder.length() - 1); } builder.append("},"); }
From source file:com.github.jillesvangurp.urlbuilder.UrlBuilder.java
/** * @return URL as a String. Note, you can also use toString. *//* ww w . ja v a 2 s . c om*/ public String build() { StringBuilder result = new StringBuilder(url); if (params.size() > 0) { result.append('?'); for (Entry<String, String> entry : params) { String value = entry.getValue(); result.append(entry.getKey() + '=' + value); result.append('&'); } result.deleteCharAt(result.length() - 1); // remove trailing & } return result.toString(); }