Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
Expand Down Expand Up @@ -33,15 +34,15 @@
* @param list the list of strings to join. If the list is empty, an empty string is returned.
* @return the concatenated string
*/
public static @NotNull String joinAnd(List<String> list) {
public static @NotNull String joinAnd(@Nullable List<String> list) {
return join(list, ", ", " and ");
}

public static @NotNull String join(Collection list, String separator) {
public static @NotNull String join(@Nullable Collection<?> list, @NotNull String separator) {

Check warning on line 41 in src/main/java/org/mvplugins/multiverse/core/utils/StringFormatter.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/utils/StringFormatter.java:41:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
if (list == null || list.isEmpty()) {
return "";
}
return list.stream().map(String::valueOf).collect(Collectors.joining(separator)).toString();
return list.stream().map(String::valueOf).collect(Collectors.joining(separator));
}

/**
Expand All @@ -53,7 +54,7 @@
* @param lastSeparator the separator to use before the last element. For example, " and ".
* @return the concatenated string
*/
public static @NotNull String join(List<String> list, String separator, String lastSeparator) {
public static @NotNull String join(@Nullable List<String> list, @NotNull String separator, @NotNull String lastSeparator) {

Check warning on line 57 in src/main/java/org/mvplugins/multiverse/core/utils/StringFormatter.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 127). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/utils/StringFormatter.java:57:0: warning: Line is longer than 120 characters (found 127). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
if (list == null || list.isEmpty()) {
return "";
}
Expand Down Expand Up @@ -116,7 +117,7 @@
* @param args The args to parse
* @return The parsed args
*/
public static Collection<String> parseQuotesInArgs(String[] args) {
public static @NotNull Collection<String> parseQuotesInArgs(@NotNull String[] args) {

Check warning on line 120 in src/main/java/org/mvplugins/multiverse/core/utils/StringFormatter.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Cyclomatic Complexity is 12 (max allowed is 7). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/utils/StringFormatter.java:120:5: warning: Cyclomatic Complexity is 12 (max allowed is 7). (com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck)
List<String> result = new ArrayList<>(args.length);
StringBuilder current = new StringBuilder();
boolean inQuotes = false;
Expand Down Expand Up @@ -161,8 +162,9 @@
* @param input The string to add quotes to
* @return The quoted string
*/
public static String quoteMultiWordString(String input) {
return input.contains(" ") ? "\"" + input + "\"" : input;
@Contract("null -> null")
public static @Nullable String quoteMultiWordString(@Nullable String input) {
return input != null && input.contains(" ") ? "\"" + input + "\"" : input;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.mvplugins.multiverse.core.utils

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class StringFormatterTest {
@Test
Expand Down Expand Up @@ -42,6 +43,7 @@ class StringFormatterTest {
"test",
StringFormatter.quoteMultiWordString("test")
)
assertNull(StringFormatter.quoteMultiWordString(null))
}

@Test
Expand Down