org.apache.dubbo.common.utils.StringUtils.repeat()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.apache.dubbo.common.utils.StringUtils.repeat()方法的一些代码示例,展示了StringUtils.repeat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.repeat()方法的具体详情如下:
包路径:org.apache.dubbo.common.utils.StringUtils
类名称:StringUtils
方法名:repeat

StringUtils.repeat介绍

[英]Returns padding using the specified delimiter repeated to a given length.

StringUtils.repeat('e', 0)  = "" 
StringUtils.repeat('e', 3)  = "eee" 
StringUtils.repeat('e', -2) = ""

Note: this method doesn't not support padding with Unicode Supplementary Characters as they require a pair of chars to be represented. If you are needing to support full I18N of your applications consider using #repeat(String,int) instead.
[中]返回使用指定分隔符重复指定长度的填充。

StringUtils.repeat('e', 0)  = "" 
StringUtils.repeat('e', 3)  = "eee" 
StringUtils.repeat('e', -2) = ""

注意:此方法不支持使用Unicode Supplementary Characters填充,因为它们需要表示一对字符。如果需要支持应用程序的完整I18N,请考虑使用“重复”(String,int)。

代码示例

代码示例来源:origin: apache/incubator-dubbo

private String getDataFormat(ColumnDefine columnDefine, int width, String data) {
  switch (columnDefine.align) {
    case MIDDLE: {
      final int length = length(data);
      final int diff = width - length;
      final int left = diff / 2;
      return repeat(" ", diff - left) + "%s" + repeat(" ", left);
    }
    case RIGHT: {
      return "%" + width + "s";
    }
    case LEFT:
    default: {
      return "%-" + width + "s";
    }
  }
}

代码示例来源:origin: apache/incubator-dubbo

private String getDataFormat(ColumnDefine columnDefine, int width, String data) {
  switch (columnDefine.align) {
    case MIDDLE: {
      final int length = length(data);
      final int diff = width - length;
      final int left = diff / 2;
      return repeat(" ", diff - left) + "%s" + repeat(" ", left);
    }
    case RIGHT: {
      return "%" + width + "s";
    }
    case LEFT:
    default: {
      return "%-" + width + "s";
    }
  }
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * <p>Repeat a String {@code repeat} times to form a
 * new String, with a String separator injected each time. </p>
 *
 * <pre>
 * StringUtils.repeat(null, null, 2) = null
 * StringUtils.repeat(null, "x", 2)  = null
 * StringUtils.repeat("", null, 0)   = ""
 * StringUtils.repeat("", "", 2)     = ""
 * StringUtils.repeat("", "x", 3)    = "xxx"
 * StringUtils.repeat("?", ", ", 3)  = "?, ?, ?"
 * </pre>
 *
 * @param str        the String to repeat, may be null
 * @param separator  the String to inject, may be null
 * @param repeat     number of times to repeat str, negative treated as zero
 * @return a new String consisting of the original String repeated,
 *  {@code null} if null String input
 * @since 2.5
 */
public static String repeat(final String str, final String separator, final int repeat) {
  if(str == null || separator == null) {
    return repeat(str, repeat);
  }
  // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
  final String result = repeat(str + separator, repeat);
  return removeEnd(result, separator);
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * <p>Repeat a String {@code repeat} times to form a
 * new String, with a String separator injected each time. </p>
 *
 * <pre>
 * StringUtils.repeat(null, null, 2) = null
 * StringUtils.repeat(null, "x", 2)  = null
 * StringUtils.repeat("", null, 0)   = ""
 * StringUtils.repeat("", "", 2)     = ""
 * StringUtils.repeat("", "x", 3)    = "xxx"
 * StringUtils.repeat("?", ", ", 3)  = "?, ?, ?"
 * </pre>
 *
 * @param str        the String to repeat, may be null
 * @param separator  the String to inject, may be null
 * @param repeat     number of times to repeat str, negative treated as zero
 * @return a new String consisting of the original String repeated,
 *  {@code null} if null String input
 * @since 2.5
 */
public static String repeat(final String str, final String separator, final int repeat) {
  if(str == null || separator == null) {
    return repeat(str, repeat);
  }
  // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
  final String result = repeat(str + separator, repeat);
  return removeEnd(result, separator);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public String rendering() {
  final StringBuilder ladderSB = new StringBuilder();
  int deep = 0;
  for (String item : items) {
    // no separator is required for the first item
    if (deep == 0) {
      ladderSB
          .append(item)
          .append(System.lineSeparator());
    }
    // need separator for others
    else {
      ladderSB
          .append(repeat(STEP_CHAR, deep * INDENT_STEP))
          .append(LADDER_CHAR)
          .append(item)
          .append(System.lineSeparator());
    }
    deep++;
  }
  return ladderSB.toString();
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public String rendering() {
  final StringBuilder ladderSB = new StringBuilder();
  int deep = 0;
  for (String item : items) {
    // no separator is required for the first item
    if (deep == 0) {
      ladderSB
          .append(item)
          .append(System.lineSeparator());
    }
    // need separator for others
    else {
      ladderSB
          .append(repeat(STEP_CHAR, deep * INDENT_STEP))
          .append(LADDER_CHAR)
          .append(item)
          .append(System.lineSeparator());
    }
    deep++;
  }
  return ladderSB.toString();
}

代码示例来源:origin: apache/incubator-dubbo

return repeat(str.charAt(0), repeat);
switch (inputLength) {
  case 1 :
    return repeat(str.charAt(0), repeat);
  case 2 :
    final char ch0 = str.charAt(0);

代码示例来源:origin: apache/incubator-dubbo

return repeat(str.charAt(0), repeat);
switch (inputLength) {
  case 1 :
    return repeat(str.charAt(0), repeat);
  case 2 :
    final char ch0 = str.charAt(0);

代码示例来源:origin: apache/incubator-dubbo

} else {
  treeSB.append(prefix)
      .append(repeat(' ', stepStringLength))
      .append(hasChild ? "|" : EMPTY)
      .append(repeat(' ', costPrefixLength))
      .append(scanner.nextLine())
      .append(System.lineSeparator());

代码示例来源:origin: apache/incubator-dubbo

} else {
  treeSB.append(prefix)
      .append(repeat(' ', stepStringLength))
      .append(hasChild ? "|" : EMPTY)
      .append(repeat(' ', costPrefixLength))
      .append(scanner.nextLine())
      .append(System.lineSeparator());

代码示例来源:origin: apache/incubator-dubbo

/**
 * draw separation line
 */
private String drawSeparationLine(final int[] widthCacheArray) {
  final StringBuilder separationLineSB = new StringBuilder();
  final int lastCol = indexLastCol(widthCacheArray);
  final int colCount = widthCacheArray.length;
  for (int colIndex = 0; colIndex < colCount; colIndex++) {
    final int width = widthCacheArray[colIndex];
    if (width <= 0) {
      continue;
    }
    final boolean isFirstCol = colIndex == 0;
    final boolean isLastCol = colIndex == lastCol;
    if (isFirstCol
        && border.has(Border.BORDER_OUTER_LEFT)) {
      separationLineSB.append("+");
    }
    if (!isFirstCol
        && border.has(Border.BORDER_INNER_V)) {
      separationLineSB.append("+");
    }
    separationLineSB.append(repeat("-", width + 2 * padding));
    if (isLastCol
        && border.has(Border.BORDER_OUTER_RIGHT)) {
      separationLineSB.append("+");
    }
  }
  return separationLineSB.toString();
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * draw separation line
 */
private String drawSeparationLine(final int[] widthCacheArray) {
  final StringBuilder separationLineSB = new StringBuilder();
  final int lastCol = indexLastCol(widthCacheArray);
  final int colCount = widthCacheArray.length;
  for (int colIndex = 0; colIndex < colCount; colIndex++) {
    final int width = widthCacheArray[colIndex];
    if (width <= 0) {
      continue;
    }
    final boolean isFirstCol = colIndex == 0;
    final boolean isLastCol = colIndex == lastCol;
    if (isFirstCol
        && border.has(Border.BORDER_OUTER_LEFT)) {
      separationLineSB.append("+");
    }
    if (!isFirstCol
        && border.has(Border.BORDER_INNER_V)) {
      separationLineSB.append("+");
    }
    separationLineSB.append(repeat("-", width + 2 * padding));
    if (isLastCol
        && border.has(Border.BORDER_OUTER_RIGHT)) {
      separationLineSB.append("+");
    }
  }
  return separationLineSB.toString();
}

代码示例来源:origin: apache/incubator-dubbo

final ColumnDefine columnDefine = columnDefineArray[colIndex];
final String dataFormat = getDataFormat(columnDefine, width, data);
final String paddingChar = repeat(" ", padding);
segmentSB.append(format(borderChar + paddingChar + dataFormat + paddingChar, data));

代码示例来源:origin: apache/incubator-dubbo

final ColumnDefine columnDefine = columnDefineArray[colIndex];
final String dataFormat = getDataFormat(columnDefine, width, data);
final String paddingChar = repeat(" ", padding);
segmentSB.append(format(borderChar + paddingChar + dataFormat + paddingChar, data));

代码示例来源:origin: org.apache.dubbo/dubbo

private String getDataFormat(ColumnDefine columnDefine, int width, String data) {
  switch (columnDefine.align) {
    case MIDDLE: {
      final int length = length(data);
      final int diff = width - length;
      final int left = diff / 2;
      return repeat(" ", diff - left) + "%s" + repeat(" ", left);
    }
    case RIGHT: {
      return "%" + width + "s";
    }
    case LEFT:
    default: {
      return "%-" + width + "s";
    }
  }
}

代码示例来源:origin: org.apache.dubbo/dubbo-qos

private String getDataFormat(ColumnDefine columnDefine, int width, String data) {
  switch (columnDefine.align) {
    case MIDDLE: {
      final int length = length(data);
      final int diff = width - length;
      final int left = diff / 2;
      return repeat(" ", diff - left) + "%s" + repeat(" ", left);
    }
    case RIGHT: {
      return "%" + width + "s";
    }
    case LEFT:
    default: {
      return "%-" + width + "s";
    }
  }
}

代码示例来源:origin: org.apache.dubbo/dubbo-common

/**
 * <p>Repeat a String {@code repeat} times to form a
 * new String, with a String separator injected each time. </p>
 *
 * <pre>
 * StringUtils.repeat(null, null, 2) = null
 * StringUtils.repeat(null, "x", 2)  = null
 * StringUtils.repeat("", null, 0)   = ""
 * StringUtils.repeat("", "", 2)     = ""
 * StringUtils.repeat("", "x", 3)    = "xxx"
 * StringUtils.repeat("?", ", ", 3)  = "?, ?, ?"
 * </pre>
 *
 * @param str        the String to repeat, may be null
 * @param separator  the String to inject, may be null
 * @param repeat     number of times to repeat str, negative treated as zero
 * @return a new String consisting of the original String repeated,
 *  {@code null} if null String input
 * @since 2.5
 */
public static String repeat(final String str, final String separator, final int repeat) {
  if(str == null || separator == null) {
    return repeat(str, repeat);
  }
  // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
  final String result = repeat(str + separator, repeat);
  return removeEnd(result, separator);
}

代码示例来源:origin: org.apache.dubbo/dubbo

/**
 * <p>Repeat a String {@code repeat} times to form a
 * new String, with a String separator injected each time. </p>
 *
 * <pre>
 * StringUtils.repeat(null, null, 2) = null
 * StringUtils.repeat(null, "x", 2)  = null
 * StringUtils.repeat("", null, 0)   = ""
 * StringUtils.repeat("", "", 2)     = ""
 * StringUtils.repeat("", "x", 3)    = "xxx"
 * StringUtils.repeat("?", ", ", 3)  = "?, ?, ?"
 * </pre>
 *
 * @param str        the String to repeat, may be null
 * @param separator  the String to inject, may be null
 * @param repeat     number of times to repeat str, negative treated as zero
 * @return a new String consisting of the original String repeated,
 *  {@code null} if null String input
 * @since 2.5
 */
public static String repeat(final String str, final String separator, final int repeat) {
  if(str == null || separator == null) {
    return repeat(str, repeat);
  }
  // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
  final String result = repeat(str + separator, repeat);
  return removeEnd(result, separator);
}

代码示例来源:origin: org.apache.dubbo/dubbo

@Override
public String rendering() {
  final StringBuilder ladderSB = new StringBuilder();
  int deep = 0;
  for (String item : items) {
    // no separator is required for the first item
    if (deep == 0) {
      ladderSB
          .append(item)
          .append(System.lineSeparator());
    }
    // need separator for others
    else {
      ladderSB
          .append(repeat(STEP_CHAR, deep * INDENT_STEP))
          .append(LADDER_CHAR)
          .append(item)
          .append(System.lineSeparator());
    }
    deep++;
  }
  return ladderSB.toString();
}

代码示例来源:origin: org.apache.dubbo/dubbo-qos

@Override
public String rendering() {
  final StringBuilder ladderSB = new StringBuilder();
  int deep = 0;
  for (String item : items) {
    // no separator is required for the first item
    if (deep == 0) {
      ladderSB
          .append(item)
          .append(System.lineSeparator());
    }
    // need separator for others
    else {
      ladderSB
          .append(repeat(STEP_CHAR, deep * INDENT_STEP))
          .append(LADDER_CHAR)
          .append(item)
          .append(System.lineSeparator());
    }
    deep++;
  }
  return ladderSB.toString();
}

相关文章