001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver.querymatcher; 019 020import org.apache.yetus.audience.InterfaceAudience; 021 022/** 023 * Simple wrapper for a byte buffer and a counter. Does not copy. 024 * <p> 025 * NOT thread-safe because it is not used in a multi-threaded context, yet. 026 */ 027@InterfaceAudience.Private 028class ColumnCount { 029 private final byte[] bytes; 030 private final int offset; 031 private final int length; 032 private int count; 033 034 /** 035 * Constructor 036 * @param column the qualifier to count the versions for 037 */ 038 public ColumnCount(byte[] column) { 039 this(column, 0); 040 } 041 042 /** 043 * Constructor 044 * @param column the qualifier to count the versions for 045 * @param count initial count 046 */ 047 public ColumnCount(byte[] column, int count) { 048 this(column, 0, column.length, count); 049 } 050 051 /** 052 * Constuctor 053 * @param column the qualifier to count the versions for 054 * @param offset in the passed buffer where to start the qualifier from 055 * @param length of the qualifier 056 * @param count initial count 057 */ 058 public ColumnCount(byte[] column, int offset, int length, int count) { 059 this.bytes = column; 060 this.offset = offset; 061 this.length = length; 062 this.count = count; 063 } 064 065 /** Returns the buffer */ 066 public byte[] getBuffer() { 067 return this.bytes; 068 } 069 070 /** Returns the offset */ 071 public int getOffset() { 072 return this.offset; 073 } 074 075 /** Returns the length */ 076 public int getLength() { 077 return this.length; 078 } 079 080 /** 081 * Decrement the current version count 082 * @return current count 083 */ 084 public int decrement() { 085 return --count; 086 } 087 088 /** 089 * Increment the current version count 090 * @return current count 091 */ 092 public int increment() { 093 return ++count; 094 } 095 096 /** 097 * Set the current count to a new count 098 * @param count new count to set 099 */ 100 public void setCount(int count) { 101 this.count = count; 102 } 103}