View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  
23  /**
24   * Simple wrapper for a byte buffer and a counter.  Does not copy.
25   * <p>
26   * NOT thread-safe because it is not used in a multi-threaded context, yet.
27   */
28  @InterfaceAudience.Private
29  public class ColumnCount {
30    private final byte [] bytes;
31    private final int offset;
32    private final int length;
33    private int count;
34  
35    /**
36     * Constructor
37     * @param column the qualifier to count the versions for
38     */
39    public ColumnCount(byte [] column) {
40      this(column, 0);
41    }
42  
43    /**
44     * Constructor
45     * @param column the qualifier to count the versions for
46     * @param count initial count
47     */
48    public ColumnCount(byte [] column, int count) {
49      this(column, 0, column.length, count);
50    }
51  
52    /**
53     * Constuctor
54     * @param column the qualifier to count the versions for
55     * @param offset in the passed buffer where to start the qualifier from
56     * @param length of the qualifier
57     * @param count initial count
58     */
59    public ColumnCount(byte [] column, int offset, int length, int count) {
60      this.bytes = column;
61      this.offset = offset;
62      this.length = length;
63      this.count = count;
64    }
65  
66    /**
67     * @return the buffer
68     */
69    public byte [] getBuffer(){
70      return this.bytes;
71    }
72  
73    /**
74     * @return the offset
75     */
76    public int getOffset(){
77      return this.offset;
78    }
79  
80    /**
81     * @return the length
82     */
83    public int getLength(){
84      return this.length;
85    }
86  
87    /**
88     * Decrement the current version count
89     * @return current count
90     */
91    public int decrement() {
92      return --count;
93    }
94  
95    /**
96     * Increment the current version count
97     * @return current count
98     */
99    public int increment() {
100     return ++count;
101   }
102 
103   /**
104    * Set the current count to a new count
105    * @param count new count to set
106    */
107   public void setCount(int count) {
108     this.count = count;
109   }
110 
111 }