package com.gyee.wisdom.common.data;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author songwb<songwb@aliyun.com>
 */
public abstract class DataUtil {

    private DataUtil() {
    }

    public static <T> List<T> convertDataList(Collection<? extends ToData<T>> toDataList) {
        return toDataList.stream().map(ToData::toData).collect(Collectors.toList());
    }

    public static <T> T getData(ToData<T> data) {
        return Optional.ofNullable(data).isPresent() ? data.toData() : null;
    }
}
