summaryrefslogtreecommitdiff
path: root/src/main/java/testing/SimulationResult.java
blob: 4cab8ee10191ba71601ea915fadd851b1a3009d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package testing;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Contains the results of a headless simulation run, including
 * captured logs and execution metrics.
 */
public class SimulationResult {
    private final List<LogEntry> allLogs;
    private final Map<Integer, List<LogEntry>> processLogs;
    private final SimulationMetrics metrics;
    
    public SimulationResult(List<LogEntry> allLogs, 
                           Map<Integer, List<LogEntry>> processLogs,
                           SimulationMetrics metrics) {
        this.allLogs = Collections.unmodifiableList(allLogs);
        this.processLogs = Collections.unmodifiableMap(processLogs);
        this.metrics = metrics;
    }
    
    public List<LogEntry> getAllLogs() {
        return allLogs;
    }
    
    public List<LogEntry> getLogsForProcess(int processNum) {
        return processLogs.getOrDefault(processNum, Collections.emptyList());
    }
    
    public Map<Integer, List<LogEntry>> getProcessLogs() {
        return processLogs;
    }
    
    public SimulationMetrics getMetrics() {
        return metrics;
    }
    
    /**
     * Count logs matching a pattern
     */
    public int countLogs(String pattern) {
        return (int) allLogs.stream()
            .filter(log -> log.getMessage().contains(pattern))
            .count();
    }
    
    /**
     * Find first log matching pattern
     */
    public Optional<LogEntry> findFirst(String pattern) {
        return allLogs.stream()
            .filter(log -> log.getMessage().contains(pattern))
            .findFirst();
    }
    
    /**
     * Find all logs matching pattern
     */
    public List<LogEntry> findAll(String pattern) {
        return allLogs.stream()
            .filter(log -> log.getMessage().contains(pattern))
            .collect(Collectors.toList());
    }
    
    /**
     * Get logs in time range
     */
    public List<LogEntry> getLogsInTimeRange(long startTime, long endTime) {
        return allLogs.stream()
            .filter(log -> log.getTimestamp() >= startTime && 
                          log.getTimestamp() <= endTime)
            .collect(Collectors.toList());
    }
    
    /**
     * Generate summary report
     */
    public String generateSummary() {
        StringBuilder sb = new StringBuilder();
        sb.append("=== Simulation Result Summary ===\n");
        sb.append("Total logs: ").append(allLogs.size()).append("\n");
        sb.append("Processes: ").append(metrics.getNumProcesses()).append("\n");
        sb.append("\nLogs per process:\n");
        
        for (Map.Entry<Integer, Integer> entry : 
             metrics.getProcessMessageCounts().entrySet()) {
            sb.append("  Process ").append(entry.getKey())
              .append(": ").append(entry.getValue()).append(" logs\n");
        }
        
        return sb.toString();
    }
}