io.cloudflight.structurizr.plantuml.MapUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of structurizr-export-c4plantuml Show documentation
Show all versions of structurizr-export-c4plantuml Show documentation
Extension of the Structurizr Export Library
The newest version!
package io.cloudflight.structurizr.plantuml;
import javax.annotation.Nullable;
import java.util.Map;
public class MapUtils {
private MapUtils() {
}
/**
* Transforms the given map into a comma-separated String of key-value pairs, i.e.: key1=value1, key2=value2
.
* The order of the entries is given by {@link Map#entrySet()}, therefore use a {@link java.util.LinkedHashMap} if
* you want to influence the order of the entries.
*
* @param map a map of values
* @return null
, if the map is null. an empty string of the map is empty,
* else a comma-separated string of key/value-pairs
*/
@Nullable
public static String mapToString(Map map) {
if (map == null) {
return null;
}
if (map.isEmpty()) {
return "";
}
StringBuilder buf = new StringBuilder();
for (Map.Entry entry : map.entrySet()) {
buf.append(String.format("%s=%s, ", entry.getKey(), entry.getValue()));
}
String tagsAsString = buf.toString();
return tagsAsString.substring(0, tagsAsString.length() - 2);
}
}