1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph.observe;
25
26 import java.io.Serializable;
27 import java.util.Collections;
28 import java.util.List;
29 import net.jcip.annotations.Immutable;
30 import org.modeshape.graph.ExecutionContext;
31 import org.modeshape.graph.SecurityContext;
32 import org.modeshape.graph.property.DateTime;
33 import org.modeshape.graph.request.ChangeRequest;
34
35
36
37
38 @Immutable
39 public class Changes implements Comparable<Changes>, Serializable {
40
41 private static final long serialVersionUID = 1L;
42
43 protected final String processId;
44 protected final String contextId;
45 protected final String userName;
46 protected final String sourceName;
47 protected final DateTime timestamp;
48 protected final List<ChangeRequest> changeRequests;
49
50 public Changes( String processId,
51 String contextId,
52 String userName,
53 String sourceName,
54 DateTime timestamp,
55 List<ChangeRequest> requests ) {
56 assert requests != null;
57 assert !requests.isEmpty();
58 this.userName = userName;
59 this.sourceName = sourceName;
60 this.timestamp = timestamp;
61 this.changeRequests = Collections.unmodifiableList(requests);
62 this.processId = processId != null ? processId : "";
63 this.contextId = contextId != null ? contextId : "";
64 assert this.userName != null;
65 assert this.sourceName != null;
66 assert this.timestamp != null;
67 assert this.changeRequests != null;
68 assert this.processId != null;
69 }
70
71 protected Changes( Changes changes ) {
72 this.userName = changes.userName;
73 this.sourceName = changes.sourceName;
74 this.timestamp = changes.timestamp;
75 this.changeRequests = changes.changeRequests;
76 this.processId = changes.processId;
77 this.contextId = changes.contextId;
78 assert this.userName != null;
79 assert this.sourceName != null;
80 assert this.timestamp != null;
81 assert this.changeRequests != null;
82 assert this.processId != null;
83 assert this.contextId != null;
84 }
85
86
87
88
89
90
91
92 public String getUserName() {
93 return this.userName;
94 }
95
96
97
98
99
100
101 public String getSourceName() {
102 return this.sourceName;
103 }
104
105
106
107
108
109
110 public DateTime getTimestamp() {
111 return this.timestamp;
112 }
113
114
115
116
117
118
119 public String getProcessId() {
120 return processId;
121 }
122
123
124
125
126
127
128
129 public String getContextId() {
130 return contextId;
131 }
132
133
134
135
136
137
138 public List<ChangeRequest> getChangeRequests() {
139 return changeRequests;
140 }
141
142
143
144
145
146
147 @Override
148 public int hashCode() {
149 return getTimestamp().hashCode();
150 }
151
152
153
154
155
156
157 public int compareTo( Changes that ) {
158 if (this == that) return 0;
159 return this.getTimestamp().compareTo(that.getTimestamp());
160 }
161
162
163
164
165
166
167 @Override
168 public boolean equals( Object obj ) {
169 if (obj == this) return true;
170 if (obj instanceof Changes) {
171 Changes that = (Changes)obj;
172 if (!this.getProcessId().equals(that.getProcessId())) return false;
173 if (!this.getContextId().equals(that.getContextId())) return false;
174 if (!this.getSourceName().equals(that.getSourceName())) return false;
175 if (!this.getTimestamp().equals(that.getTimestamp())) return false;
176 if (!this.getUserName().equals(that.getUserName())) return false;
177 return true;
178 }
179 return false;
180 }
181
182
183
184
185
186
187 @Override
188 public String toString() {
189 if (processId.length() != 0) {
190 return getTimestamp() + " @" + getUserName() + " [" + getSourceName() + "] - " + changeRequests.size() + " events";
191 }
192 return getTimestamp() + " @" + getUserName() + " #" + getProcessId() + " [" + getSourceName() + "] - "
193 + changeRequests.size() + " events";
194 }
195 }