Java Code Examples for java.util.StringJoiner#setEmptyValue()

The following examples show how to use java.util.StringJoiner#setEmptyValue() . 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: DCmdCheck.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printSetttings(Recording recording) {
    Map<String, String> settings = recording.getSettings();
    for (EventType eventType : sortByEventPath(getFlightRecorder().getEventTypes())) {
        StringJoiner sj = new StringJoiner(",", "[", "]");
        sj.setEmptyValue("");
        for (SettingDescriptor s : eventType.getSettingDescriptors()) {
            String settingsPath = eventType.getName() + "#" + s.getName();
            if (settings.containsKey(settingsPath)) {
                sj.add(s.getName() + "=" + settings.get(settingsPath));
            }
        }
        String settingsText = sj.toString();
        if (!settingsText.isEmpty()) {
            print(" %s (%s)", eventType.getLabel(), eventType.getName());
            println();
            println("   " + settingsText);
        }
    }
}
 
Example 2
Source File: MergeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 3
Source File: MergeTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 4
Source File: MergeTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 5
Source File: MergeTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 6
Source File: MergeTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 7
Source File: MergeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 8
Source File: DCmdCheck.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void printSetttings(Recording recording) {
    Map<String, String> settings = recording.getSettings();
    for (EventType eventType : sortByEventPath(getFlightRecorder().getEventTypes())) {
        StringJoiner sj = new StringJoiner(",", "[", "]");
        sj.setEmptyValue("");
        for (SettingDescriptor s : eventType.getSettingDescriptors()) {
            String settingsPath = eventType.getName() + "#" + s.getName();
            if (settings.containsKey(settingsPath)) {
                sj.add(s.getName() + "=" + settings.get(settingsPath));
            }
        }
        String settingsText = sj.toString();
        if (!settingsText.isEmpty()) {
            print(" %s (%s)", eventType.getLabel(), eventType.getName());
            println();
            println("   " + settingsText);
        }
    }
}
 
Example 9
Source File: MergeTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 10
Source File: MergeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void testEmptyBoth() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");

    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    other.setEmptyValue("NOTHING");
    sj.merge(other);
    assertEquals(sj.toString(), "{}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "EMPTY");
}
 
Example 11
Source File: MergeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyOther() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");

    other.setEmptyValue("EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");
}
 
Example 12
Source File: MergeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyOther() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");

    other.setEmptyValue("EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");
}
 
Example 13
Source File: ParameterizedTypeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public String toString() {
    StringBuilder sb = new StringBuilder();

    if (ownerType != null) {
        sb.append(ownerType.getTypeName());

        sb.append("$");

        if (ownerType instanceof ParameterizedTypeImpl) {
            // Find simple name of nested type by removing the
            // shared prefix with owner.
            sb.append(rawType.getName().replace( ((ParameterizedTypeImpl)ownerType).rawType.getName() + "$",
                                     ""));
        } else
           sb.append(rawType.getSimpleName());
    } else
        sb.append(rawType.getName());

    if (actualTypeArguments != null) {
        StringJoiner sj = new StringJoiner(", ", "<", ">");
        sj.setEmptyValue("");
        for(Type t: actualTypeArguments) {
            sj.add(t.getTypeName());
        }
        sb.append(sj.toString());
    }

    return sb.toString();
}
 
Example 14
Source File: StringJoinerClass.java    From JavaSE8-Features with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
		
//		Creating a StringJoiner
		StringJoiner sj = new StringJoiner(",", "{", "}");
		sj.setEmptyValue("No stooges yet");
		System.out.println(sj);
		
		sj.add("Moe")
			.add("Larry")
			.add("Curly");
		System.out.println(sj);
		
//		Merging StringJoiner instances
		StringJoiner sj2 = new StringJoiner(",");
		sj2.add("Shemp");
		
		sj.merge(sj2);
		System.out.println(sj);
		
//		Working with collections
		Set<String> set = new TreeSet<>();
		set.add("California");
		set.add("Oregon");
		set.add("Washington");
		StringJoiner sj3 = new StringJoiner(" and ");
		set.forEach( s -> sj3.add(s));
		
		System.out.println(sj3);
	}
 
Example 15
Source File: CheckCfgTemplateProposalProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds template proposals for all checks which may be referenced in current catalog configuration. Only proposals for checks
 * which have not yet been configured are provided.
 *
 * @param templateContext
 *          the template context
 * @param context
 *          the context
 * @param acceptor
 *          the acceptor
 */
private void addConfiguredCheckTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) { // NOPMD
  ConfiguredCatalog configuredCatalog = EcoreUtil2.getContainerOfType(context.getCurrentModel(), ConfiguredCatalog.class);
  Iterable<String> alreadyConfiguredCheckNames = Iterables.filter(Iterables.transform(configuredCatalog.getCheckConfigurations(), new Function<ConfiguredCheck, String>() {
    @Override
    public String apply(final ConfiguredCheck from) {
      if (from.getCheck() != null) {
        return from.getCheck().getName();
      }
      return null;
    }
  }), Predicates.notNull());
  final CheckCatalog catalog = configuredCatalog.getCatalog();
  for (final Check check : catalog.getAllChecks()) {
    // create a template on the fly
    final String checkName = check.getName();
    if (!Iterables.contains(alreadyConfiguredCheckNames, checkName)) {

      // check if referenced check has configurable parameters
      final StringJoiner paramsJoiner = new StringJoiner(", ", " (", ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      paramsJoiner.setEmptyValue(""); //$NON-NLS-1$
      for (final FormalParameter param : check.getFormalParameters()) {
        final String paramName = param.getName();
        final Object defaultValue = interpreter.evaluate(param.getRight()).getResult();

        final String valuePlaceholder = helper.createLiteralValuePattern(paramName, defaultValue);
        paramsJoiner.add(paramName + " = " + valuePlaceholder); //$NON-NLS-1$
      }

      final String severity = (catalog.isFinal() || check.isFinal()) ? "default " : "${default:Enum('SeverityKind')} "; //$NON-NLS-1$ //$NON-NLS-2$
      final String description = "Configures the check \"" + check.getLabel() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
      final String contextTypeId = "com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck." + checkName; //$NON-NLS-1$
      final String pattern = severity + qualifiedNameValueConverter.toString(checkName) + paramsJoiner + "${cursor}"; //$NON-NLS-1$

      Template t = new Template(checkName, description, contextTypeId, pattern, true);
      TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCheck(check.getDefaultSeverity()), getRelevance(t));
      acceptor.accept(tp);
    }
  }
}
 
Example 16
Source File: MergeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyOther() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");

    other.setEmptyValue("EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");
}
 
Example 17
Source File: SyndesisServerContainer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private String getJavaOptionString() {
    StringJoiner stringJoiner = new StringJoiner(" -D", "-D", "");
    stringJoiner.setEmptyValue("");
    javaOptions.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).forEach(stringJoiner::add);

    String optionString = stringJoiner.toString();
    if (enableDebug) {
        return optionString + String.format(" -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=%s", SyndesisTestEnvironment.getDebugPort());
    }

    return optionString;
}
 
Example 18
Source File: MergeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyOther() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");

    other.setEmptyValue("EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");
}
 
Example 19
Source File: MergeTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptyOther() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");

    other.setEmptyValue("EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c}");
}
 
Example 20
Source File: StringJoinerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenJoinerWithPrefixSuffixWithEmptyValue_thenReturnDefault() {
    StringJoiner commaSeparatedPrefixSuffixJoiner = new StringJoiner(DELIMITER_COMMA, PREFIX, SUFFIX);
    commaSeparatedPrefixSuffixJoiner.setEmptyValue(EMPTY_JOINER);

    assertEquals(commaSeparatedPrefixSuffixJoiner.toString(), EMPTY_JOINER);
}