package cn.axzo.msg.center.dal;

import cn.axzo.msg.center.domain.entity.Todo;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;

/**
 * @author yanglin
 */
public class SampleTodos {

    private final Map<Long, Todo> businessId2Todo;

    SampleTodos(List<Todo> todos) {
        this.businessId2Todo = todos.stream()
                .collect(toMap(Todo::getTodoBusinessId, identity()));
    }

    public Optional<Todo> findSample(Long businessId) {
        return Optional.ofNullable(businessId2Todo.get(businessId));
    }
}
