List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:Main.java
/** * This method adds underscore in between the words (eg: converts GeneHomolog * to Gene_Homolog)// www .java 2 s . c om * * @param name */ public static void evaluateString(String name, List<String> options, List<String> words) { if (options == null || words == null) throw new IllegalArgumentException("Options or Words is not initialized"); //remove package name if the name is a class name if (name != null) { int index = name.lastIndexOf("."); name = name.substring(index + 1); } //Set optionSet = new HashSet(); options.add(name); char firstChar = name.charAt(0); firstChar = Character.toUpperCase(firstChar); if (name.indexOf("_") > 0) { String temp = Character.toString(firstChar) + name.substring(1); options.add(temp); } String temp = firstChar + name.substring(1).toLowerCase(); options.add(temp); String evaluatedString = null; ; StringBuffer wholeWords = new StringBuffer(); StringBuffer tempSeparateWord = new StringBuffer(); char[] chars = name.toCharArray(); StringBuffer sb = new StringBuffer(); boolean first = true; int index = 0; for (int i = 0; i < chars.length; i++) { //Character c = new Character(chars[i]); //System.out.println("inside loop i = " +i); if (Character.isUpperCase(chars[i])) { if ((i > 1) && ((i - index) > 1)) { //System.out.println("Inside capital if"); first = false; sb.append("_").append(chars[i]); words.add(tempSeparateWord.toString()); tempSeparateWord = new StringBuffer(); tempSeparateWord.append(chars[i]); wholeWords.append(" ").append(chars[i]); } else { wholeWords.append(chars[i]); tempSeparateWord.append(chars[i]); sb.append(chars[i]); } index = i; } else { if (chars[i] != '_') { sb.append(chars[i]); wholeWords.append(chars[i]); tempSeparateWord.append(chars[i]); } } } //System.out.println("Converted string: "+sb.toString()); //if the string contains "_", then make the first character uppercase if (!first) { char c = Character.toUpperCase(sb.charAt(0)); sb.deleteCharAt(0); sb.insert(0, c); char c1 = Character.toUpperCase(wholeWords.charAt(0)); wholeWords.deleteCharAt(0); wholeWords.insert(0, c1); } options.add(sb.toString()); options.add(wholeWords.toString()); if (words.size() > 0) { /* StringBuffer tmp = (StringBuffer)separateWords.get(0); char c2 = Character.toUpperCase(tmp.charAt(0)); tmp.deleteCharAt(0); tmp.insert(0, c2); separateWords.remove(0); separateWords.add(0, tmp); */ String temp2 = words.get(words.size() - 1).toString(); if (tempSeparateWord != null) { temp = tempSeparateWord.toString(); if (temp2.compareToIgnoreCase(temp) != 0) { words.add(temp); } } } List possibleOptions = new ArrayList(options); options = null;//garbage collection ready //testing for (int i = 0; i < possibleOptions.size(); i++) { System.out.println("options[" + i + "]=" + possibleOptions.get(i)); } for (int i = 0; i < words.size(); i++) { System.out.println("separateWords[" + i + "]=" + words.get(i)); } return; }
From source file:edu.umd.cs.submitServer.servlets.ReportTestOutcomes.java
/** * Compares two testOutcomeCollections that were run against the same * testSetupPK and produces a String suitable for entry in a log4j log * summarizing the differences between the two collections. Used by the * background retesting mechanism. TODO It's ugly that this returns a String! * //from w w w . j a v a 2s .c o m * @param oldCollection * The collection currently in the database. * @param newCollection * The collection returned after a background re-test. * @param submissionPK * The submissionPK of the submission being retested. * @param testSetupPK * The testSetupPK of the testSetup used for the re-test. * @return null if the two testOutcomeCollections are the same; a String * suitable for writing in a log if there are differences */ private static String compareCardinalOutcomes(TestOutcomeCollection oldCollection, TestOutcomeCollection newCollection, @Submission.PK Integer submissionPK, Integer testSetupPK, String testMachine) { for (TestOutcome newOutcome : newCollection) { // If any of the tests were marked "COULD_NOT_RUN" then don't record // anything // into the DB if (newOutcome.getOutcome().equals(TestOutcome.COULD_NOT_RUN)) { getFailedBackgroundRetestLog().warn(newOutcome.getOutcome() + " result for submissionPK " + submissionPK + ", testSetupPK " + testSetupPK + " and test " + newOutcome.getTestType() + newOutcome.getTestNumber() + " : " + newOutcome.getTestName()); return null; } } // TODO Handle when one compiles and the next doesn't compile. // NOTE: We're ignoring a lot of other info here like md5sums, clover // info, etc. StringBuffer buf = new StringBuffer(); for (TestOutcome oldOutcome : oldCollection.getIterableForCardinalTestTypes()) { TestOutcome newOutcome = newCollection.getTest(oldOutcome.getTestName()); if (oldOutcome.getOutcome().equals(TestOutcome.COULD_NOT_RUN)) { getFailedBackgroundRetestLog().warn("Not currently able to compare could not runs"); return "skip"; } if (newOutcome == null) { // We're in trouble here throw new IllegalStateException("Can't find " + oldOutcome.getTestName() + " in new testOutcomeCollection after background retest for " + " submissionPK " + submissionPK + " and testSetupPK " + testSetupPK); } if (!oldOutcome.getOutcome().equals(newOutcome.getOutcome())) { buf.append("\t" + oldOutcome.getTestName() + ": outcome in database is " + oldOutcome.getOutcome() + "; background retest produced " + newOutcome.getOutcome() + "\n"); } } if (buf.length() > 0) { buf.insert(0, "submissionPK = " + submissionPK + ", testSetupPK = " + testSetupPK + " on " + testMachine + ":\n"); // Strip off last newline buf.delete(buf.length() - 1, buf.length()); return buf.toString(); } return null; }
From source file:org.dspace.storage.rdbms.DatabaseManager.java
private static void offsetAndLimitOracleQuery(StringBuffer query, List<Serializable> params, int offset, int limit) { // prepare the LIMIT clause if (limit > 0 || offset > 0) { query.insert(0, "SELECT /*+ FIRST_ROWS(n) */ rec.*, ROWNUM rnum FROM ("); query.append(") "); }//from w w w .j a v a 2s. co m if (limit > 0) { query.append("rec WHERE rownum<=? "); if (offset > 0) { params.add(Integer.valueOf(limit + offset)); } else { params.add(Integer.valueOf(limit)); } } if (offset > 0) { query.insert(0, "SELECT * FROM ("); query.append(") WHERE rnum>?"); params.add(Integer.valueOf(offset)); } }
From source file:com.sbcc.edu.jrollspellchecker.MainWindow.java
public void changedReplace(IndexedWord word) { int startIndex = word.getStartIndex(); String tempWindowText = spellCheckText.getText(); StringBuffer buf = new StringBuffer(spellCheckText.getText()); buf.delete(word.getStartIndex(), word.getEndIndex()); buf.insert(word.getStartIndex(), curWord.getText()); System.out.println("Trying replace for " + word.data); spellCheckText.setText(buf.toString()); this.mainIndexedWords = new ArrayList<IndexedWord>(); indexTest(mainIndexedWords, startIndex); cycleNew(mainIndexedWords);/*from ww w . ja v a 2 s . com*/ }
From source file:com.ebay.jetstream.dynamicconfig.ConfigUploaderToMongo.java
private String appendBeanTags(String beanDefinition) { int index = beanDefinition.indexOf("<bean"); StringBuffer beanDef = new StringBuffer(beanDefinition); beanDef.insert(index, beans_beginning_tag); beanDef.append(beans_end_tag);//from www . j ava2s. c o m return beanDef.toString(); }
From source file:org.eclipse.skalli.view.internal.filter.ext.GitGerritFilter.java
/** * Generates a name based on the project hierarchy (short names) and the project ID using a delimiter and a possible suffix. *//*from w ww .j a v a 2 s . co m*/ String generateName(Project project, String delimiter, String suffix) { StringBuffer sb = new StringBuffer(); ProjectService projectService = ((ProjectService) EntityServices.getByEntityClass(Project.class)); for (Project parent : projectService.getParentChain(project.getUuid())) { if (parent.getProjectId() == project.getProjectId()) { sb.insert(0, parent.getProjectId()); } else { sb.insert(0, delimiter); sb.insert(0, parent.getOrConstructShortName()); } } sb.append(suffix); return sb.toString(); }
From source file:nl.nn.adapterframework.pipes.IteratingPipe.java
protected String sendMessage(Object input, IPipeLineSession session, String correlationID, ISender sender, Map threadContext) throws SenderException, TimeOutException { // sendResult has a messageID for async senders, the result for sync senders boolean keepGoing = true; IDataIterator it = null;/*from www . j av a 2 s .c o m*/ try { ItemCallback callback = new ItemCallback(session, correlationID, sender); it = getIterator(input, session, correlationID, threadContext); if (it == null) { iterateInput(input, session, correlationID, threadContext, callback); } else { String nextItemStored = null; while (keepGoing && (it.hasNext() || nextItemStored != null)) { if (Thread.currentThread().isInterrupted()) { throw new TimeOutException("Thread has been interrupted"); } StringBuffer items = new StringBuffer(); if (getBlockSize() > 0) { items.append(getBlockPrefix()); for (int i = 0; i < getBlockSize() && it.hasNext(); i++) { String item = (String) it.next(); items.append(getLinePrefix()); items.append(item); items.append(getLineSuffix()); } items.append(getBlockSuffix()); keepGoing = callback.handleItem(items.toString()); } else { if (getStartPosition() >= 0 && getEndPosition() > getStartPosition()) { items.append(getBlockPrefix()); String keyPreviousItem = null; boolean sameKey = true; while (sameKey && (it.hasNext() || nextItemStored != null)) { String item; if (nextItemStored == null) { item = (String) it.next(); } else { item = nextItemStored; nextItemStored = null; } String key; if (getEndPosition() >= item.length()) { key = item.substring(getStartPosition()); } else { key = item.substring(getStartPosition(), getEndPosition()); } if (keyPreviousItem == null || key.equals(keyPreviousItem)) { items.append(getLinePrefix()); items.append(item); items.append(getLineSuffix()); if (keyPreviousItem == null) { keyPreviousItem = key; } } else { sameKey = false; nextItemStored = item; } } items.append(getBlockSuffix()); keepGoing = callback.handleItem(items.toString()); } else { String item = getItem(it); items.append(getLinePrefix()); items.append(item); items.append(getLineSuffix()); keepGoing = callback.handleItem(item); } } } } String results = ""; if (isCollectResults()) { StringBuffer callbackResults = callback.getResults(); callbackResults.insert(0, "<results count=\"" + callback.getCount() + "\">\n"); callbackResults.append("</results>"); results = callbackResults.toString(); } else { results = "<results count=\"" + callback.getCount() + "\"/>"; } return results; } finally { if (it != null) { try { if (isCloseIteratorOnExit()) { it.close(); } } catch (Exception e) { log.warn("Exception closing iterator", e); } } } }
From source file:org.apache.ftpserver.usermanager.DbUserManager.java
/** * Escape string to be embedded in SQL statement. */// w ww. j av a 2 s . c o m private String escapeString(String input) { StringBuffer valBuf = new StringBuffer(input); for (int i = 0; i < valBuf.length(); i++) { char ch = valBuf.charAt(i); if (ch == '\'' || ch == '\\' || ch == '$' || ch == '^' || ch == '[' || ch == ']' || ch == '{' || ch == '}') { valBuf.insert(i, '\\'); i++; } } return valBuf.toString(); }
From source file:com.npower.dm.hibernate.entity.DDFNodeEntity.java
/** * caculate the nodePath./*from w w w. j av a 2s . co m*/ * If the node's name is null, will instead with "${NodeName}" defined by DDFNode.NAME_OF_DYNAMIC_NODE. * The path will start with "./" * @return */ public String getNodePath() { StringBuffer result = new StringBuffer(); String name = this.getName(); name = (name == null) ? DDFNode.NAME_OF_DYNAMIC_NODE : name; result.append(name); DDFNode parent = this.getParentDDFNode(); while (parent != null) { result.insert(0, "/"); name = parent.getName(); name = (name == null) ? DDFNode.NAME_OF_DYNAMIC_NODE : name; result.insert(0, name); parent = parent.getParentDDFNode(); } String path = result.toString(); if (!path.startsWith("./")) { return "./" + path; } else { return path; } }
From source file:com.granule.json.utils.internal.JSONObject.java
/** * Internal method to escape special attribute name characters, to handle things like name spaces. * @param str The string to escape the characters in. */// w w w . j a va 2 s .c om private String escapeStringSpecialCharacters(String str) { if (logger.isLoggable(Level.FINER)) logger.exiting(className, "escapeStringSpecialCharacters(String)"); if (str != null) { StringBuffer strBuf = new StringBuffer(""); for (int i = 0; i < str.length(); i++) { char strChar = str.charAt(i); switch (strChar) { case '"': { strBuf.append("\\\""); break; } case '\t': { strBuf.append("\\t"); break; } case '\b': { strBuf.append("\\b"); break; } case '\\': { strBuf.append("\\\\"); break; } case '\f': { strBuf.append("\\f"); break; } case '\r': { strBuf.append("\\r"); break; } case '/': { strBuf.append("\\/"); break; } default: { if ((strChar >= 32) && (strChar <= 126)) { strBuf.append(strChar); } else { strBuf.append("\\u"); StringBuffer sb = new StringBuffer(Integer.toHexString(strChar)); while (sb.length() < 4) { sb.insert(0, '0'); } strBuf.append(sb.toString()); } break; } } } str = strBuf.toString(); } if (logger.isLoggable(Level.FINER)) logger.exiting(className, "escapeStringSpecialCharacters(String)"); return str; }