List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:com.haulmont.cuba.gui.ComponentsHelper.java
public static String getComponentPath(Component c) { StringBuilder sb = new StringBuilder(c.getId() == null ? "" : c.getId()); if (c instanceof Component.BelongToFrame) { Frame frame = ((Component.BelongToFrame) c).getFrame(); while (frame != null) { sb.insert(0, "."); String s = frame.getId(); if (s.contains(".")) s = "[" + s + "]"; sb.insert(0, s);/* w w w .ja va2 s . co m*/ if (frame instanceof Window) break; frame = frame.getFrame(); } } return sb.toString(); }
From source file:com.kotcrab.vis.editor.util.ApplicationUtils.java
public static String getRestartCommand() { List<String> vmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); StringBuilder vmArgsOneLine = new StringBuilder(); if (OsUtils.isMac()) { vmArgsOneLine.append("-XstartOnFirstThread "); }//from w ww.j a v a 2 s.co m for (String arg : vmArguments) { if (arg.contains("-agentlib") == false) { vmArgsOneLine.append(arg).append(" "); } } final StringBuilder cmd = new StringBuilder(PlatformUtils.getJavaBinPath() + " " + vmArgsOneLine); String[] mainCommand = System.getProperty("sun.java.command").split(" "); if (mainCommand[0].endsWith(".jar")) cmd.append("-jar " + new File(mainCommand[0]).getPath()); else cmd.append("-cp \"" + System.getProperty("java.class.path") + "\" " + mainCommand[0]); for (int i = 1; i < mainCommand.length; i++) { cmd.append(" "); cmd.append(mainCommand[i]); } //if launching from idea, not in debug mode String ideaLauncher = "-Didea.launcher.bin.path="; int ideaLauncherStart = cmd.indexOf(ideaLauncher); if (ideaLauncherStart != -1) { cmd.insert(ideaLauncherStart + ideaLauncher.length(), "\""); cmd.insert(cmd.indexOf("-cp ", ideaLauncherStart) - 1, "\""); } return cmd.toString(); }
From source file:com.magic.util.StringUtil.java
public static String padNumberString(String numberString, int targetMinLength) { StringBuilder outStrBfr = new StringBuilder(numberString); while (targetMinLength > outStrBfr.length()) { outStrBfr.insert(0, '0'); }//from ww w . j ava 2 s . c o m return outStrBfr.toString(); }
From source file:com.igormaznitsa.mindmap.model.ModelUtils.java
@Nullable public static URI toURI(@Nullable final Path path) { if (path == null) { return null; }// w w w . j ava 2 s . co m try { final StringBuilder buffer = new StringBuilder(); final Path root = path.getRoot(); if (root != null) { buffer.append(root.toString().replace('\\', '/')); } for (final Path p : path) { if (buffer.length() > 0 && buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } buffer.append(encodeForURI(p.toFile().getName())); } if (path.isAbsolute()) { buffer.insert(0, "file://" + (root == null ? "/" : "")); //NOI18N } return new URI(buffer.toString()); } catch (Exception ex) { throw new IllegalArgumentException("Can't convert path to URI: " + path, ex); //NOI18N } }
From source file:com.magic.util.StringUtil.java
/** Make sure the string starts with a forward slash but does not end with one; converts back-slashes to forward-slashes; if in String is null or empty, returns zero length string. */ public static String cleanUpPathPrefix(String prefix) { if (prefix == null || prefix.length() == 0) return ""; StringBuilder cppBuff = new StringBuilder(prefix.replace('\\', '/')); if (cppBuff.charAt(0) != '/') { cppBuff.insert(0, '/'); }/* www. j av a 2 s . com*/ if (cppBuff.charAt(cppBuff.length() - 1) == '/') { cppBuff.deleteCharAt(cppBuff.length() - 1); } return cppBuff.toString(); }
From source file:Main.java
public static String encodeBase58(byte[] input) { if (input == null) { return null; }//from w w w . j a va 2 s.c om StringBuilder str = new StringBuilder((input.length * 350) / 256 + 1); BigInteger bn = new BigInteger(1, input); long rem; while (true) { BigInteger[] divideAndRemainder = bn.divideAndRemainder(BASE58_CHUNK_MOD); bn = divideAndRemainder[0]; rem = divideAndRemainder[1].longValue(); if (bn.compareTo(BigInteger.ZERO) == 0) { break; } for (int i = 0; i < BASE58_CHUNK_DIGITS; i++) { str.append(BASE58[(int) (rem % 58)]); rem /= 58; } } while (rem != 0) { str.append(BASE58[(int) (rem % 58)]); rem /= 58; } str.reverse(); int nLeadingZeros = 0; while (nLeadingZeros < input.length && input[nLeadingZeros] == 0) { str.insert(0, BASE58[0]); nLeadingZeros++; } return str.toString(); }
From source file:com.ctriposs.rest4j.internal.server.model.ResourceModelEncoder.java
private static void buildPathInternal(ResourceModel resourceModel, final StringBuilder sb, boolean addEntityElement) { do {/*from ww w . ja v a 2s. c o m*/ if (addEntityElement) { if (resourceModel.getKeys().size() >= 1) { sb.insert(0, "/{" + resourceModel.getKeyName() + "}"); } } sb.insert(0, "/" + resourceModel.getName()); addEntityElement = true; } while ((resourceModel = resourceModel.getParentResourceModel()) != null); }
From source file:fr.putnami.pwt.plugin.ajaxbot.filter.AjaxPageFilter.java
private static String rewriteQueryString(String queryString) throws UnsupportedEncodingException { StringBuilder queryStringSb = new StringBuilder(queryString); int i = queryStringSb.indexOf("&" + QUERY_PARAM_ESCAPED_FRAGMENT); if (i != -1) { StringBuilder tmpSb = new StringBuilder(queryStringSb.substring(0, i)); tmpSb.append("#!"); tmpSb.append(URLDecoder.decode(queryStringSb.substring(i + 20, queryStringSb.length()), "UTF-8")); queryStringSb = tmpSb;//from w w w .j ava 2 s.c o m } i = queryStringSb.indexOf(QUERY_PARAM_ESCAPED_FRAGMENT); if (i != -1) { StringBuilder tmpSb = new StringBuilder(queryStringSb.substring(0, i)); tmpSb.append("#!"); tmpSb.append(URLDecoder.decode(queryStringSb.substring(i + 19, queryStringSb.length()), "UTF-8")); queryStringSb = tmpSb; } if (queryStringSb.indexOf("#!") != 0) { queryStringSb.insert(0, '?'); } return queryStringSb.toString(); }
From source file:nl.softwaredesign.exporter.ODTExportFormat.java
/** * @param toConvert color to convert/*from ww w . j a v a2 s. co m*/ * @return the six character hex string (rrggbb) for the color */ private static String rgbHexValue(Color toConvert) { StringBuilder result = new StringBuilder(); result.append(Integer.toHexString(toConvert.getRed())); if (result.length() < 2) { result.insert(0, '0'); } result.append(Integer.toHexString(toConvert.getGreen())); if (result.length() < 4) { result.insert(2, '0'); } result.append(Integer.toHexString(toConvert.getBlue())); if (result.length() < 6) { result.insert(4, '0'); } return result.toString(); }
From source file:eu.dasish.annotation.backend.Helpers.java
public static StringBuilder replaceString(StringBuilder source, String oldFragment, Object newObject) { if (oldFragment != null) { int lengthOld = oldFragment.length(); String newFragment;/* www .java 2s.c om*/ if (newObject != null) { if (newObject instanceof Integer) { newFragment = ((Integer) newObject).toString(); } else { if (newObject instanceof String) { newFragment = (String) newObject; } else { newFragment = newObject.toString(); } } } else { newFragment = " "; } int lengthNew = newFragment.length(); int indexOf = source.indexOf(oldFragment); while (indexOf > 0) { source.delete(indexOf, indexOf + lengthOld); source.insert(indexOf, newFragment); indexOf = source.indexOf(oldFragment, indexOf + lengthNew); } } return source; }