Finalize ListConverter

after two months, it finally works
This commit is contained in:
JeremyStar™ 2024-08-12 20:51:37 +02:00
parent 949655b020
commit 1713c9c8a8
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 33 additions and 11 deletions

View file

@ -19,10 +19,8 @@
package de.staropensource.sosengine.base.utility; package de.staropensource.sosengine.base.utility;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -46,9 +44,20 @@ public final class ListFormatter {
* @param array array to convert * @param array array to convert
* @return formatted string * @return formatted string
*/ */
@ApiStatus.Experimental() // TODO
public static @NotNull String formatArray(@NotNull Object[] array) { public static @NotNull String formatArray(@NotNull Object[] array) {
return Arrays.toString(array); StringBuilder output = new StringBuilder();
for (int index = 0; index < array.length; index++) {
if (!output.isEmpty())
if (index == array.length - 1)
output.append(" & ");
else
output.append(", ");
output.append(array[index]);
}
return output.toString();
} }
/** /**
@ -57,9 +66,8 @@ public final class ListFormatter {
* @param set set to convert * @param set set to convert
* @return formatted string * @return formatted string
*/ */
@ApiStatus.Experimental() // TODO
public static @NotNull String formatSet(@NotNull Set<?> set) { public static @NotNull String formatSet(@NotNull Set<?> set) {
return set.toString(); return formatArray(set.toArray());
} }
/** /**
@ -68,9 +76,8 @@ public final class ListFormatter {
* @param list list to convert * @param list list to convert
* @return formatted string * @return formatted string
*/ */
@ApiStatus.Experimental() // TODO
public static @NotNull String formatList(@NotNull List<?> list) { public static @NotNull String formatList(@NotNull List<?> list) {
return list.toString(); return formatArray(list.toArray());
} }
/** /**
@ -79,8 +86,23 @@ public final class ListFormatter {
* @param map map to convert * @param map map to convert
* @return formatted string * @return formatted string
*/ */
@ApiStatus.Experimental() // TODO
public static @NotNull String formatMap(@NotNull Map<?, ?> map) { public static @NotNull String formatMap(@NotNull Map<?, ?> map) {
return map.toString(); StringBuilder output = new StringBuilder();
int index = 0;
for (Object key : map.keySet()) {
if (!output.isEmpty())
if (index == map.size() - 1)
output.append(" & ");
else
output.append(", ");
output
.append(key)
.append("=")
.append(map.get(key));
}
return output.toString();
} }
} }

View file

@ -22,7 +22,7 @@ import org.mikeneck.graalvm.BuildTypeSelector
// Plugins // Plugins
plugins { plugins {
id("java") id("java")
id "application" id("application")
id("io.freefair.lombok") version("${pluginLombok}") id("io.freefair.lombok") version("${pluginLombok}")
id("io.github.goooler.shadow") version("${pluginShadow}") id("io.github.goooler.shadow") version("${pluginShadow}")
id('org.mikeneck.graalvm-native-image') version("${pluginNativeImage}") id('org.mikeneck.graalvm-native-image') version("${pluginNativeImage}")