package main.doge.service;

import main.doge.service.domain.Todo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

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

@Service
public class TodoService {

    private final RestTemplate restTemplate;
    private final String uri;

    @Autowired
    public TodoService(RestTemplate restTemplate, @Value("${doge.service.uri}") String uri) {
        this.restTemplate = restTemplate;
        this.uri = uri;
    }

    public List<Todo> getTodos() {
        return Arrays.asList(callService(uri + "/todos", Todo[].class));
    }

    public Todo getSingleTodo(int todoId) {
        return callService(uri + "/todo/" + Integer.toString(todoId), Todo.class);
    }

    private <T> T callService(String uri, Class<T> type) {
        return restTemplate.getForObject(uri, type);
    }
}

@@ -328,16 +328,52 @@
 il.List;
+%0Aimport java.util.stream.Collectors;
 %0A%0A@Servi
@@ -722,14 +722,14 @@
 ays.
-asList
+stream
 (cal
@@ -767,16 +767,45 @@
 .class))
+.collect(Collectors.toList())
 ;%0A    %7D%0A

Refactor to use Java 8 stream