Example usage for java.util StringJoiner setEmptyValue

List of usage examples for java.util StringJoiner setEmptyValue

Introduction

In this page you can find the example usage for java.util StringJoiner setEmptyValue.

Prototype

public StringJoiner setEmptyValue(CharSequence emptyValue) 

Source Link

Document

Sets the sequence of characters to be used when determining the string representation of this StringJoiner and no elements have been added yet, that is, when it is empty.

Usage

From source file:iterator.test.matchers.type.annotation.AnnotationMap.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder("@");
    sb.append(getAnnotationClass().getSimpleName());
    StringJoiner joiner = new StringJoiner(COMMA, "(", ")");
    joiner.setEmptyValue(EMPTY);
    if (members.containsKey("value")) {
        MemberValue<?> mv = members.get("value");
        if (mv.isUndefined() || !mv.isDefault()) {
            if (members.size() > 1
                    && members.entrySet().stream().filter(entry -> !"value".equals(entry.getKey()))
                            .anyMatch(entry -> !entry.getValue().isDefault())) {
                joiner.add(String.format("value = %s", mv));
            } else {
                joiner.add(mv.toString());
            }/*from w w  w.  java2 s  .  co  m*/
        }
    }
    members.entrySet().stream().filter(entry -> !"value".equals(entry.getKey())
            && (entry.getValue().isUndefined() || !entry.getValue().isDefault())).forEach(entry -> {
                joiner.add(String.format("%s = %s", entry.getKey(), entry.getValue()));
            });
    sb.append(joiner.toString());
    return sb.toString();
}