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,19 +47,15 @@ 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 );
59
-
60
- static IOContext defaultContext (FileOpenHint ... hints ) {
61
- return new DefaultIOContext (Constants .DEFAULT_READADVICE , hints );
62
- }
58
+ IOContext READONCE = new DefaultIOContext (Optional .of (ReadAdvice .SEQUENTIAL ));
63
59
64
60
/** Returns an {@link IOContext} for merging with the specified {@link MergeInfo} */
65
61
static IOContext merge (MergeInfo mergeInfo ) {
@@ -86,8 +82,13 @@ public FileOpenHint[] hints() {
86
82
}
87
83
88
84
@ Override
89
- public ReadAdvice readAdvice () {
90
- return ReadAdvice .SEQUENTIAL ;
85
+ public IOContext withHints (FileOpenHint ... hints ) {
86
+ return this ;
87
+ }
88
+
89
+ @ Override
90
+ public Optional <ReadAdvice > readAdvice () {
91
+ return Optional .of (ReadAdvice .SEQUENTIAL );
91
92
}
92
93
93
94
@ Override
@@ -122,8 +123,13 @@ public FileOpenHint[] hints() {
122
123
}
123
124
124
125
@ Override
125
- public ReadAdvice readAdvice () {
126
- return ReadAdvice .SEQUENTIAL ;
126
+ public IOContext withHints (FileOpenHint ... hints ) {
127
+ return this ;
128
+ }
129
+
130
+ @ Override
131
+ public Optional <ReadAdvice > readAdvice () {
132
+ return Optional .of (ReadAdvice .SEQUENTIAL );
127
133
}
128
134
129
135
@ Override
@@ -145,9 +151,12 @@ public IOContext withReadAdvice(ReadAdvice advice) {
145
151
/** Any hints on how the file will be opened */
146
152
FileOpenHint [] hints ();
147
153
154
+ /** Sets the hints on this IOContext, if it makes sense to do so for this specific context */
155
+ IOContext withHints (FileOpenHint ... hints );
156
+
148
157
/** Advice on the expected read access pattern */
149
158
@ Deprecated
150
- ReadAdvice readAdvice ();
159
+ Optional < ReadAdvice > readAdvice ();
151
160
152
161
/**
153
162
* Return an updated {@link IOContext} that has the provided {@link ReadAdvice}, if the provided
0 commit comments