List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:com.cloud.utils.StringUtils.java
public static String cleanupTags(String tags) { if (tags != null) { final String[] tokens = tags.split(","); final StringBuilder t = new StringBuilder(); for (int i = 0; i < tokens.length; i++) { t.append(tokens[i].trim()).append(","); }/*from www . j ava 2 s . c o m*/ t.delete(t.length() - 1, t.length()); tags = t.toString(); } return tags; }
From source file:com.dsh105.commodus.StringUtil.java
/** * Combines a set of strings into a single string, separated by the given character set * * @param startIndex index to begin the separation at, inclusive * @param endIndex index to end the separation at, exclusive * @param separator character set included between each part of the given array * @param stringArray array to combine/* w w w . j a v a2s .c om*/ * @return the combined string */ public static String combineArray(int startIndex, int endIndex, String separator, String... stringArray) { if (stringArray == null || startIndex >= endIndex) { return ""; } else { StringBuilder builder = new StringBuilder(); for (int i = startIndex; i < endIndex; i++) { builder.append(stringArray[i]); builder.append(separator); } builder.delete(builder.length() - separator.length(), builder.length()); return builder.toString(); } }
From source file:Main.java
private static String getControlByType(String prefs, String key, Object type, String value) { String htmlControl = ""; String htmlControlVal = ""; key = prefs + "_debugghostseperator_" + key; if (type instanceof Boolean) { htmlControlVal = (value.equalsIgnoreCase("true")) ? "checked=\"checked\"" : ""; htmlControl = "<input id=\"" + key + "\" type=\"checkbox\" value=\"" + key + "\" " + htmlControlVal + " />"; } else if (type instanceof Integer) { htmlControlVal = value;// w w w . ja v a 2s . c o m htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\"" + key + "\">"; } else if (type instanceof String) { htmlControlVal = (value != null) ? value : "null"; htmlControl = "<input class=\"form-control\" type=\"text\" value=\"" + htmlControlVal + "\" id=\"" + key + "\">"; } else if (type instanceof Float) { htmlControlVal = value; htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\"" + key + "\">"; } else if (type instanceof Long) { htmlControlVal = value; htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\"" + key + "\">"; } else if (type instanceof HashSet) { StringBuilder sb = new StringBuilder(); HashSet<String> valueSet = (HashSet) type; int rowHeight = Math.min(valueSet.size(), 5); sb.append("<textarea class=\"form-control\" id=\"" + key + "\" rows=\"" + rowHeight + "\" style=\"margin-top: 0px; margin-bottom: 0px;\">"); for (String val : valueSet) { sb.append(val); sb.append("\r\n"); } sb.delete(sb.length() - 2, sb.length()); sb.append("</textarea>"); htmlControl = sb.toString(); } else { htmlControl = "[DebugGhost has no control configured for type '" + type.getClass().getSimpleName() + "']"; } htmlControl += "<input id=\"" + key + "_TYPE\" type=\"hidden\" value=\"" + type.getClass().getSimpleName() + "\" />"; return htmlControl; }
From source file:com.gargoylesoftware.htmlunit.util.DebuggingWebConnection.java
/** * Produces a String that will produce a JS map like "{'key1': 'value1', 'key 2': 'value2'}" * @param headers a list of {@link NameValuePair} * @return the JS String/* w w w . j ava 2s. com*/ */ static String nameValueListToJsMap(final List<NameValuePair> headers) { if (headers == null || headers.isEmpty()) { return "{}"; } final StringBuilder buffer = new StringBuilder("{"); for (final NameValuePair header : headers) { buffer.append("'" + header.getName() + "': '" + escapeJSString(header.getValue()) + "', "); } buffer.delete(buffer.length() - 2, buffer.length()); buffer.append("}"); return buffer.toString(); }
From source file:org.apache.marmotta.platform.ldp.util.LdpUtils.java
public static String getAcceptPostHeader(String extraFormats) { final Collection<RDFFormat> rdfFormats = filterAvailableParsers(LdpService.SERVER_PREFERED_RDF_FORMATS); final StringBuilder sb = new StringBuilder(); for (RDFFormat rdfFormat : rdfFormats) { sb.append(rdfFormat.getDefaultMIMEType()); sb.append(", "); }//from w w w. ja va 2 s. c o m if (StringUtils.isNotBlank(extraFormats)) { sb.append(extraFormats); } else { sb.delete(sb.length() - 2, sb.length()); } return sb.toString(); }
From source file:edu.kit.dama.util.ZipUtils.java
/** * Compress all files of one directory with given extensions to a single zip * file./*from w w w . j a va2 s . c om*/ * * @param pZipFile resulting zip File. Existing file will be overwritten! * @param pDirectory directory to explore. * @param pExtension allowed file name extensions of files to compress * @return success or not. */ public static boolean zipDirectory(final File pZipFile, final File pDirectory, final String... pExtension) { boolean success = false; File[] files = pDirectory.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { boolean accept = false; String lowerCase = name.toLowerCase(); if (pExtension != null) { for (String extension : pExtension) { if (lowerCase.endsWith(extension.toLowerCase())) { accept = true; break; } } } else { accept = true; } return accept; } }); if (LOGGER.isDebugEnabled()) { String fileSeparator = ", "; LOGGER.debug("Zip files to " + pZipFile.getName()); StringBuilder sb = new StringBuilder("Selected files: "); for (File file : files) { sb.append(file.getName()).append(fileSeparator); } int lastIndex = sb.lastIndexOf(fileSeparator); sb.delete(lastIndex, lastIndex + fileSeparator.length()); LOGGER.debug(sb.toString()); } try { zip(files, pDirectory.getPath(), pZipFile); success = true; } catch (IOException ex) { LOGGER.error("Error while zipping files!", ex); } return success; }
From source file:Main.java
/** * Returns the path of one File relative to another. * <p/>//from w ww . jav a 2 s.c o m * From http://stackoverflow.com/questions/204784 * * @param target the target directory * @param base the base directory * @return target's path relative to the base directory */ public static String getRelativePath(File target, File base) { String[] baseComponents; String[] targetComponents; try { baseComponents = base.getCanonicalPath().split(Pattern.quote(File.separator)); targetComponents = target.getCanonicalPath().split(Pattern.quote(File.separator)); } catch (IOException e) { return target.getAbsolutePath(); } // skip common components int index = 0; for (; index < targetComponents.length && index < baseComponents.length; ++index) { if (!targetComponents[index].equals(baseComponents[index])) break; } StringBuilder result = new StringBuilder(); if (index != baseComponents.length) { // backtrack to base directory for (int i = index; i < baseComponents.length; ++i) result.append("..").append(File.separator); } for (; index < targetComponents.length; ++index) result.append(targetComponents[index]).append(File.separator); if (!target.getPath().endsWith("/") && !target.getPath().endsWith("\\")) { // remove final path separator result.delete(result.length() - "/".length(), result.length()); } return result.toString(); }
From source file:Main.java
public static String fillTextBox(TextPaint paint, int fragmentWidth, String source) { StringBuilder sb = new StringBuilder(); final int length = source.length(); // Display whole words only int lastWhiteSpace = 0; for (int index = 0; paint.measureText(sb.toString()) < fragmentWidth && index < length; index++) { char c = source.charAt(index); if (Character.isWhitespace(c)) lastWhiteSpace = index;/*from ww w . j av a2 s .c o m*/ sb.append(c); } if (sb.length() != length) { // Delete last word part sb.delete(lastWhiteSpace, sb.length()); sb.append("..."); } return sb.toString(); }
From source file:com.openteach.diamond.network.waverider.network.Packet.java
public static void dump(ByteBuffer buffer) { logger.info(/*from ww w . j av a2s . co m*/ "==========================================================================dump data=========================================================================="); byte[] bytes = buffer.array(); StringBuilder sb = new StringBuilder(""); for (int i = 0; i < bytes.length; i++) { sb.append(bytes[i]); if (i % 80 == 0 && i > 0) { logger.info(sb); sb.delete(0, sb.length()); } } logger.info( "==========================================================================dump data end======================================================================"); }
From source file:net.certiv.json.util.Strings.java
public static String asString(ArrayList<String> values, boolean asPrefix, String sep) { StringBuilder sb = new StringBuilder(); String pf = asPrefix ? sep : ""; String sf = asPrefix ? "" : sep; for (String value : values) { sb.append(pf + value + sf);/*from w ww. j a va 2 s . c om*/ } if (!asPrefix) { // removes trailing sep by default int beg = sb.length() - 1 - sep.length(); sb.delete(beg, sb.length()); } return sb.toString(); }