org.apache.commons.lang.text.StrBuilder#toString ( )源码实例Demo

下面列出了org.apache.commons.lang.text.StrBuilder#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: NumberRange.java
/**
 * <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();
}
 
源代码2 项目: lams   文件: CharSetUtils.java
/**
 * <p>Squeezes any repetitions of a character that is mentioned in the
 * supplied set.</p>
 *
 * <p>An example is:</p>
 * <ul>
 *   <li>squeeze(&quot;hello&quot;, {&quot;el&quot;}) => &quot;helo&quot;</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();
}
 
源代码3 项目: lams   文件: ClassUtils.java
/**
 * 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;
}
 
源代码4 项目: hop   文件: Const.java
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();
}
 
源代码5 项目: kylin-on-parquet-v2   文件: PushDownUtil.java
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();
}
 
源代码6 项目: lams   文件: IntRange.java
/**
 * <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;
}
 
源代码7 项目: lams   文件: NumberRange.java
/**
 * <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;
}
 
源代码8 项目: lams   文件: LongRange.java
/**
 * <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;
}
 
源代码9 项目: lams   文件: DoubleRange.java
/**
 * <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;
}
 
源代码10 项目: lams   文件: CharSetUtils.java
/**
 * 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();
}
 
源代码11 项目: celos   文件: FixObjectCompareResult.java
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();
}
 
源代码12 项目: lams   文件: ClassUtils.java
/**
 * <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();
        }
    }
}
 
源代码13 项目: mxisd   文件: MessageEventProcessor.java
public String getHelp() {
    StrBuilder builder = new StrBuilder();
    builder.appendln("Available commands:");
    for (String cmd : processors.keySet()) {
        builder.append("\t").appendln(cmd);
    }
    return builder.toString();
}
 
源代码14 项目: pentaho-kettle   文件: Const.java
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();
  }
 
源代码15 项目: kfs   文件: DataReportServiceImpl.java
/**
 * @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();
}
 
源代码16 项目: kfs   文件: AgencyStagingDataMaintainable.java
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();
    }
 
源代码17 项目: lams   文件: CharSetUtils.java
/**
 * <p>Translate characters in a String.
 * This is a multi character search and replace routine.</p>
 *
 * <p>An example is:</p>
 * <ul>
 *   <li>translate(&quot;hello&quot;, &quot;ho&quot;, &quot;jy&quot;)
 *    =&gt; 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 (&quot;&quot;)
 * @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 (&quot;&quot;)
 * @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();
}
 
源代码18 项目: lams   文件: DurationFormatUtils.java
/**
 * <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();
}
 
源代码19 项目: lams   文件: FastDateFormat.java
/**
 * <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();
}
 
源代码20 项目: lams   文件: Range.java
/**
 * <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();
}