package com.tofly.ghrq_route.module.OfflineWork.domain;

import org.greenrobot.greendao.converter.PropertyConverter;

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

public class List_String_Converter implements PropertyConverter<List<String>, String> {

    private static final String SPLIT = "#";

    @Override
    public List<String> convertToEntityProperty(String databaseValue) {
        if (databaseValue == null)
            return null;

        List<String> list_str = Arrays.asList(databaseValue.split(SPLIT));
        List<String> fieldsBeanList = new ArrayList<>();

        for (String str : list_str){
            fieldsBeanList.add(str);
        }
        return fieldsBeanList;
    }

    @Override
    public String convertToDatabaseValue(List<String> fieldsBeans) {
        if (fieldsBeans == null){
            return null;
        }else {
            StringBuilder builder = new StringBuilder();
            for (String fieldsBean : fieldsBeans){
                builder.append(fieldsBean);
                builder.append(SPLIT);
            }
            return builder.toString();
        }
    }
}
