30
30
import com .sun .tools .visualvm .core .datasupport .Utils ;
31
31
import com .sun .tools .visualvm .core .ui .DataSourceWindowManager ;
32
32
import java .io .File ;
33
+ import java .util .Objects ;
33
34
34
35
/**
35
36
* Abstract implementation of Snapshot.
@@ -46,6 +47,8 @@ public abstract class Snapshot extends DataSource {
46
47
private File file ;
47
48
private final SnapshotCategory category ;
48
49
50
+ private String snapshotID ;
51
+
49
52
50
53
/**
51
54
* Creates new instance of AbstractSnapshot with the data stored in a file.
@@ -98,6 +101,7 @@ protected final void setFile(File newFile) {
98
101
if (file == null && newFile == null ) return ;
99
102
File oldFile = file ;
100
103
file = newFile ;
104
+ if (oldFile == null ) snapshotID = null ;
101
105
getChangeSupport ().firePropertyChange (PROPERTY_FILE , oldFile , newFile );
102
106
}
103
107
@@ -193,5 +197,34 @@ protected Storage createStorage() {
193
197
protected final boolean isInSnapshot () {
194
198
return getOwner () instanceof Snapshot ;
195
199
}
200
+
201
+
202
+ /**
203
+ * Returns ID of the Snapshot. The ID should be based on the snapshot file
204
+ * if available and will only be computed for the first non-null file.
205
+ *
206
+ * @return ID of the Snapshot
207
+ *
208
+ * @since VisualVM 1.4
209
+ */
210
+ protected String computeSnapshotID () {
211
+ File f = getFile ();
212
+ return f == null ? super .hashCode () + "-no_file" : f .getPath (); // NOI18N
213
+ }
214
+
215
+ private String getSnapshotID () {
216
+ if (snapshotID == null ) snapshotID = computeSnapshotID ();
217
+ return snapshotID ;
218
+ }
219
+
220
+
221
+ public boolean equals (Object o ) {
222
+ if (!(o instanceof Snapshot )) return false ;
223
+ return Objects .equals (getSnapshotID (), ((Snapshot )o ).getSnapshotID ());
224
+ }
225
+
226
+ public int hashCode () {
227
+ return Objects .hashCode (getSnapshotID ());
228
+ }
196
229
197
230
}
0 commit comments