List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:net.sourceforge.vulcan.dotnet.NAntBuildTool.java
private void constructLoggerArgs(List<String> args) { UdpEventSource eventSource = (UdpEventSource) this.eventSource; final StringBuilder sb = new StringBuilder("-listener:"); sb.append(NANT_LOGGER_CLASS_NAME);//from w w w . ja v a2 s . c o m args.add(sb.toString()); sb.delete(0, sb.length()); sb.append("-ext:"); sb.append(pluginDir.getAbsolutePath()); sb.append(File.separatorChar); sb.append("NantBuildListener.dll"); args.add(sb.toString()); final Map<String, String> antProps = getAntProps(); antProps.put(Constants.HOST_PROPERTY, eventSource.getHostname()); antProps.put(Constants.PORT_PROPERTY, Integer.toString(eventSource.getPort())); }
From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java
private static void issueNotification(Context context, Set<String> addedMilestones, Set<String> removedMilestones, Map<String, int[]> changedProgresses) { String title = context.getString(R.string.notification_title); StringBuilder message = new StringBuilder(); // Changed progresses for (String milestoneTitle : changedProgresses.keySet()) { int oldProgress = changedProgresses.get(milestoneTitle)[0]; int newProgress = changedProgresses.get(milestoneTitle)[1]; message.append("\n").append(String.format(context.getString(R.string.notific_msg_text_format), milestoneTitle, oldProgress, newProgress)); }// w w w . j a v a2s . com // Added milestones for (String milestoneTitle : addedMilestones) { message.append("\n").append(context.getString(R.string.milestone_added_notification, milestoneTitle)); } // Removed milestones for (String milestoneTitle : removedMilestones) { message.append("\n").append(context.getString(R.string.milestone_removed_notification, milestoneTitle)); } // Remove first newline message.delete(0, 1); // Create PendingIntent PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); boolean sound = pref.getBoolean(Constants.NOTIFICATION_SOUND_PREF, true); boolean vibrate = pref.getBoolean(Constants.NOTIFICATION_VIBRATE_PREF, true); boolean light = pref.getBoolean(Constants.NOTIFICATION_LIGHT_PREF, true); int defaults = 0; if (sound) defaults = defaults | Notification.DEFAULT_SOUND; if (vibrate) defaults = defaults | Notification.DEFAULT_VIBRATE; if (light) defaults = defaults | Notification.DEFAULT_LIGHTS; // Build the notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setSmallIcon(R.mipmap.notification_small_icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setDefaults(defaults).setAutoCancel(true); // Issue the notification NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(PROGRESS_NOTIFICATION_ID, builder.build()); }
From source file:com.github.p4535992.database.datasource.database.data.Dao.java
private void removeSuffix(StringBuilder script, String str) { if (script.toString().endsWith(str)) { script.delete(script.length() - str.length(), script.length()); }//from ww w . jav a 2s.c o m }
From source file:io.cloudslang.content.httpclient.consume.HeadersConsumer.java
public void consume(Map<String, String> returnResult) { StringBuilder result = new StringBuilder(); if (headers != null) { for (Header header : headers) { result.append(header.toString()).append("\r\n"); }// w w w . java 2 s . co m if (result.length() != 0) { result.delete(result.length() - 2, result.length()); } } returnResult.put(CSHttpClient.RESPONSE_HEADERS, result.toString()); }
From source file:com.github.parisoft.resty.request.HttpRequest.java
private void constructHeaders() { for (Entry<String, List<String>> header : request.headers().entrySet()) { final StringBuilder valueBuilder = new StringBuilder(); for (String value : header.getValue()) { valueBuilder.append(value).append(", "); }//www . java 2 s . com valueBuilder.delete(valueBuilder.length() - 2, valueBuilder.length()); addHeader(header.getKey(), valueBuilder.toString()); } }
From source file:de.iteratec.iteraplan.common.GeneralHelper.java
/** * Returns a String made from the concatenation of the attribute names and values of the given Collection of associations, * separated by the standard {@link Constants#BUILDINGBLOCKSEP}. * /* ww w. j av a2s . com*/ * @param assoc * A Isr2BoAssociation Object * * @param isAttributeName * Decides whether the attribute name is returned. * * @return Concatenated attributes names and values of the association. */ public static String getAttributValuesForAssociation( AbstractAssociation<? extends BuildingBlock, ? extends BuildingBlock> assoc, boolean isAttributeName) { StringBuilder attributes = new StringBuilder(); HashBucketMap<AttributeType, AttributeValue> attributeMap = assoc.getAttributeTypeToAttributeValues(); if (attributeMap.size() != 0) { Set<AttributeType> atSet = attributeMap.keySet(); attributes.append(" ("); for (AttributeType at : atSet) { if (isAttributeName) { // append the name of the attribute attributes.append(at.getName()); attributes.append(": "); } List<AttributeValue> avList = attributeMap.get(at); for (AttributeValue attValue : avList) { attributes.append(attValue.getValue().toString()); // append attribute value attributes.append(Constants.BUILDINGBLOCKSEP); // append separator } } attributes.delete(attributes.length() - 2, attributes.length()); attributes.append(")"); } return attributes.toString(); }
From source file:org.apache.tajo.engine.planner.physical.HashBasedColPartitionStoreExec.java
@Override public Tuple next() throws IOException { Tuple tuple;//w ww. ja va 2 s.c o m StringBuilder sb = new StringBuilder(); while ((tuple = child.next()) != null) { // set subpartition directory name sb.delete(0, sb.length()); if (keyIds != null) { for (int i = 0; i < keyIds.length; i++) { Datum datum = tuple.get(keyIds[i]); if (i > 0) sb.append("/"); sb.append(keyNames[i]).append("="); sb.append(datum.asChars()); } } // add tuple Appender appender = getAppender(sb.toString()); appender.addTuple(tuple); } List<TableStats> statSet = new ArrayList<TableStats>(); for (Map.Entry<String, Appender> entry : appenderMap.entrySet()) { Appender app = entry.getValue(); app.flush(); app.close(); statSet.add(app.getStats()); } // Collect and aggregated statistics data TableStats aggregated = StatisticsUtil.aggregateTableStat(statSet); context.setResultStats(aggregated); return null; }
From source file:com.linkedin.urls.PathNormalizer.java
License:asdf
/** * 1. Replaces "/./" with "/" recursively. * 2. "/blah/asdf/.." -> "/blah"/*from w w w .j a v a 2 s. c om*/ * 3. "/blah/blah2/blah3/../../blah4" -> "/blah/blah4" * 4. "//" -> "/" * 5. Adds a slash at the end if there isn't one */ private static String sanitizeDotsAndSlashes(String path) { StringBuilder stringBuilder = new StringBuilder(path); Stack<Integer> slashIndexStack = new Stack<Integer>(); int index = 0; while (index < stringBuilder.length() - 1) { if (stringBuilder.charAt(index) == '/') { slashIndexStack.add(index); if (stringBuilder.charAt(index + 1) == '.') { if (index < stringBuilder.length() - 2 && stringBuilder.charAt(index + 2) == '.') { //If it looks like "/../" or ends with "/.." if (index < stringBuilder.length() - 3 && stringBuilder.charAt(index + 3) == '/' || index == stringBuilder.length() - 3) { boolean endOfPath = index == stringBuilder.length() - 3; slashIndexStack.pop(); int endIndex = index + 3; // backtrack so we can detect if this / is part of another replacement index = slashIndexStack.empty() ? -1 : slashIndexStack.pop() - 1; int startIndex = endOfPath ? index + 1 : index; stringBuilder.delete(startIndex + 1, endIndex); } } else if (index < stringBuilder.length() - 2 && stringBuilder.charAt(index + 2) == '/' || index == stringBuilder.length() - 2) { boolean endOfPath = index == stringBuilder.length() - 2; slashIndexStack.pop(); int startIndex = endOfPath ? index + 1 : index; stringBuilder.delete(startIndex, index + 2); // "/./" -> "/" index--; // backtrack so we can detect if this / is part of another replacement } } else if (stringBuilder.charAt(index + 1) == '/') { slashIndexStack.pop(); stringBuilder.deleteCharAt(index); index--; } } index++; } if (stringBuilder.length() == 0) { stringBuilder.append("/"); //Every path has at least a slash } return stringBuilder.toString(); }
From source file:eu.ggnet.dwoss.util.ImageFinder.java
public int nextImageId() { if (path == null || (!path.exists() && !path.isDirectory())) return -1; int max = 0;//from w w w.j av a2s . c o m for (String name : path.list()) { StringBuilder rev = new StringBuilder(name); rev.reverse(); int p = rev.indexOf("."); if (p < 0) continue; rev.delete(0, p + 1); p = rev.indexOf("_"); if (p < 0) continue; rev.delete(p, rev.length()); rev.reverse(); int val = 0; try { val = Integer.parseInt(rev.toString()); } catch (NumberFormatException e) { continue; } if (max < val) max = val; } return max + 1; }
From source file:com.edgenius.wiki.render.RenderUtil.java
/** * @param input//from w w w. j a va 2 s . c om * @param key * @param regions * @param newlineKey * @return */ public static CharSequence createRegion(CharSequence input, String key, Collection<Region> regions, String newlineKey) { if (regions == null || regions.size() == 0) return input; //first, web split whole text by special border tag string some think like "key_regionKey_S|E" input = createRegionBorder(input, key, regions, newlineKey); //then we split them one by one. The split is dependent on the RegionComparator(), which ensure the split //from end to start, and from inside to outside. And this makes easier on below replacement process. Set<Region> sortRegions = new TreeSet<Region>(new RegionComparator()); sortRegions.addAll(regions); StringBuilder buf = new StringBuilder(input); StringBuilder regKey = new StringBuilder(key); int ks = key.length(); for (Region region : sortRegions) { //See our issue http://bug.edgenius.com/issues/34 //and SUN Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993 Pattern pat = Pattern.compile(new StringBuilder(key).append(region.getKey()).append("S(.*?)") .append(key).append(region.getKey()).append("E").toString(), Pattern.DOTALL); try { Matcher matcher = pat.matcher(buf); if (matcher.find()) { region.setBody(matcher.group(1)); buf.delete(matcher.start(), matcher.end()); regKey.delete(ks, regKey.length()); buf.insert(matcher.start(), regKey.append(region.getKey()).append(Region.REGION_SUFFIX)); } } catch (StackOverflowError e) { AuditLogger.error("StackOverflow Error in RenderUtil.createRegion. Input[" + buf + "] Pattern [" + pat.pattern() + "]"); } catch (Throwable e) { AuditLogger.error("Unexpected error in RenderUtil.createRegion. Input[" + buf + "] Pattern [" + pat.pattern() + "]", e); } } return buf; }