org.apache.logging.log4j.util.Strings.join()方法的使用及代码示例

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

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

Strings.join介绍

[英]Joins the elements of the provided Iterable into a single String containing the provided elements.

No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.
[中]将提供的Iterable的元素连接到包含提供的元素的单个字符串中。
列表前后不添加分隔符。迭代中的空对象或空字符串由空字符串表示。

代码示例

代码示例来源:origin: org.apache.logging.log4j/log4j-api

/**
 * <p>Joins the elements of the provided {@code Iterable} into
 * a single String containing the provided elements.</p>
 *
 * <p>No delimiter is added before or after the list. Null objects or empty
 * strings within the iteration are represented by empty strings.</p>
 *
 * @param iterable  the {@code Iterable} providing the values to join together, may be null
 * @param separator  the separator character to use
 * @return the joined String, {@code null} if null iterator input
 */
public static String join(final Iterable<?> iterable, final char separator) {
  if (iterable == null) {
    return null;
  }
  return join(iterable.iterator(), separator);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void testJoin() {
  Assert.assertEquals(null, Strings.join((Iterable<?>) null, '.'));
  Assert.assertEquals(null, Strings.join((Iterator<?>) null, '.'));
  Assert.assertEquals("", Strings.join((Arrays.asList()), '.'));
  Assert.assertEquals("a", Strings.join(Arrays.asList("a"), '.'));
  Assert.assertEquals("a.b", Strings.join(Arrays.asList("a", "b"), '.'));
  Assert.assertEquals("a.b.c", Strings.join(Arrays.asList("a", "b", "c"), '.'));
  Assert.assertEquals("", Strings.join(Arrays.asList((String) null), ':'));
  Assert.assertEquals(":", Strings.join(Arrays.asList(null, null), ':'));
  Assert.assertEquals("a:", Strings.join(Arrays.asList("a", null), ':'));
  Assert.assertEquals(":b", Strings.join(Arrays.asList(null, "b"), ':'));
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * <p>Joins the elements of the provided {@code Iterable} into
 * a single String containing the provided elements.</p>
 *
 * <p>No delimiter is added before or after the list. Null objects or empty
 * strings within the iteration are represented by empty strings.</p>
 *
 * @param iterable  the {@code Iterable} providing the values to join together, may be null
 * @param separator  the separator character to use
 * @return the joined String, {@code null} if null iterator input
 */
public static String join(final Iterable<?> iterable, final char separator) {
  if (iterable == null) {
    return null;
  }
  return join(iterable.iterator(), separator);
}

代码示例来源:origin: spring-cloud/spring-cloud-gcp

@Override
  public String toString() {
    return "Singer{" + "singerId='" + this.singerId + '\'' + ", firstName='"
        + this.firstName + '\'' + ", lastName='" + this.lastName + '\''
        + ", albums=" + this.albums + ", firstBand=" + this.firstBand + ", bands="
        + ((this.bands == null) ? ""
            : Strings.join(this.bands.stream().map((x) -> x.getName())
                .collect(Collectors.toList()), ','))
        + ", personalInstruments="
        + ((this.personalInstruments == null) ? ""
            : Strings.join(this.personalInstruments.stream()
                .map((x) -> x.getType()).collect(Collectors.toList()), ','))
        + '}';
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-1.2-api

@Override
  public void format(final LogEvent event, final StringBuilder toAppendTo) {
    final List<String> ndc = event.getContextStack().asList();
    toAppendTo.append(Strings.join(ndc, ' '));
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-1.2-api

if (!ndc.isEmpty()) {
  buf.append("<log4j:NDC><![CDATA[");
  Transform.appendEscapingCData(buf, Strings.join(ndc, ' '));
  buf.append("]]></log4j:NDC>\r\n");

代码示例来源:origin: PegaSysEng/pantheon

/** Logs the Peer connections for each node. */
public void logPeerConnections() {
 final List<String> connStr = new ArrayList<>();
 for (final TestNode node : nodes) {
  for (final PeerConnection peer : node.network.getPeers()) {
   final String localString = node.shortId() + "@" + peer.getLocalAddress();
   final String peerString =
     shortId(peer.getPeer().getNodeId()) + "@" + peer.getRemoteAddress();
   connStr.add("Connection: " + localString + " to " + peerString);
  }
 }
 LOG.info("TestNodeList Connections:\n" + join(connStr, '\n'));
}

相关文章