View Javadoc
1   /*
2    * Copyright 2021 TiKV Project Authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  
18  package org.tikv.common.util;
19  
20  import com.google.protobuf.ByteString;
21  
22  /** if Limit of a ScanBatch is 0, it means to scan all keys in */
23  public class ScanOption {
24    private final ByteString startKey;
25    private final ByteString endKey;
26    private final int limit;
27    private final boolean keyOnly;
28  
29    private ScanOption(ByteString startKey, ByteString endKey, int limit, boolean keyOnly) {
30      this.startKey = startKey;
31      this.endKey = endKey;
32      this.limit = limit;
33      this.keyOnly = keyOnly;
34    }
35  
36    public static ScanOptionBuilder newBuilder() {
37      return new ScanOptionBuilder();
38    }
39  
40    public ByteString getStartKey() {
41      return startKey;
42    }
43  
44    public ByteString getEndKey() {
45      return endKey;
46    }
47  
48    public int getLimit() {
49      return limit;
50    }
51  
52    public boolean isKeyOnly() {
53      return keyOnly;
54    }
55  
56    public static class ScanOptionBuilder {
57      private ByteString startKey;
58      private ByteString endKey;
59      private int limit;
60      private boolean keyOnly;
61  
62      private ScanOptionBuilder() {
63        this.startKey = ByteString.EMPTY;
64        this.endKey = ByteString.EMPTY;
65        this.limit = 0;
66        this.keyOnly = false;
67      }
68  
69      public ScanOption build() {
70        return new ScanOption(startKey, endKey, limit, keyOnly);
71      }
72  
73      public ScanOptionBuilder setStartKey(ByteString startKey) {
74        this.startKey = startKey;
75        return this;
76      }
77  
78      public ScanOptionBuilder setEndKey(ByteString endKey) {
79        this.endKey = endKey;
80        return this;
81      }
82  
83      public ScanOptionBuilder setLimit(int limit) {
84        this.limit = limit;
85        return this;
86      }
87  
88      public ScanOptionBuilder setKeyOnly(boolean keyOnly) {
89        this.keyOnly = keyOnly;
90        return this;
91      }
92    }
93  }