package io.domisum.lib.auxiliumlib.util;

import io.domisum.lib.auxiliumlib.PHR;
import io.domisum.lib.auxiliumlib.annotations.API;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@API
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class StringListUtil
{
	
	private static final String DEFAULT_DELIMITER = ", ";
	
	
	@API
	public static <T> String list(Iterable<T> iterable, Function<T, Object> function, String delimiter)
	{
		var display = new StringBuilder();
		boolean removeDelimiter = false;
		for(T element : iterable)
		{
			var elementDisplay = function == null ? element : function.apply(element);
			display.append(elementDisplay);
			display.append(delimiter);
			removeDelimiter = true;
		}
		
		if(removeDelimiter)
			display.delete(display.length()-delimiter.length(), display.length());
		
		return display.toString();
	}
	
	@API
	public static <T> String list(Iterable<T> iterable, Function<T, Object> function)
	{
		return list(iterable, function, DEFAULT_DELIMITER);
	}
	
	@API
	public static String list(Iterable<?> iterable, String delimiter)
	{
		return list(iterable, null, delimiter);
	}
	
	@API
	public static String list(Iterable<?> iterable)
	{
		return list(iterable, DEFAULT_DELIMITER);
	}
	
	@API
	public static String list(String delimiter, Object... items)
	{
		return list(Arrays.asList(items), delimiter);
	}
	
	
	@API
	public static <T> String list(Map<?, T> map, String delimiter, Function<T, Object> valueFunction)
	{
		var mappings = new ArrayList<String>();
		for(var entry : map.entrySet())
		{
			String mapping = PHR.r("'{}'->'{}'", entry.getKey(), valueFunction.apply(entry.getValue()));
			mappings.add(mapping);
		}
		mappings.sort(Comparator.naturalOrder());
		
		return list(mappings, delimiter);
	}
	
	@API
	public static <T> String list(Map<?, T> map, Function<T, Object> valueFunction)
	{
		return list(map, DEFAULT_DELIMITER, valueFunction);
	}
	
	
	@API
	public static String list(Map<?, ?> map, String delimiter)
	{
		return list(map, delimiter, v->v);
	}
	
	@API
	public static String list(Map<?, ?> map)
	{
		return list(map, DEFAULT_DELIMITER);
	}
	
	
	@API
	public static String list(Stream<?> stream, String delimiter)
	{
		var elementsCollection = stream.collect(Collectors.toList());
		return list(elementsCollection, delimiter);
	}
	
	@API
	public static String list(Stream<?> stream)
	{
		return list(stream, DEFAULT_DELIMITER);
	}
	
}

@@ -2626,10 +2626,254 @@
 );%0A%09%7D%0A%09%0A
+%09%0A%09@API%0A%09public static %3CT%3E String listInSingleQuotes(Iterable%3CT%3E iterable)%0A%09%7B%0A%09%09return list(iterable, s-%3E%22'%22+s+%22'%22);%0A%09%7D%0A%09%0A%09@API%0A%09public static %3CT%3E String listInDoubleQuotes(Iterable%3CT%3E iterable)%0A%09%7B%0A%09%09return list(iterable, s-%3E%22%5C%22%22+s+%22%5C%22%22);%0A%09%7D%0A%09%0A
 %7D%0A

Add StringListUtil#listInDoubleQuotes