/
Journal.java
69 lines (56 loc) · 1.33 KB
/
Journal.java
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
/*
* Copyright (c) 2013, 2014 Chris Newland.
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki
*/
package org.adoptopenjdk.jitwatch.model;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_NEWLINE;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.adoptopenjdk.jitwatch.util.ParseUtil;
public class Journal
{
// writes dominate so not COWAL
private List<Tag> entryList;
public Journal()
{
entryList = new ArrayList<>();
}
public void addEntry(Tag entry)
{
synchronized (entryList)
{
entryList.add(entry);
}
}
public List<Tag> getEntryList()
{
synchronized (entryList)
{
List<Tag> copy = new ArrayList<>(entryList);
Collections.sort(copy, new Comparator<Tag>()
{
@Override
public int compare(Tag tag1, Tag tag2)
{
long ts1 = ParseUtil.getStamp(tag1.getAttrs());
long ts2 = ParseUtil.getStamp(tag2.getAttrs());
return Long.compare(ts1, ts2);
}
});
return copy;
}
}
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
for (Tag tag : getEntryList())
{
builder.append(tag.toString(true)).append(C_NEWLINE);
}
return builder.toString();
}
}