HBASE-24163 MOB compactor implementations should use format specifiers when calling...
[hbase.git] / hbase-common / src / main / java / org / apache / hadoop / hbase / util / Order.java
blob9d864ce6cfc2f0669a46a3e8a2dfcb6d98a2b18a
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 * Used to describe or modify the lexicographical sort order of a
24 * {@code byte[]}. Default ordering is considered {@code ASCENDING}. The order
25 * of a {@code byte[]} can be inverted, resulting in {@code DESCENDING} order,
26 * by replacing each byte with its 1's compliment.
28 @InterfaceAudience.Public
29 public enum Order {
30 ASCENDING {
31 @Override
32 public int cmp(int cmp) {
33 /* noop */ return cmp;
36 @Override
37 public byte apply(byte val) {
38 /* noop */ return val;
41 @Override
42 public void apply(byte[] val) {
43 /* noop */
46 @Override
47 public void apply(byte[] val, int offset, int length) {
48 /* noop */
51 @Override
52 public String toString() {
53 return "ASCENDING";
57 DESCENDING {
58 /**
59 * A {@code byte} value is inverted by taking its 1's Complement, achieved
60 * via {@code xor} with {@code 0xff}.
62 private static final byte MASK = (byte) 0xff;
64 @Override
65 public int cmp(int cmp) {
66 return -1 * cmp;
69 @Override
70 public byte apply(byte val) {
71 return (byte) (val ^ MASK);
74 @Override
75 public void apply(byte[] val) {
76 for (int i = 0; i < val.length; i++) {
77 val[i] ^= MASK;
81 @Override
82 public void apply(byte[] val, int offset, int length) {
83 for (int i = 0; i < length; i++) {
84 val[offset + i] ^= MASK;
88 @Override
89 public String toString() {
90 return "DESCENDING";
94 /**
95 * Returns the adjusted trichotomous value according to the ordering imposed by this
96 * {@code Order}.
98 public abstract int cmp(int cmp);
101 * Apply order to the byte {@code val}.
103 public abstract byte apply(byte val);
106 * Apply order to the byte array {@code val}.
108 public abstract void apply(byte[] val);
111 * Apply order to a range within the byte array {@code val}.
113 public abstract void apply(byte[] val, int offset, int length);