1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.tikv.common.util;
19
20 import com.google.protobuf.ByteString;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import org.tikv.common.region.TiRegion;
25
26
27 public class Batch {
28 private final BackOffer backOffer;
29 private final TiRegion region;
30 private final List<ByteString> keys;
31 private final List<ByteString> values;
32 private final Map<ByteString, ByteString> map;
33
34 public Batch(BackOffer backOffer, TiRegion region, List<ByteString> keys) {
35 this.backOffer = ConcreteBackOffer.create(backOffer);
36 this.region = region;
37 this.keys = keys;
38 this.values = null;
39 this.map = null;
40 }
41
42 public Batch(
43 BackOffer backOffer, TiRegion region, List<ByteString> keys, List<ByteString> values) {
44 this.backOffer = ConcreteBackOffer.create(backOffer);
45 this.region = region;
46 this.keys = keys;
47 this.values = values;
48 this.map = toMap(keys, values);
49 }
50
51 private Map<ByteString, ByteString> toMap(List<ByteString> keys, List<ByteString> values) {
52 assert keys.size() == values.size();
53 Map<ByteString, ByteString> kvMap = new HashMap<>();
54 for (int i = 0; i < keys.size(); i++) {
55 kvMap.put(keys.get(i), values.get(i));
56 }
57 return kvMap;
58 }
59
60 public BackOffer getBackOffer() {
61 return ConcreteBackOffer.create(backOffer);
62 }
63
64 public TiRegion getRegion() {
65 return region;
66 }
67
68 public List<ByteString> getKeys() {
69 return keys;
70 }
71
72 public List<ByteString> getValues() {
73 return values;
74 }
75
76 public Map<ByteString, ByteString> getMap() {
77 return map;
78 }
79 }