List of usage examples for java.lang StringBuilder length
int length();
From source file:com.cloudera.data.filesystem.PartitionExpression.java
private static String toExpression(FieldPartitioner fieldPartitioner) { // TODO: add other strategies if (fieldPartitioner instanceof HashFieldPartitioner) { return String.format("hash(\"%s\", %s)", fieldPartitioner.getName(), fieldPartitioner.getCardinality()); } else if (fieldPartitioner instanceof IdentityFieldPartitioner) { return String.format("identity(\"%s\", %s)", fieldPartitioner.getName(), fieldPartitioner.getCardinality()); } else if (fieldPartitioner instanceof RangeFieldPartitioner) { List<Comparable<?>> upperBounds = ((RangeFieldPartitioner) fieldPartitioner).getUpperBounds(); StringBuilder builder = new StringBuilder(); for (Comparable<?> bound : upperBounds) { if (builder.length() > 0) { builder.append(", "); }/*from ww w .j a v a 2 s.co m*/ if (bound instanceof String) { builder.append("\"").append(bound).append("\""); } else { builder.append(bound); } } return String.format("range(\"%s\", %s", fieldPartitioner.getName(), builder.toString()); } throw new IllegalArgumentException("Unrecognized PartitionStrategy: " + fieldPartitioner); }
From source file:Main.java
public static String removeFromCollection(String collectionString, String content) { String[] elements = collectionString.split(SPLITER); StringBuilder builder = new StringBuilder(); for (String element : elements) { if (element.equals(content)) { continue; }//from www . j a v a 2 s.c om builder.append(element).append(","); } if (builder.length() > 0) { builder.deleteCharAt(builder.lastIndexOf(",")); } return builder.toString(); }
From source file:com.qwazr.utils.LinkUtils.java
public final static String urlHostPathWrapReduce(String url, int maxSize) { URL u;//ww w.j ava 2s .com try { u = new URL(url); } catch (MalformedURLException e) { return url; } String path = StringUtils.fastConcat(u.getHost(), '/', u.getPath()); String[] frags = StringUtils.split(path, '/'); if (frags.length < 2) return path; int startPos = 1; int endPos = frags.length - 2; StringBuilder sbStart = new StringBuilder(frags[0]); StringBuilder sbEnd = new StringBuilder(frags[frags.length - 1]); int length = sbStart.length() + sbEnd.length(); for (;;) { boolean bHandled = false; if (startPos != -1 && startPos < endPos) { if (frags[startPos].length() + length < maxSize) { sbStart.append('/'); sbStart.append(frags[startPos++]); bHandled = true; } } if (endPos != -1 && endPos > startPos) { if (frags[endPos].length() + length < maxSize) { sbEnd.insert(0, '/'); sbEnd.insert(0, frags[endPos--]); bHandled = true; } } if (!bHandled) break; } return StringUtils.fastConcat(sbStart, "//", sbEnd); }
From source file:com.weibo.api.motan.config.ConfigUtil.java
public static String extractProtocols(String export) { Map<String, Integer> protocols = parseExport(export); StringBuilder sb = new StringBuilder(16); for (String p : protocols.keySet()) { sb.append(p).append(MotanConstants.COMMA_SEPARATOR); }//from w w w.j a va 2s . c o m if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:Main.java
public static String getThrows(ExecutableElement d) { Collection<? extends TypeMirror> params = d.getThrownTypes(); if (params.size() == 0) return ""; StringBuilder sbuf = new StringBuilder(params.size() * 20); sbuf.append("throws "); for (TypeMirror param : params) { sbuf.append(param.toString());//from www.j a v a 2 s . c om sbuf.append(','); } sbuf.setLength(sbuf.length() - 1); return sbuf.toString(); }
From source file:Main.java
public static String convertStreamToString(InputStream is) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null;/*from w w w. j av a 2 s. co m*/ String NL = System.getProperty("line.separator"); while ((line = reader.readLine()) != null) { sb.append(line + NL); } sb.replace(sb.length() - 1, sb.length(), ""); is.close(); return sb.toString(); }
From source file:com.sm.store.cluster.Utils.java
public static String list2String(List<String> list) { StringBuilder sb = new StringBuilder(); for (String each : list) { if (sb.length() > 0) sb.append(" " + each); else/* www . j ava2 s .c om*/ sb.append(each); } return sb.toString(); }
From source file:hr.fer.spocc.export.DotExporter.java
private static void reduceTreePrefix(StringBuilder prefix) { int index = prefix.lastIndexOf("."); if (index != -1) prefix.delete(index, prefix.length()); }
From source file:com.nortal.petit.beanmapper.BeanMappingStringUtils.java
/** * Transforms the given camel case string into it's underscore * representation. Example: someString -> some_string. * /*from w w w . j ava2 s .c om*/ * @param camelCase * string in camel case. * @return string in underscore representation. */ public static String camelCaseToUnderscore(String camelCase) { if (StringUtils.isBlank(camelCase)) { return camelCase; } StringBuilder sb = new StringBuilder(); for (Character c : camelCase.toCharArray()) { if (Character.isUpperCase(c)) { c = Character.toLowerCase(c); if (sb.length() > 0) { sb.append("_"); } } sb.append(c); } return sb.toString(); }
From source file:com.vaadin.tools.ReportUsage.java
private static void appendUserAgentProperty(StringBuilder sb, String propName) { String propValue = System.getProperty(propName); if (propValue != null) { if (sb.length() > 0) { sb.append(';').append(' '); }/*from w w w. j a va2 s . c o m*/ sb.append(propName); sb.append('='); sb.append(propValue); } }