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

org.vxwo.springboot.experience.web.util.SplitUtil Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
package org.vxwo.springboot.experience.web.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author vxwo-team
 */

public final class SplitUtil {

    /**
     * Shrink list, remove blank element
     *
     * @param value  the list for shrink
     * @return  the list by shrinked
     */
    public static List shrinkList(List value) {
        if (value == null) {
            return new ArrayList<>();
        }

        return value.stream().map(o -> o.trim()).filter(o -> !o.isEmpty())
                .collect(Collectors.toList());
    }

    /**
     * Splits the string around matches of the given regular expression.
     *
     * @param value  the string for split for
     * @param regex  the delimiting regular expression
     * @return  the list of strings computed by splitting
     */
    public static List splitToList(String value, String regex) {
        return shrinkList(Arrays.asList(value.split(regex)));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy