-
Notifications
You must be signed in to change notification settings - Fork 121
/
KeyRangeType.java
172 lines (163 loc) · 5.27 KB
/
KeyRangeType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*-
* #%L
* LmdbJava
* %%
* Copyright (C) 2016 - 2017 The LmdbJava Open Source Project
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.lmdbjava;
/**
* Key range type.
*
* <p>
* The terminology used in this class is adapted from Google Guava's ranges.
* Refer to the <a href="https://github.com/google/guava/wiki/RangesExplained">
* Ranges Explained</a> wiki page for more information. LmddJava prepends either
* "FORWARD" or "BACKWARD" to denote the iterator order.
*
* <p>
* In the examples below, it is assumed the table has keys 2, 4, 6 and 8.
*/
public enum KeyRangeType {
/**
* Starting on the first key and iterate forward until no keys remain.
*
* <p>
* The "start" and "stop" values are ignored.
*
* <p>
* In our example, the returned keys would be 2, 4, 6 and 8.
*/
FORWARD_ALL(true, false, false),
/**
* Start on the passed key (or the first key immediately after it) and
* iterate forward until no keys remain.
*
* <p>
* The "start" value is required. The "stop" value is ignored.
*
* <p>
* In our example and with a passed search key of 5, the returned keys would
* be 6 and 8. With a passed key of 6, the returned keys would be 6 and 8.
*/
FORWARD_AT_LEAST(true, true, false),
/**
* Start on the first key and iterate forward until a key equal to it (or the
* first key immediately after it) is reached.
*
* <p>
* The "stop" value is required. The "start" value is ignored.
*
* <p>
* In our example and with a passed search key of 5, the returned keys would
* be 2 and 4. With a passed key of 6, the returned keys would be 2, 4 and 6.
*/
FORWARD_AT_MOST(true, false, true),
/**
* Iterate forward between the passed keys, matching on the first keys
* directly equal to the passed key (or immediately following it in the case
* of the "start" key, or immediately preceding it in the case of the "stop"
* key).
*
* <p>
* The "start" and "stop" values are both required.
*
* <p>
* In our example and with a passed search range of 3 - 7, the returned keys
* would be 4 and 6. With a range of 2 - 6, the keys would be 2, 4 and 6.
*/
FORWARD_CLOSED(true, true, true),
/**
* Start on the last key and iterate backward until no keys remain.
*
* <p>
* The "start" and "stop" values are ignored.
*
* <p>
* In our example, the returned keys would be 8, 6, 4 and 2.
*/
BACKWARD_ALL(false, false, false),
/**
* Start on the passed key (or the first key immediately preceding it) and
* iterate backward until no keys remain.
*
* <p>
* The "start" value is required. The "stop" value is ignored.
*
* <p>
* In our example and with a passed search key of 5, the returned keys would
* be 4 and 2. With a passed key of 6, the returned keys would be 6, 4 and 2.
*/
BACKWARD_AT_LEAST(false, true, false),
/**
* Start on the last key and iterate backward until a key equal to it (or the
* first key immediately preceding it it) is reached.
*
* <p>
* The "stop" value is required. The "start" value is ignored.
*
* <p>
* In our example and with a passed search key of 5, the returned keys would
* be 8 and 6. With a passed key of 6, the returned keys would be 8 and 6.
*/
BACKWARD_AT_MOST(false, false, true),
/**
* Iterate backward between the passed keys, matching on the first keys
* directly equal to the passed key (or immediately preceding it in the case
* of the "start" key, or immediately following it in the case of the "stop"
* key).
*
* <p>
* The "start" and "stop" values are both required.
*
* <p>
* In our example and with a passed search range of 7 - 3, the returned keys
* would be 6 and 4. With a range of 6 - 2, the keys would be 6, 4 and 2.
*/
BACKWARD_CLOSED(false, true, true);
private final boolean directionForward;
private final boolean startKeyRequired;
private final boolean stopKeyRequired;
KeyRangeType(final boolean directionForward, final boolean startKeyRequired,
final boolean stopKeyRequired) {
this.directionForward = directionForward;
this.startKeyRequired = startKeyRequired;
this.stopKeyRequired = stopKeyRequired;
}
/**
* Whether the key space is iterated in the order provided by LMDB.
*
* @return true if forward, false if reverse
*/
public boolean isDirectionForward() {
return directionForward;
}
/**
* Whether the iteration requires a "start" key.
*
* @return true if start key must be non-null
*/
public boolean isStartKeyRequired() {
return startKeyRequired;
}
/**
* Whether the iteration requires a "stop" key.
*
* @return true if stop key must be non-null
*/
public boolean isStopKeyRequired() {
return stopKeyRequired;
}
}