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

org.swiftboot.util.pref.StringListConverter Maven / Gradle / Ivy

The newest version!
package org.swiftboot.util.pref;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Converter for string List, you can create your own implementation.
 *
 * @author allen
 */
public class StringListConverter extends StringConverter> {

    @Override
    public List deserialize(String prefValue) {
        if (StringUtils.isNotBlank(prefValue)) {
            String[] split = StringUtils.split(prefValue, ",");
            if (split != null && split.length > 0) {
                List ret = new ArrayList<>(split.length);
                Collections.addAll(ret, split);
                return ret;
            }
        }
        return null;
    }

    @Override
    public String serialize(List valueObject) {
        return StringUtils.join(valueObject, ",");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy