List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.microsoft.tfs.client.common.ui.vcexplorer.findinsce.actions.CopyToClipboardAction.java
private String getSelectedList() { final StringBuffer sb = new StringBuffer(); for (final TypedServerItem selectedItem : editor.getSelectedServerItems()) { if (sb.length() > 0) { sb.append(NewlineUtils.PLATFORM_NEWLINE); }//from www. j a va 2 s. co m sb.append(selectedItem.getServerPath()); } return sb.toString(); }
From source file:com.panet.imeta.core.row.ValueDataUtil.java
/** * Right pad a StringBuffer: adds spaces to a string until a certain length. * If the length is smaller then the limit specified, the String is truncated. * @param ret The StringBuffer to pad/* w ww. j ava 2 s .co m*/ * @param limit The desired length of the padded string. * @return The padded String. */ public static final String rightPad(StringBuffer ret, int limit) { int len = ret.length(); int l; if (len > limit) { ret.setLength(limit); } else { for (l = len; l < limit; l++) ret.append(' '); } return ret.toString(); }
From source file:cn.remex.core.util.StringUtils.java
/** * /*from www. j a v a 2 s . c o m*/ * Trim <i>all</i> whitespace from the given String: * leading, trailing, and inbetween characters. * @param str the String to check ?? * @return the trimmed String ?? * @see java.lang.Character#isWhitespace */ public static String trimAllWhitespace(final String str) { if (!hasLength(str)) { return str; } StringBuffer buf = new StringBuffer(str); int index = 0; while (buf.length() > index) { if (Character.isWhitespace(buf.charAt(index))) { buf.deleteCharAt(index); } else { index++; } } return buf.toString(); }
From source file:de.tudarmstadt.ukp.dkpro.tc.weka.util.WekaUtils.java
/** * Generates an instances object containing the predictions of a given single-label classifier * for a given test set/* w w w.java2 s.c o m*/ * * @param testData * test set * @param cl * single-label classifier, needs to be trained beforehand, needs to be compatible * with the test set trained classifier * @return instances object with additional attribute storing the predictions * @throws Exception */ public static Instances getPredictionInstancesSingleLabel(Instances testData, Classifier cl) throws Exception { StringBuffer classVals = new StringBuffer(); for (int i = 0; i < testData.classAttribute().numValues(); i++) { if (classVals.length() > 0) { classVals.append(","); } classVals.append(testData.classAttribute().value(i)); } // get predictions List<Double> labelPredictionList = new ArrayList<Double>(); for (int i = 0; i < testData.size(); i++) { labelPredictionList.add(cl.classifyInstance(testData.instance(i))); } // add an attribute with the predicted values at the end off the attributes Add filter = new Add(); filter.setAttributeName(WekaTestTask.PREDICTION_CLASS_LABEL_NAME); if (classVals.length() > 0) { filter.setAttributeType(new SelectedTag(Attribute.NOMINAL, Add.TAGS_TYPE)); filter.setNominalLabels(classVals.toString()); } filter.setInputFormat(testData); testData = Filter.useFilter(testData, filter); // fill predicted values for each instance for (int i = 0; i < labelPredictionList.size(); i++) { testData.instance(i).setValue(testData.classIndex() + 1, labelPredictionList.get(i)); } return testData; }
From source file:de.unidue.inf.is.ezdl.dlbackend.misc.TemplateParser.java
public void insertLoop(StringBuffer stringbuffer) { work = work.insert(looppos, stringbuffer.toString()); looppos += stringbuffer.length(); }
From source file:co.id.app.sys.util.StringUtils.java
/** * To left pad the string with the format until it achieve the maximum length that specified * @param string//from w w w. j a v a 2 s .com * @param format * @param len * @return */ public static String lpad(String string, String format, int len) { StringBuffer buffer = new StringBuffer(string); while (buffer.length() < len) { buffer.insert(0, format); } return buffer.toString(); }
From source file:edu.uci.ics.asterix.event.service.AsterixEventServiceUtil.java
public static String getNodeDirectories(String asterixInstanceName, Node node, Cluster cluster) { String storeDataSubDir = asterixInstanceName + File.separator + "data" + File.separator; String[] storeDirs = null;/*from w w w .j a va 2 s. co m*/ StringBuffer nodeDataStore = new StringBuffer(); String storeDirValue = node.getStore(); if (storeDirValue == null) { storeDirValue = cluster.getStore(); if (storeDirValue == null) { throw new IllegalStateException(" Store not defined for node " + node.getId()); } storeDataSubDir = node.getId() + File.separator + storeDataSubDir; } storeDirs = storeDirValue.split(","); for (String ns : storeDirs) { nodeDataStore.append(ns + File.separator + storeDataSubDir.trim()); nodeDataStore.append(","); } nodeDataStore.deleteCharAt(nodeDataStore.length() - 1); return nodeDataStore.toString(); }
From source file:com.glaf.core.util.RequestUtils.java
private static StringBuffer append(Object key, Object value, StringBuffer queryString, String ampersand) { if (queryString.length() > 0) { queryString.append(ampersand);/* w w w .ja v a2 s .c o m*/ } try { queryString.append(URLEncoder.encode(key.toString(), "UTF-8")); queryString.append('='); queryString.append(URLEncoder.encode(value.toString(), "UTF-8")); } catch (UnsupportedEncodingException e) { } return queryString; }
From source file:org.dspace.submit.lookup.PubmedOnlineDataLoader.java
@Override public List<Record> getByIdentifier(Context context, Map<String, Set<String>> keys) throws HttpException, IOException { Set<String> pmids = keys != null ? keys.get(PUBMED) : null; Set<String> dois = keys != null ? keys.get(DOI) : null; List<Record> results = new ArrayList<Record>(); if (pmids != null && pmids.size() > 0 && (dois == null || dois.size() == 0)) { for (String pmid : pmids) { Record p = null;/* w w w . java 2s.c o m*/ try { p = pubmedService.getByPubmedID(pmid); } catch (Exception e) { log.error(LogManager.getHeader(context, "getByIdentifier", "pmid=" + pmid), e); } if (p != null) results.add(convertFields(p)); } } else if (dois != null && dois.size() > 0 && (pmids == null || pmids.size() == 0)) { StringBuffer query = new StringBuffer(); for (String d : dois) { if (query.length() > 0) { query.append(" OR "); } query.append(d).append("[AI]"); } List<Record> pubmedResults = pubmedService.search(query.toString()); for (Record p : pubmedResults) { results.add(convertFields(p)); } } else if (dois != null && dois.size() > 0 && pmids != null && pmids.size() > 0) { // EKT:ToDo: support list of dois and pmids in the search method of // pubmedService List<Record> pubmedResults = pubmedService.search(dois.iterator().next(), pmids.iterator().next()); if (pubmedResults != null) { for (Record p : pubmedResults) { results.add(convertFields(p)); } } } return results; }
From source file:com.panet.imeta.core.row.ValueDataUtil.java
/** * Replace value occurances in a String with another value. * @param string The original String./*from www . j a v a 2 s . c om*/ * @param repl The text to replace * @param with The new text bit * @return The resulting string with the text pieces replaced. */ public static final String replace(String string, String repl, String with) { StringBuffer str = new StringBuffer(string); for (int i = str.length() - 1; i >= 0; i--) { if (str.substring(i).startsWith(repl)) { str.delete(i, i + repl.length()); str.insert(i, with); } } return str.toString(); }