All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.polyglotted.common.util.CommaUtil Maven / Gradle / Ivy

package io.polyglotted.common.util;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Splitter.MapSplitter;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@SuppressWarnings({"unused", "WeakerAccess"})
public abstract class CommaUtil {
    private static final Splitter COMMA_SPLITTER = Splitter.on(",").trimResults().omitEmptyStrings();
    private static final MapSplitter EQUALS_SPLITTER = COMMA_SPLITTER.withKeyValueSeparator("=");
    private static final Joiner COMMA_JOINER = Joiner.on(",").skipNulls();

    public static Map commaEqSplit(String value) { return EQUALS_SPLITTER.split(value); }

    public static Map mapSplit(String value, String separator) { return mapSplitter(separator).split(value); }

    public static MapSplitter mapSplitter(String keyValueSeparator) { return COMMA_SPLITTER.withKeyValueSeparator(keyValueSeparator); }

    public static List commaSplit(String value) { return value == null ? null : COMMA_SPLITTER.splitToList(value); }

    public static String commaJoin(Collection values) { return values == null ? null : COMMA_JOINER.join(values); }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy