List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:ch.iceage.icedms.persistence.jdbc.query.AbstractGenericQueries.java
protected final Object getColumns(String tableName, String tableAlias, JoinClause... clause) { StringBuilder sb = new StringBuilder(); for (String column : schema.getColumNames(tableName)) { sb.append(tableAlias).append(".").append(column).append(" ").append(tableAlias).append("_") .append(column).append(", "); }/* ww w . ja v a2s.com*/ if (clause != null) { for (JoinClause current : clause) { for (String column : schema.getColumNames(current.getTableTo())) { sb.append(current.getTableAliasTo()).append(".").append(column).append(" ") .append(current.getTableAliasTo()).append("_").append(column).append(", "); } } sb.deleteCharAt(sb.length() - 2); } return sb; }
From source file:org.apache.olingo.client.core.uri.URIBuilderImpl.java
protected String buildMultiKeySegment(final Map<String, Object> segmentValues, final boolean escape, final char sperator) { if (segmentValues == null || segmentValues.isEmpty()) { return StringUtils.EMPTY; } else {//from www.ja va 2 s . c o m final StringBuilder keyBuilder = new StringBuilder().append('('); for (Map.Entry<String, Object> entry : segmentValues.entrySet()) { keyBuilder.append(entry.getKey()).append('=') .append(escape ? URIUtils.escape(entry.getValue()) : entry.getValue()); keyBuilder.append(sperator); } keyBuilder.deleteCharAt(keyBuilder.length() - 1).append(')'); return keyBuilder.toString(); } }
From source file:com.g3net.tool.StringUtils.java
/** * Trim leading whitespace from the given String. * //from www .j a va 2 s . c om * @param str * the String to check * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimLeadingWhitespace(String str) { if (!hasLength(str)) { return str; } StringBuilder buf = new StringBuilder(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) { buf.deleteCharAt(0); } return buf.toString(); }
From source file:models.TopicModel.java
public void saveObjectGraph() throws Exception { Ebean.beginTransaction();//from w w w . jav a2 s. c om Configuration config = Play.application().configuration(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(malletTopicModel); oos.close(); model = baos.toByteArray(); baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(malletTopicModel.getInferencer()); oos.close(); inferencer = baos.toByteArray(); ArrayList<Topic> topicList = new ArrayList<Topic>(); // create topics Object[][] topicWords = malletTopicModel.getTopWords(config.getInt("smarts.topicModel.numTopWords")); for (int topicNum = 0; topicNum < this.numTopics; topicNum++) { StringBuilder wordList = new StringBuilder(); Object[] words = topicWords[topicNum]; for (Object w : words) { wordList.append(w); wordList.append(" "); } if (wordList.length() > 0) { // remove trailing space wordList.deleteCharAt(wordList.length() - 1); } Topic topic = new Topic(topicNum, wordList.toString()); topics.add(topic); topicList.add(topic); } // create documents PancakeTopicInferencer inferencer = malletTopicModel.getInferencer(); InstanceList docVectors = getDocumentVectors(); // Only record the n most significant topics List<List> orderedDistributions = inferencer.inferSortedDistributions(docVectors, config.getInt("smarts.inference.numIterations"), config.getInt("smarts.inference.thinning"), config.getInt("smarts.inference.burnInPeriod"), Double.parseDouble(config.getString("smarts.inference.threshold")), config.getInt("smarts.inference.numSignificantFeatures")); for (int docIndex = 0; docIndex < orderedDistributions.size(); docIndex++) { List docData = orderedDistributions.get(docIndex); String docName = (String) docData.get(0); double[] docTopWeights = generateTopTopicWeightVector(docIndex, orderedDistributions); Document doc = new Document(docName, docTopWeights); documents.add(doc); getDocuments().add(doc); } Ebean.save(this); Ebean.save(topics); // loop to save so the save hook is called for (Document doc : documents) { doc.save(); } Ebean.commitTransaction(); } finally { Ebean.endTransaction(); } }
From source file:com.g3net.tool.StringUtils.java
/** * Trim leading and trailing whitespace from the given String. * /*from w ww . j a va2 s.c o m*/ * @param str * the String to check * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimWhitespace(String str) { if (!hasLength(str)) { return str; } StringBuilder buf = new StringBuilder(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) { buf.deleteCharAt(0); } while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) { buf.deleteCharAt(buf.length() - 1); } return buf.toString(); }
From source file:com.g3net.tool.StringUtils.java
/** * str0?// ww w . j a v a 2 s . c o m * * @param str * @param defaultValue * @return */ public static String trimWhitespace(String str, String defaultValue) { if (!hasLength(str)) { return defaultValue; } StringBuilder buf = new StringBuilder(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) { buf.deleteCharAt(0); } while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) { buf.deleteCharAt(buf.length() - 1); } return buf.toString(); }
From source file:org.shredzone.commons.view.manager.ViewPattern.java
/** * Evaluates the given {@link EvaluationContext} and builds an URL to the appropriate * view.//from www. j a v a2 s . c o m * * @param context * {@link EvaluationContext} to be used * @param data * {@link PathContext} containing all data required for building the URL * @return URL that was built, or {@code null} if the {@link PathContext} did not * contain all necessary data for building the URL */ public String evaluate(EvaluationContext context, PathContext data) { StringBuilder sb = new StringBuilder(); for (Expression expr : expression) { String value = expr.getValue(context, data, String.class); if (value == null) { // A part resolved to null, so this ViewPattern is unable // to build a path from the given PathData. return null; } sb.append(value); } // Remove ugly double slashes int pos; while ((pos = sb.indexOf("//")) >= 0) { sb.deleteCharAt(pos); } return sb.toString(); }
From source file:com.appcelerator.titanium.desktop.ui.wizard.Packager.java
private String getQueryString(Map<String, String> data) throws UnsupportedEncodingException { StringBuilder builder = new StringBuilder(); for (Map.Entry<String, String> entry : data.entrySet()) { builder.append(URLEncoder.encode(entry.getKey(), ENCODING)).append('=') .append(URLEncoder.encode(entry.getValue(), ENCODING)).append('&'); }//from www . ja va 2 s . co m if (builder.length() > 0) { builder.deleteCharAt(builder.length() - 1); // chop off trailing '&' } return builder.toString(); }
From source file:com.haulmont.cuba.gui.ScreenHistorySupport.java
protected String makeLink(Window window) { Entity entity = null;/*from w w w . j av a 2s . co m*/ if (window.getFrame() instanceof Window.Editor) entity = ((Window.Editor) window.getFrame()).getItem(); String url = configuration.getConfig(GlobalConfig.class).getWebAppUrl() + "/open?" + "screen=" + window.getFrame().getId(); if (entity != null) { String item = metadata.getSession().getClassNN(entity.getClass()).getName() + "-" + entity.getId(); url += "&" + "item=" + item + "&" + "params=item:" + item; } Map<String, Object> params = getWindowParams(window); StringBuilder sb = new StringBuilder(); if (params != null) { for (Map.Entry<String, Object> param : params.entrySet()) { Object value = param.getValue(); if (value instanceof String /*|| value instanceof Integer || value instanceof Double*/ || value instanceof Boolean) { sb.append(",").append(param.getKey()).append(":") .append(URLEncodeUtils.encodeUtf8(value.toString())); } } } if (sb.length() > 0) { if (entity != null) { url += sb.toString(); } else { url += "¶ms=" + sb.deleteCharAt(0).toString(); } } return url; }
From source file:net.sf.jabref.bst.BibtexCaseChanger.java
/** * Convert the given string according to the format character (title, lower, * up) and append the result to the stringBuffer, return the updated * position.//w ww .j a va 2 s . c o m * * @param c * @param start * @param s * @param sb * @param format * @return the new position */ private int convertAccented(char[] c, int start, String s, StringBuilder sb, FORMAT_MODE format) { int pos = start; pos += s.length(); switch (format) { case TITLE_LOWERS: case ALL_LOWERS: if ("L O OE AE AA".contains(s)) { sb.append(s.toLowerCase()); } else { sb.append(s); } break; case ALL_UPPERS: if ("l o oe ae aa".contains(s)) { sb.append(s.toUpperCase()); } else if ("i j ss".contains(s)) { sb.deleteCharAt(sb.length() - 1); // Kill backslash sb.append(s.toUpperCase()); while ((pos < c.length) && Character.isWhitespace(c[pos])) { pos++; } } else { sb.append(s); } break; default: LOGGER.info("convertAccented - Unknown format: " + format); break; } return pos; }