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