Java Code Examples for org.apache.commons.lang.text.StrBuilder#toString()
The following examples show how to use
org.apache.commons.lang.text.StrBuilder#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassUtils.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Converts a class name to a JLS style class name. * * @param className the class name * @return the converted name */ private static String toCanonicalName(String className) { className = StringUtils.deleteWhitespace(className); if (className == null) { throw new NullArgumentException("className"); } else if (className.endsWith("[]")) { StrBuilder classNameBuffer = new StrBuilder(); while (className.endsWith("[]")) { className = className.substring(0, className.length() - 2); classNameBuffer.append("["); } String abbreviation = (String) abbreviationMap.get(className); if (abbreviation != null) { classNameBuffer.append(abbreviation); } else { classNameBuffer.append("L").append(className).append(";"); } className = classNameBuffer.toString(); } return className; }
Example 2
Source File: NumberRange.java From lams with GNU General Public License v2.0 | 6 votes |
/** * <p>Returns the string representation of this range.</p> * * <p>This string is the string representation of the minimum and * maximum numbers in the range, separated by a hyphen. If a number * is negative, then it is enclosed in parentheses.</p> * * @return the string representation of this range */ public String toString() { StrBuilder sb = new StrBuilder(); if (min.doubleValue() < 0) { sb.append('(') .append(min) .append(')'); } else { sb.append(min); } sb.append('-'); if (max.doubleValue() < 0) { sb.append('(') .append(max) .append(')'); } else { sb.append(max); } return sb.toString(); }
Example 3
Source File: CharSetUtils.java From lams with GNU General Public License v2.0 | 6 votes |
/** * <p>Squeezes any repetitions of a character that is mentioned in the * supplied set.</p> * * <p>An example is:</p> * <ul> * <li>squeeze("hello", {"el"}) => "helo"</li> * </ul> * * @see CharSet#getInstance(java.lang.String) for set-syntax. * @param str the string to squeeze, may be null * @param set the character set to use for manipulation, may be null * @return modified String, <code>null</code> if null string input */ public static String squeeze(String str, String[] set) { if (StringUtils.isEmpty(str) || ArrayUtils.isEmpty(set)) { return str; } CharSet chars = CharSet.getInstance(set); StrBuilder buffer = new StrBuilder(str.length()); char[] chrs = str.toCharArray(); int sz = chrs.length; char lastChar = ' '; char ch = ' '; for (int i = 0; i < sz; i++) { ch = chrs[i]; if (chars.contains(ch)) { if ((ch == lastChar) && (i != 0)) { continue; } } buffer.append(ch); lastChar = ch; } return buffer.toString(); }
Example 4
Source File: PushDownUtil.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
static String schemaCompletion(String inputSql, String schema) throws SqlParseException { if (inputSql == null || inputSql.equals("")) { return ""; } SqlNode node = CalciteParser.parse(inputSql); // get all table node that don't have schema by visitor pattern PushDownUtil.FromTablesVisitor ftv = new PushDownUtil.FromTablesVisitor(); node.accept(ftv); List<SqlNode> tablesWithoutSchema = ftv.getTablesWithoutSchema(); // sql do not need completion if (tablesWithoutSchema.isEmpty()) { return inputSql; } List<Pair<Integer, Integer>> tablesPos = new ArrayList<>(); for (SqlNode tables : tablesWithoutSchema) { tablesPos.add(CalciteParser.getReplacePos(tables, inputSql)); } // make the behind position in the front of the list, so that the front position // will not be affected when replaced Collections.sort(tablesPos, new Comparator<Pair<Integer, Integer>>() { @Override public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) { int r = o2.getFirst() - o1.getFirst(); return r == 0 ? o2.getSecond() - o1.getSecond() : r; } }); StrBuilder afterConvert = new StrBuilder(inputSql); for (Pair<Integer, Integer> pos : tablesPos) { String tableWithSchema = schema + "." + inputSql.substring(pos.getFirst(), pos.getSecond()); afterConvert.replace(pos.getFirst(), pos.getSecond(), tableWithSchema); } return afterConvert.toString(); }
Example 5
Source File: AgencyStagingDataMaintainable.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
protected String getMessageAsString(List<ErrorMessage> errorMessages){ List<String> messageList = new ArrayList<String>(); for (ErrorMessage error : errorMessages){ messageList.add(MessageUtils.getErrorMessage(error)); } StrBuilder builder = new StrBuilder(); builder.appendWithSeparators(messageList, BusinessObjectReportHelper.LINE_BREAK); return builder.toString(); }
Example 6
Source File: DataReportServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * @see org.kuali.kfs.module.tem.batch.service.DataReportService#getMessageAsString(java.util.List) */ @Override public String getMessageAsString(List<ErrorMessage> errorMessages){ List<String> messageList = new ArrayList<String>(); for (ErrorMessage error : errorMessages){ messageList.add(MessageUtils.getErrorMessage(error)); } StrBuilder builder = new StrBuilder(); builder.appendWithSeparators(messageList, BusinessObjectReportHelper.LINE_BREAK); return builder.toString(); }
Example 7
Source File: Const.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private static String removeEnclosure( String stringToSplit, String enclosure ) { int firstIndex = stringToSplit.indexOf( enclosure ); int lastIndex = stringToSplit.lastIndexOf( enclosure ); if ( firstIndex == lastIndex ) { return stringToSplit; } StrBuilder strBuilder = new StrBuilder( stringToSplit ); strBuilder.replace( firstIndex, enclosure.length() + firstIndex, "" ); strBuilder.replace( lastIndex - enclosure.length(), lastIndex, "" ); return strBuilder.toString(); }
Example 8
Source File: MessageEventProcessor.java From mxisd with GNU Affero General Public License v3.0 | 5 votes |
public String getHelp() { StrBuilder builder = new StrBuilder(); builder.appendln("Available commands:"); for (String cmd : processors.keySet()) { builder.append("\t").appendln(cmd); } return builder.toString(); }
Example 9
Source File: ClassUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <p>Converts a given name of class into canonical format. * If name of class is not a name of array class it returns * unchanged name.</p> * <p>Example: * <ul> * <li><code>getCanonicalName("[I") = "int[]"</code></li> * <li><code>getCanonicalName("[Ljava.lang.String;") = "java.lang.String[]"</code></li> * <li><code>getCanonicalName("java.lang.String") = "java.lang.String"</code></li> * </ul> * </p> * * @param className the name of class * @return canonical form of class name * @since 2.4 */ private static String getCanonicalName(String className) { className = StringUtils.deleteWhitespace(className); if (className == null) { return null; } else { int dim = 0; while (className.startsWith("[")) { dim++; className = className.substring(1); } if (dim < 1) { return className; } else { if (className.startsWith("L")) { className = className.substring( 1, className.endsWith(";") ? className.length() - 1 : className.length()); } else { if (className.length() > 0) { className = (String) reverseAbbreviationMap.get( className.substring(0, 1)); } } StrBuilder canonicalClassNameBuffer = new StrBuilder(className); for (int i = 0; i < dim; i++) { canonicalClassNameBuffer.append("[]"); } return canonicalClassNameBuffer.toString(); } } }
Example 10
Source File: FixObjectCompareResult.java From celos with Apache License 2.0 | 5 votes |
public String generateDescription() throws IOException { StrBuilder strBuilder = new StrBuilder(); PathToMessageProcessor pathToMessage = new PathToMessageProcessor(); TreeObjectProcessor.process(this, pathToMessage); for (Map.Entry<Path, String> pathMessage : pathToMessage.messages.entrySet()) { String keyText = StringUtils.isEmpty(pathMessage.getKey().toString()) ? "" : pathMessage.getKey() + " : " ; strBuilder.appendln(keyText + pathMessage.getValue()); } return strBuilder.toString(); }
Example 11
Source File: CharSetUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Implementation of delete and keep * * @param str String to modify characters within * @param set String[] set of characters to modify * @param expect whether to evaluate on match, or non-match * @return modified String */ private static String modify(String str, String[] set, boolean expect) { CharSet chars = CharSet.getInstance(set); StrBuilder buffer = new StrBuilder(str.length()); char[] chrs = str.toCharArray(); int sz = chrs.length; for(int i=0; i<sz; i++) { if(chars.contains(chrs[i]) == expect) { buffer.append(chrs[i]); } } return buffer.toString(); }
Example 12
Source File: DoubleRange.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <p>Gets the range as a <code>String</code>.</p> * * <p>The format of the String is 'Range[<i>min</i>,<i>max</i>]'.</p> * * @return the <code>String</code> representation of this range */ public String toString() { if (toString == null) { StrBuilder buf = new StrBuilder(32); buf.append("Range["); buf.append(min); buf.append(','); buf.append(max); buf.append(']'); toString = buf.toString(); } return toString; }
Example 13
Source File: LongRange.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <p>Gets the range as a <code>String</code>.</p> * * <p>The format of the String is 'Range[<i>min</i>,<i>max</i>]'.</p> * * @return the <code>String</code> representation of this range */ public String toString() { if (toString == null) { StrBuilder buf = new StrBuilder(32); buf.append("Range["); buf.append(min); buf.append(','); buf.append(max); buf.append(']'); toString = buf.toString(); } return toString; }
Example 14
Source File: NumberRange.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <p>Gets the range as a <code>String</code>.</p> * * <p>The format of the String is 'Range[<i>min</i>,<i>max</i>]'.</p> * * @return the <code>String</code> representation of this range */ public String toString() { if (toString == null) { StrBuilder buf = new StrBuilder(32); buf.append("Range["); buf.append(min); buf.append(','); buf.append(max); buf.append(']'); toString = buf.toString(); } return toString; }
Example 15
Source File: IntRange.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <p>Gets the range as a <code>String</code>.</p> * * <p>The format of the String is 'Range[<i>min</i>,<i>max</i>]'.</p> * * @return the <code>String</code> representation of this range */ public String toString() { if (toString == null) { StrBuilder buf = new StrBuilder(32); buf.append("Range["); buf.append(min); buf.append(','); buf.append(max); buf.append(']'); toString = buf.toString(); } return toString; }
Example 16
Source File: Const.java From hop with Apache License 2.0 | 5 votes |
private static String removeEnclosure( String stringToSplit, String enclosure ) { int firstIndex = stringToSplit.indexOf( enclosure ); int lastIndex = stringToSplit.lastIndexOf( enclosure ); if ( firstIndex == lastIndex ) { return stringToSplit; } StrBuilder strBuilder = new StrBuilder( stringToSplit ); strBuilder.replace( firstIndex, enclosure.length() + firstIndex, "" ); strBuilder.replace( lastIndex - enclosure.length(), lastIndex, "" ); return strBuilder.toString(); }
Example 17
Source File: CharSetUtils.java From lams with GNU General Public License v2.0 | 4 votes |
/** * <p>Translate characters in a String. * This is a multi character search and replace routine.</p> * * <p>An example is:</p> * <ul> * <li>translate("hello", "ho", "jy") * => jelly</li> * </ul> * * <p>If the length of characters to search for is greater than the * length of characters to replace, then the last character is * used.</p> * * <pre> * CharSetUtils.translate(null, *, *) = null * CharSetUtils.translate("", *, *) = "" * </pre> * * @param str String to replace characters in, may be null * @param searchChars a set of characters to search for, must not be null * @param replaceChars a set of characters to replace, must not be null or empty ("") * @return translated String, <code>null</code> if null string input * @throws NullPointerException if <code>searchChars</code> or <code>replaceChars</code> * is <code>null</code> * @throws ArrayIndexOutOfBoundsException if <code>replaceChars</code> is empty ("") * @deprecated Use {@link StringUtils#replaceChars(String, String, String)}. * Method will be removed in Commons Lang 3.0. * NOTE: StringUtils#replaceChars behaves differently when 'searchChars' is longer * than 'replaceChars'. CharSetUtils#translate will use the last char of the replacement * string whereas StringUtils#replaceChars will delete */ public static String translate(String str, String searchChars, String replaceChars) { if (StringUtils.isEmpty(str)) { return str; } StrBuilder buffer = new StrBuilder(str.length()); char[] chrs = str.toCharArray(); char[] withChrs = replaceChars.toCharArray(); int sz = chrs.length; int withMax = replaceChars.length() - 1; for(int i=0; i<sz; i++) { int idx = searchChars.indexOf(chrs[i]); if(idx != -1) { if(idx > withMax) { idx = withMax; } buffer.append(withChrs[idx]); } else { buffer.append(chrs[i]); } } return buffer.toString(); }
Example 18
Source File: DurationFormatUtils.java From lams with GNU General Public License v2.0 | 4 votes |
/** * <p>The internal method to do the formatting.</p> * * @param tokens the tokens * @param years the number of years * @param months the number of months * @param days the number of days * @param hours the number of hours * @param minutes the number of minutes * @param seconds the number of seconds * @param milliseconds the number of millis * @param padWithZeros whether to pad * @return the formatted string */ static String format(Token[] tokens, int years, int months, int days, int hours, int minutes, int seconds, int milliseconds, boolean padWithZeros) { StrBuilder buffer = new StrBuilder(); boolean lastOutputSeconds = false; int sz = tokens.length; for (int i = 0; i < sz; i++) { Token token = tokens[i]; Object value = token.getValue(); int count = token.getCount(); if (value instanceof StringBuffer) { buffer.append(value.toString()); } else { if (value == y) { buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(years), count, '0') : Integer .toString(years)); lastOutputSeconds = false; } else if (value == M) { buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(months), count, '0') : Integer .toString(months)); lastOutputSeconds = false; } else if (value == d) { buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(days), count, '0') : Integer .toString(days)); lastOutputSeconds = false; } else if (value == H) { buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(hours), count, '0') : Integer .toString(hours)); lastOutputSeconds = false; } else if (value == m) { buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(minutes), count, '0') : Integer .toString(minutes)); lastOutputSeconds = false; } else if (value == s) { buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(seconds), count, '0') : Integer .toString(seconds)); lastOutputSeconds = true; } else if (value == S) { if (lastOutputSeconds) { milliseconds += 1000; String str = padWithZeros ? StringUtils.leftPad(Integer.toString(milliseconds), count, '0') : Integer.toString(milliseconds); buffer.append(str.substring(1)); } else { buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(milliseconds), count, '0') : Integer.toString(milliseconds)); } lastOutputSeconds = false; } } } return buffer.toString(); }
Example 19
Source File: FastDateFormat.java From lams with GNU General Public License v2.0 | 4 votes |
/** * <p>Performs the parsing of tokens.</p> * * @param pattern the pattern * @param indexRef index references * @return parsed token */ protected String parseToken(String pattern, int[] indexRef) { StrBuilder buf = new StrBuilder(); int i = indexRef[0]; int length = pattern.length(); char c = pattern.charAt(i); if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') { // Scan a run of the same character, which indicates a time // pattern. buf.append(c); while (i + 1 < length) { char peek = pattern.charAt(i + 1); if (peek == c) { buf.append(c); i++; } else { break; } } } else { // This will identify token as text. buf.append('\''); boolean inLiteral = false; for (; i < length; i++) { c = pattern.charAt(i); if (c == '\'') { if (i + 1 < length && pattern.charAt(i + 1) == '\'') { // '' is treated as escaped ' i++; buf.append(c); } else { inLiteral = !inLiteral; } } else if (!inLiteral && (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z')) { i--; break; } else { buf.append(c); } } } indexRef[0] = i; return buf.toString(); }
Example 20
Source File: Range.java From lams with GNU General Public License v2.0 | 3 votes |
/** * <p>Gets the range as a <code>String</code>.</p> * * <p>The format of the String is 'Range[<i>min</i>,<i>max</i>]'.</p> * * <p>This implementation uses the {@link #getMinimumNumber()} and * {@link #getMaximumNumber()} methods. * Subclasses may be able to optimise this.</p> * * @return the <code>String</code> representation of this range */ public String toString() { StrBuilder buf = new StrBuilder(32); buf.append("Range["); buf.append(getMinimumNumber()); buf.append(','); buf.append(getMaximumNumber()); buf.append(']'); return buf.toString(); }