17
17
package org .apache .lucene .store ;
18
18
19
19
import java .util .Objects ;
20
- import org . apache . lucene . util .Constants ;
20
+ import java . util .Optional ;
21
21
22
22
/**
23
23
* IOContext holds additional details on the merge/search context. An IOContext object can never be
@@ -47,18 +47,49 @@ interface FileOpenHint {}
47
47
* <p>It will use {@link ReadAdvice#RANDOM} by default, unless set by system property {@code
48
48
* org.apache.lucene.store.defaultReadAdvice}.
49
49
*/
50
- IOContext DEFAULT = new DefaultIOContext (Constants . DEFAULT_READADVICE );
50
+ IOContext DEFAULT = new DefaultIOContext (Optional . empty () );
51
51
52
52
/**
53
53
* A default context for reads with {@link ReadAdvice#SEQUENTIAL}.
54
54
*
55
55
* <p>This context should only be used when the read operations will be performed in the same
56
56
* thread as the thread that opens the underlying storage.
57
57
*/
58
- IOContext READONCE = new DefaultIOContext (ReadAdvice .SEQUENTIAL );
58
+ IOContext READONCE = new DefaultIOContext (Optional . of ( ReadAdvice .SEQUENTIAL ) );
59
59
60
60
static IOContext defaultContext (FileOpenHint ... hints ) {
61
- return new DefaultIOContext (Constants .DEFAULT_READADVICE , hints );
61
+ Objects .requireNonNull (hints );
62
+ return new IOContext () {
63
+ @ Override
64
+ public Context context () {
65
+ return Context .DEFAULT ;
66
+ }
67
+
68
+ @ Override
69
+ public MergeInfo mergeInfo () {
70
+ return null ;
71
+ }
72
+
73
+ @ Override
74
+ public FlushInfo flushInfo () {
75
+ return null ;
76
+ }
77
+
78
+ @ Override
79
+ public FileOpenHint [] hints () {
80
+ return hints ;
81
+ }
82
+
83
+ @ Override
84
+ public Optional <ReadAdvice > readAdvice () {
85
+ return Optional .empty ();
86
+ }
87
+
88
+ @ Override
89
+ public IOContext withReadAdvice (ReadAdvice advice ) {
90
+ return this ;
91
+ }
92
+ };
62
93
}
63
94
64
95
/** Returns an {@link IOContext} for merging with the specified {@link MergeInfo} */
@@ -86,8 +117,8 @@ public FileOpenHint[] hints() {
86
117
}
87
118
88
119
@ Override
89
- public ReadAdvice readAdvice () {
90
- return ReadAdvice .SEQUENTIAL ;
120
+ public Optional < ReadAdvice > readAdvice () {
121
+ return Optional . of ( ReadAdvice .SEQUENTIAL ) ;
91
122
}
92
123
93
124
@ Override
@@ -122,8 +153,8 @@ public FileOpenHint[] hints() {
122
153
}
123
154
124
155
@ Override
125
- public ReadAdvice readAdvice () {
126
- return ReadAdvice .SEQUENTIAL ;
156
+ public Optional < ReadAdvice > readAdvice () {
157
+ return Optional . of ( ReadAdvice .SEQUENTIAL ) ;
127
158
}
128
159
129
160
@ Override
@@ -147,7 +178,7 @@ public IOContext withReadAdvice(ReadAdvice advice) {
147
178
148
179
/** Advice on the expected read access pattern */
149
180
@ Deprecated
150
- ReadAdvice readAdvice ();
181
+ Optional < ReadAdvice > readAdvice ();
151
182
152
183
/**
153
184
* Return an updated {@link IOContext} that has the provided {@link ReadAdvice}, if the provided
0 commit comments