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 java.io.Serializable;
24  import org.tikv.common.types.DataType;
25  
26  @JsonIgnoreProperties(ignoreUnknown = true)
27  public class TiIndexColumn implements Serializable {
28    private final String name;
29    private final int offset;
30    private final long length;
31  
32    @JsonCreator
33    public TiIndexColumn(
34        @JsonProperty("name") org.tikv.common.meta.CIStr name,
35        @JsonProperty("offset") int offset,
36        @JsonProperty("length") long length) {
37      this.name = name.getL();
38      this.offset = offset;
39      this.length = length;
40    }
41  
42    public String getName() {
43      return name;
44    }
45  
46    public int getOffset() {
47      return offset;
48    }
49  
50    public long getLength() {
51      return length;
52    }
53  
54    public boolean isLengthUnspecified() {
55      return DataType.isLengthUnSpecified(length);
56    }
57  
58    public boolean isPrefixIndex() {
59      return !isLengthUnspecified();
60    }
61  
62    public boolean matchName(String otherName) {
63      return name.equalsIgnoreCase(otherName);
64    }
65  
66    @Override
67    public String toString() {
68      return String.format(
69          "%s {name: %s, offset: %d, length: %d}", getClass().getSimpleName(), name, offset, length);
70    }
71  }