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