| 1 | package edu.ucsb.cs156.courses.services; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.courses.models.SystemMessage; | |
| 4 | import java.util.Collections; | |
| 5 | import java.util.List; | |
| 6 | import java.util.concurrent.CopyOnWriteArrayList; | |
| 7 | import org.springframework.stereotype.Service; | |
| 8 | ||
| 9 | /** | |
| 10 | * Holds system messages (e.g. startup misconfiguration warnings) for the lifetime of the running | |
| 11 | * process. Deliberately in-memory rather than persisted: a {@code @Service} bean is a Spring | |
| 12 | * singleton by default, so this naturally starts empty on every process start with no explicit | |
| 13 | * "clear on startup" step required, and -- should this app ever run multiple instances -- each | |
| 14 | * instance reports its own diagnostics rather than a shared table conflating them. | |
| 15 | */ | |
| 16 | @Service | |
| 17 | public class SystemMessagesService { | |
| 18 | ||
| 19 | private final List<SystemMessage> messages = new CopyOnWriteArrayList<>(); | |
| 20 | ||
| 21 | public void addMessage(String variant, String message) { | |
| 22 | messages.add(SystemMessage.builder().variant(variant).message(message).build()); | |
| 23 | } | |
| 24 | ||
| 25 | public List<SystemMessage> getMessages() { | |
| 26 |
1
1. getMessages : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/SystemMessagesService::getMessages → KILLED |
return Collections.unmodifiableList(messages); |
| 27 | } | |
| 28 | } | |
Mutations | ||
| 26 |
1.1 |