forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpanId.java
More file actions
60 lines (47 loc) · 1.42 KB
/
SpanId.java
File metadata and controls
60 lines (47 loc) · 1.42 KB
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
package io.sentry;
import io.sentry.util.Objects;
import java.io.IOException;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
public final class SpanId implements JsonSerializable {
public static final SpanId EMPTY_ID = new SpanId(new UUID(0, 0).toString());
private final @NotNull String value;
public SpanId(final @NotNull String value) {
this.value = Objects.requireNonNull(value, "value is required");
}
public SpanId() {
this(UUID.randomUUID());
}
private SpanId(final @NotNull UUID uuid) {
this(uuid.toString().replace("-", "").substring(0, 16));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SpanId spanId = (SpanId) o;
return value.equals(spanId.value);
}
@Override
public int hashCode() {
return value.hashCode();
}
@Override
public String toString() {
return this.value;
}
// JsonElementSerializer
@Override
public void serialize(@NotNull JsonObjectWriter writer, @NotNull ILogger logger)
throws IOException {
writer.value(value);
}
// JsonElementDeserializer
public static final class Deserializer implements JsonDeserializer<SpanId> {
@Override
public @NotNull SpanId deserialize(@NotNull JsonObjectReader reader, @NotNull ILogger logger)
throws Exception {
return new SpanId(reader.nextString());
}
}
}