List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:com.iislab.junyeop_imaciislab.moneyball.Moneyball.SlidingTabsBasicFragment.java
private String moneyToString(int money) { StringBuilder sb = new StringBuilder(String.valueOf(money)); final int limit = 99999; if (money > limit) { sb = new StringBuilder("99,999+"); } else {// w w w.j a v a 2s . c om for (int index = sb.length() - 3; index > 0; index -= 3) { sb.insert(index, ","); } } return sb.toString(); }
From source file:com.spd.ukraine.lucenewebsearch1.web.IndexingController.java
private String highLightPhrase(String text, String phrase) { String lowerText = text.toLowerCase(); String lowerPhrase = phrase.toLowerCase(); StringBuilder newText = new StringBuilder(text); for (int i = lowerText.indexOf(lowerPhrase); i >= 0; i = lowerText.indexOf(lowerPhrase, i + HIGHLIGHT_OPEN.length() + phrase.length() + HIGHLIGHT_CLOSE.length() + 1)) { newText.insert(i, HIGHLIGHT_OPEN).insert(i + HIGHLIGHT_OPEN.length() + phrase.length(), HIGHLIGHT_CLOSE);/*from w w w . j ava 2 s. c o m*/ lowerText = newText.toString().toLowerCase(); } return newText.toString(); }
From source file:com.g3net.tool.StringUtils.java
/** * /*from www . jav a2 s . c o m*/ * @param src * ? * @param c * * @param num * c * @param ishead * true? * @return */ public static String fill(String src, char c, int num, boolean ishead) { StringBuilder sb = new StringBuilder(src); char[] cs = new char[num]; Arrays.fill(cs, c); if (ishead) sb.insert(0, cs); else { sb.append(cs); } return sb.toString(); }
From source file:org.osiam.addons.self_administration.controller.AccountManagementService.java
/** * Logs the given exception and returns a suitable response status. * /* ww w . j a va2 s.com*/ * @param e * the exception to handle * @param {@link ResponseEntity} with the resulting error information and status code */ public ResponseEntity<String> handleException(RuntimeException e) { StringBuilder messageBuilder = new StringBuilder(); HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; if (e instanceof MailException) { messageBuilder.append("Failed to send email: "); } else if (e instanceof UnauthorizedException) { messageBuilder.append("Authorization failed: "); status = HttpStatus.UNAUTHORIZED; } else if (e instanceof NoResultException) { messageBuilder.append("No such entity: "); status = HttpStatus.NOT_FOUND; } else { messageBuilder.append("An exception occurred: "); } LOGGER.error(messageBuilder.toString()); messageBuilder.insert(0, "{\"error\":\""); messageBuilder.append(e.getMessage()); messageBuilder.append("\"}"); return new ResponseEntity<String>(messageBuilder.toString(), status); }
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
private void cycle(JTextComponent comp, int increment) { assert (lastCompletions != null); assert (!lastCompletions.isEmpty()); lastShownCompletion += increment;// w w w . j av a2 s. c om if (lastShownCompletion >= lastCompletions.size()) { lastShownCompletion = 0; } else if (lastShownCompletion < 0) { lastShownCompletion = lastCompletions.size() - 1; } String sno = lastCompletions.get(lastShownCompletion); toSetIn = sno.substring(lastBeginning.length() - 1); StringBuilder alltext = new StringBuilder(comp.getText()); int oldSelectionStart = comp.getSelectionStart(); int oldSelectionEnd = comp.getSelectionEnd(); // replace prefix with new prefix int startPos = comp.getSelectionStart() - lastBeginning.length(); alltext.delete(startPos, oldSelectionStart); alltext.insert(startPos, sno.subSequence(0, lastBeginning.length())); // replace suffix with new suffix alltext.delete(oldSelectionStart, oldSelectionEnd); //int cp = oldSelectionEnd - deletedChars; alltext.insert(oldSelectionStart, toSetIn.substring(1)); LOGGER.debug(alltext.toString()); comp.setText(alltext.toString()); //comp.setCaretPosition(cp+toSetIn.length()-1); comp.select(oldSelectionStart, (oldSelectionStart + toSetIn.length()) - 1); lastCaretPosition = comp.getCaretPosition(); LOGGER.debug("ToSetIn: '" + toSetIn + "'"); }
From source file:com.redhat.rhn.frontend.taglibs.list.SelectableColumnTag.java
private String getChildIds(Object parent) { if (RhnListTagFunctions.isExpandable(parent)) { StringBuilder buf = new StringBuilder(); for (Object child : ((Expandable) parent).expand()) { if (buf.length() > 0) { buf.append(","); }//from w w w. jav a 2 s. c om buf.append("'"); buf.append(makeCheckboxId(listName, ListTagHelper.getObjectId(child))); buf.append("'"); } buf.insert(0, "["); buf.append("]"); return buf.toString(); } return "[]"; }
From source file:net.sf.jabref.gui.AutoCompleteListener.java
private void cycle(JTextComponent comp, int increment) { assert (lastCompletions != null); assert (lastCompletions.length > 0); lastShownCompletion += increment;// w ww. ja va2 s. co m if (lastShownCompletion >= lastCompletions.length) { lastShownCompletion = 0; } else if (lastShownCompletion < 0) { lastShownCompletion = lastCompletions.length - 1; } String sno = lastCompletions[lastShownCompletion]; toSetIn = sno.substring(lastBeginning.length() - 1); StringBuilder alltext = new StringBuilder(comp.getText()); int oldSelectionStart = comp.getSelectionStart(); int oldSelectionEnd = comp.getSelectionEnd(); // replace prefix with new prefix int startPos = comp.getSelectionStart() - lastBeginning.length(); alltext.delete(startPos, oldSelectionStart); alltext.insert(startPos, sno.subSequence(0, lastBeginning.length())); // replace suffix with new suffix alltext.delete(oldSelectionStart, oldSelectionEnd); //int cp = oldSelectionEnd - deletedChars; alltext.insert(oldSelectionStart, toSetIn.substring(1)); //Util.pr(alltext.toString()); comp.setText(alltext.toString()); //comp.setCaretPosition(cp+toSetIn.length()-1); comp.select(oldSelectionStart, (oldSelectionStart + toSetIn.length()) - 1); lastCaretPosition = comp.getCaretPosition(); //System.out.println("ToSetIn: '"+toSetIn+"'"); }
From source file:de.xaniox.heavyspleef.core.flag.FlagRegistry.java
public void registerFlag(Class<? extends AbstractFlag<?>> clazz, I18NSupplier i18nSupplier, Object cookie) { Validate.notNull(clazz, "clazz cannot be null"); Validate.isTrue(!isFlagPresent(clazz), "Cannot register flag twice: " + clazz.getName()); if (i18nSupplier == null) { i18nSupplier = GLOBAL_SUPPLIER;// w ww .j a va 2 s . co m } /* Check if the class provides the required Flag annotation */ Validate.isTrue(clazz.isAnnotationPresent(Flag.class), "Flag-Class must be annotated with the @Flag annotation"); Flag flagAnnotation = clazz.getAnnotation(Flag.class); String name = flagAnnotation.name(); Validate.isTrue(!name.isEmpty(), "name() of annotation of flag for class " + clazz.getCanonicalName() + " cannot be empty"); /* Generate a path */ StringBuilder pathBuilder = new StringBuilder(); Flag parentFlagData = flagAnnotation; do { pathBuilder.insert(0, parentFlagData.name()); Class<? extends AbstractFlag<?>> parentFlagClass = parentFlagData.parent(); parentFlagData = parentFlagClass.getAnnotation(Flag.class); if (parentFlagData != null && parentFlagClass != NullFlag.class) { pathBuilder.insert(0, FLAG_PATH_SEPERATOR); } } while (parentFlagData != null); String path = pathBuilder.toString(); /* Check for name collides */ for (String flagPath : registeredFlagsMap.primaryKeySet()) { if (flagPath.equalsIgnoreCase(path)) { throw new IllegalArgumentException("Flag " + clazz.getName() + " collides with " + registeredFlagsMap.get(flagPath).flagClass.getName()); } } /* Check if the class can be instantiated */ try { Constructor<? extends AbstractFlag<?>> constructor = clazz.getDeclaredConstructor(); //Make the constructor accessible for future uses constructor.setAccessible(true); } catch (NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException("Flag-Class must provide an empty constructor"); } FlagClassHolder holder = new FlagClassHolder(); holder.flagClass = clazz; holder.supplier = i18nSupplier; holder.cookie = cookie; Field[] instanceInjectableFields = null; if (checkHooks(flagAnnotation)) { inject(holder, null, null); instanceInjectableFields = getInjectableDeclaredFieldsByFilter(clazz, new FieldFilter(FieldFilter.INSTANCE_MODE)); if (initializationPolicy == InitializationPolicy.COMMIT) { Method[] initMethods = getInitMethods(holder); for (Method method : initMethods) { queuedInitMethods.offer(method); } } else if (initializationPolicy == InitializationPolicy.REGISTER) { runInitMethods(holder); } if (flagAnnotation.hasCommands()) { CommandManager manager = heavySpleef.getCommandManager(); manager.registerSpleefCommands(clazz); } holder.staticFieldsInjected = true; holder.staticMethodsInitialized = true; } holder.injectingFields = instanceInjectableFields; registeredFlagsMap.put(path, flagAnnotation, holder); if (heavySpleef.isGamesLoaded()) { for (Game game : heavySpleef.getGameManager().getGames()) { for (AbstractFlag<?> flag : game.getFlagManager().getFlags()) { if (!(flag instanceof UnloadedFlag)) { continue; } UnloadedFlag unloaded = (UnloadedFlag) flag; if (!unloaded.getFlagName().equals(path)) { continue; } game.removeFlag(path); AbstractFlag<?> newFlag = newFlagInstance(path, AbstractFlag.class, game); newFlag.unmarshal(unloaded.getXmlElement()); game.addFlag(newFlag); } } } }