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.meta;
19  
20  import com.fasterxml.jackson.annotation.JsonCreator;
21  import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
22  import com.fasterxml.jackson.annotation.JsonProperty;
23  import com.google.common.annotations.VisibleForTesting;
24  import com.google.common.collect.ImmutableList;
25  import java.io.Serializable;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  @JsonIgnoreProperties(ignoreUnknown = true)
30  public class TiPartitionDef implements Serializable {
31    private final long id;
32    private final String name;
33    private final List<String> lessThan;
34    private final String comment;
35  
36    @VisibleForTesting
37    @JsonCreator
38    public TiPartitionDef(
39        @JsonProperty("id") long id,
40        @JsonProperty("name") org.tikv.common.meta.CIStr name,
41        @JsonProperty("less_than") List<String> lessThan,
42        @JsonProperty("comment") String comment) {
43      this.id = id;
44      this.name = name.getL();
45      if (lessThan == null || lessThan.isEmpty()) {
46        this.lessThan = new ArrayList<>();
47      } else {
48        this.lessThan = ImmutableList.copyOf(lessThan);
49      }
50      this.comment = comment;
51    }
52  
53    public long getId() {
54      return id;
55    }
56  
57    public String getName() {
58      return name;
59    }
60  
61    public List<String> getLessThan() {
62      return lessThan;
63    }
64  }