1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.classic.spi;
11
12 import java.io.Serializable;
13
14
15
16
17
18
19
20
21
22 public class ThrowableDataPoint implements Serializable {
23
24 private static final long serialVersionUID = -2891376879381358469L;
25
26 public enum ThrowableDataPointType {
27 RAW, STEP;
28 }
29
30 String rawString;
31 StackTraceElementProxy step;
32 final ThrowableDataPointType type;
33
34 public ThrowableDataPoint(String rawString) {
35 this.rawString = rawString;
36 this.type = ThrowableDataPointType.RAW;
37 }
38
39 public ThrowableDataPoint(StackTraceElement ste) {
40 this.step = new StackTraceElementProxy(ste);
41 this.type = ThrowableDataPointType.STEP;
42 }
43
44 public ThrowableDataPointType getType() {
45 return type;
46 }
47
48 public StackTraceElementProxy getStackTraceElementProxy() {
49 return step;
50 }
51
52 @Override
53 public String toString() {
54 switch (type) {
55 case RAW:
56 return rawString;
57 case STEP:
58 return step.getSTEAsString();
59 }
60 throw new IllegalStateException("Unreachable code");
61 }
62
63 @Override
64 public int hashCode() {
65 switch (type) {
66 case RAW:
67 return rawString.hashCode();
68 case STEP:
69 return step.hashCode();
70 }
71 throw new IllegalStateException("Unreachable code");
72 }
73
74 @Override
75 public boolean equals(Object obj) {
76 if (this == obj)
77 return true;
78 if (obj == null)
79 return false;
80 if (getClass() != obj.getClass())
81 return false;
82 final ThrowableDataPoint other = (ThrowableDataPoint) obj;
83
84 switch (type) {
85 case RAW:
86 if (rawString == null) {
87 if (other.rawString != null)
88 return false;
89 else
90 return true;
91 } else {
92 return rawString.equals(other.rawString);
93 }
94 case STEP:
95 return step.equals(other.step);
96 }
97 throw new IllegalStateException("Unreachable code");
98 }
99
100 }