HBASE-24163 MOB compactor implementations should use format specifiers when calling...
[hbase.git] / hbase-common / src / main / java / org / apache / hadoop / hbase / util / SimpleByteRange.java
blob247a8d396f6f250504fca87d12289100b4cd06ba
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.util;
20 import org.apache.yetus.audience.InterfaceAudience;
22 /**
23 * A read only version of the {@link ByteRange}.
25 @InterfaceAudience.Public
26 public class SimpleByteRange extends AbstractByteRange {
27 public SimpleByteRange() {
30 public SimpleByteRange(int capacity) {
31 this(new byte[capacity]);
34 /**
35 * Create a new {@code ByteRange} over the provided {@code bytes}.
36 * @param bytes The array to wrap.
38 public SimpleByteRange(byte[] bytes) {
39 set(bytes);
42 /**
43 * Create a new {@code ByteRange} over the provided {@code bytes}.
44 * @param bytes The array to wrap.
45 * @param offset The offset into {@code bytes} considered the beginning
46 * of this range.
47 * @param length The length of this range.
49 public SimpleByteRange(byte[] bytes, int offset, int length) {
50 set(bytes, offset, length);
54 // methods for managing the backing array and range viewport
57 @Override
58 public ByteRange unset() {
59 throw new ReadOnlyByteRangeException();
62 @Override
63 public ByteRange set(int capacity) {
64 if (super.bytes != null) {
65 throw new ReadOnlyByteRangeException();
67 return super.set(capacity);
70 @Override
71 public ByteRange set(byte[] bytes) {
72 if (super.bytes != null) {
73 throw new ReadOnlyByteRangeException();
75 return super.set(bytes);
78 @Override
79 public ByteRange set(byte[] bytes, int offset, int length) {
80 if (super.bytes != null) {
81 throw new ReadOnlyByteRangeException();
83 return super.set(bytes, offset, length);
87 // methods for retrieving data
89 @Override
90 public ByteRange put(int index, byte val) {
91 throw new ReadOnlyByteRangeException();
94 @Override
95 public ByteRange put(int index, byte[] val) {
96 throw new ReadOnlyByteRangeException();
99 @Override
100 public ByteRange put(int index, byte[] val, int offset, int length) {
101 throw new ReadOnlyByteRangeException();
105 // methods for duplicating the current instance
108 @Override
109 public ByteRange shallowCopy() {
110 SimpleByteRange clone = new SimpleByteRange(bytes, offset, length);
111 if (isHashCached()) {
112 clone.hash = hash;
114 return clone;
117 @Override
118 public ByteRange shallowCopySubRange(int innerOffset, int copyLength) {
119 SimpleByteRange clone = new SimpleByteRange(bytes, offset + innerOffset,
120 copyLength);
121 if (isHashCached()) {
122 clone.hash = hash;
124 return clone;
127 @Override
128 public boolean equals(Object thatObject) {
129 if (thatObject == null){
130 return false;
132 if (this == thatObject) {
133 return true;
135 if (hashCode() != thatObject.hashCode()) {
136 return false;
138 if (!(thatObject instanceof SimpleByteRange)) {
139 return false;
141 SimpleByteRange that = (SimpleByteRange) thatObject;
142 return Bytes.equals(bytes, offset, length, that.bytes, that.offset, that.length);
145 @Override
146 public ByteRange deepCopy() {
147 SimpleByteRange clone = new SimpleByteRange(deepCopyToNewArray());
148 if (isHashCached()) {
149 clone.hash = hash;
151 return clone;
154 @Override
155 public ByteRange putInt(int index, int val) {
156 throw new ReadOnlyByteRangeException();
159 @Override
160 public ByteRange putLong(int index, long val) {
161 throw new ReadOnlyByteRangeException();
164 @Override
165 public ByteRange putShort(int index, short val) {
166 throw new ReadOnlyByteRangeException();
169 @Override
170 public int putVLong(int index, long val) {
171 throw new ReadOnlyByteRangeException();