summaryrefslogtreecommitdiff
path: root/src/main/java/testing/LogEntry.java
blob: 6bb2ac7eaa0b0f5383f7bd55959b9f25b61e1e74 (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
package testing;

/**
 * Represents a single log entry captured during simulation execution.
 * Immutable data class for thread-safe log collection.
 */
public class LogEntry {
    private final long timestamp;
    private final String message;
    private final LogType type;
    private final int processNum;
    
    public LogEntry(long timestamp, String message, LogType type, int processNum) {
        this.timestamp = timestamp;
        this.message = message;
        this.type = type;
        this.processNum = processNum;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    public String getMessage() {
        return message;
    }
    
    public LogType getType() {
        return type;
    }
    
    public int getProcessNum() {
        return processNum;
    }
    
    public boolean isFromProcess(int processNum) {
        return this.processNum == processNum;
    }
    
    public boolean isGlobal() {
        return type == LogType.GLOBAL;
    }
    
    @Override
    public String toString() {
        if (type == LogType.PROCESS) {
            return String.format("[%d] Process %d: %s", timestamp, processNum, message);
        } else {
            return String.format("[%d] %s", timestamp, message);
        }
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        
        LogEntry logEntry = (LogEntry) o;
        return timestamp == logEntry.timestamp &&
               processNum == logEntry.processNum &&
               type == logEntry.type &&
               message.equals(logEntry.message);
    }
    
    @Override
    public int hashCode() {
        int result = Long.hashCode(timestamp);
        result = 31 * result + message.hashCode();
        result = 31 * result + type.hashCode();
        result = 31 * result + processNum;
        return result;
    }
}