29
29
import java .io .ObjectInputStream ;
30
30
import java .io .ObjectOutputStream ;
31
31
import java .io .Serializable ;
32
+ import java .util .Collections ;
33
+ import java .util .HashMap ;
34
+ import java .util .Map ;
32
35
33
36
/**
34
37
* Represents a serializable gathering of some top-level metadata concerning the
35
38
* operation of {@link IndexDatabase} -- and persisted therein too -- which are
36
39
* re-compared upon each indexing run since changes to them might require
37
40
* re-indexing particular files or in certain cases all files.
38
41
*/
39
- @ Deprecated
40
42
public final class IndexAnalysisSettings implements Serializable {
41
43
42
- private static final long serialVersionUID = 1005610724146719938L ;
44
+ private static final long serialVersionUID = 1172403004716059609L ;
43
45
44
46
private String projectName ;
45
47
@@ -57,6 +59,14 @@ public final class IndexAnalysisSettings implements Serializable {
57
59
*/
58
60
private Long analyzerGuruVersion ;
59
61
62
+ /**
63
+ * (nullable because otherwise custom de-serialization does not work, as a
64
+ * {@code final} initialized value may not actually happen because Java
65
+ * de-serialization circumvents normal construction.)
66
+ * @serial
67
+ */
68
+ private Map <String , Long > analyzersVersions = new HashMap <>();
69
+
60
70
/**
61
71
* Gets the project name to be used to distinguish different instances of
62
72
* {@link IndexAnalysisSettings} that might be returned by a Lucene
@@ -93,6 +103,32 @@ public void setAnalyzerGuruVersion(Long value) {
93
103
this .analyzerGuruVersion = value ;
94
104
}
95
105
106
+ /**
107
+ * Gets the version number for the specified file type name if it exists
108
+ * @return a defined value or {@code null} if unknown
109
+ */
110
+ public Long getAnalyzerVersion (String fileTypeName ) {
111
+ return analyzersVersions .get (fileTypeName );
112
+ }
113
+
114
+ /**
115
+ * Gets an unmodifiable view of the map of file type names to version
116
+ * numbers.
117
+ * @return a defined instance
118
+ */
119
+ public Map <String , Long > getAnalyzersVersions () {
120
+ return Collections .unmodifiableMap (analyzersVersions );
121
+ }
122
+
123
+ /**
124
+ * Replaces the contents of the instance's map with the {@code values}.
125
+ * @param values a defined instance
126
+ */
127
+ public void setAnalyzersVersions (Map <String , Long > values ) {
128
+ analyzersVersions .clear ();
129
+ analyzersVersions .putAll (values );
130
+ }
131
+
96
132
/**
97
133
* Creates a binary representation of this object.
98
134
* @return a byte array representing this object
@@ -137,6 +173,20 @@ private void readObject(ObjectInputStream in) throws ClassNotFoundException,
137
173
hasValue = in .readBoolean ();
138
174
long vlong = in .readLong ();
139
175
analyzerGuruVersion = hasValue ? vlong : null ;
176
+
177
+ /**
178
+ * De-serialization circumvents normal construction, so the following
179
+ * field could be null.
180
+ */
181
+ if (analyzersVersions == null ) {
182
+ analyzersVersions = new HashMap <>();
183
+ }
184
+ int analyzerCount = in .readInt ();
185
+ for (int i = 0 ; i < analyzerCount ; ++i ) {
186
+ vstring = in .readUTF ();
187
+ vlong = in .readLong ();
188
+ analyzersVersions .put (vstring , vlong );
189
+ }
140
190
}
141
191
142
192
private void writeObject (ObjectOutputStream out ) throws IOException {
@@ -148,5 +198,16 @@ private void writeObject(ObjectOutputStream out) throws IOException {
148
198
149
199
out .writeBoolean (analyzerGuruVersion != null ); // hasValue
150
200
out .writeLong (analyzerGuruVersion == null ? 0 : analyzerGuruVersion );
201
+
202
+ int analyzerCount = analyzersVersions .size ();
203
+ out .writeInt (analyzerCount );
204
+ for (Map .Entry <String , Long > entry : analyzersVersions .entrySet ()) {
205
+ out .writeUTF (entry .getKey ());
206
+ out .writeLong (entry .getValue ());
207
+ --analyzerCount ;
208
+ }
209
+ if (analyzerCount != 0 ) {
210
+ throw new IllegalStateException ("analyzersVersions were modified" );
211
+ }
151
212
}
152
213
}
0 commit comments