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
;
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
32 public int cmp(int cmp
) {
33 /* noop */ return cmp
;
37 public byte apply(byte val
) {
38 /* noop */ return val
;
42 public void apply(byte[] val
) {
47 public void apply(byte[] val
, int offset
, int length
) {
52 public String
toString() {
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;
65 public int cmp(int cmp
) {
70 public byte apply(byte val
) {
71 return (byte) (val ^ MASK
);
75 public void apply(byte[] val
) {
76 for (int i
= 0; i
< val
.length
; i
++) {
82 public void apply(byte[] val
, int offset
, int length
) {
83 for (int i
= 0; i
< length
; i
++) {
84 val
[offset
+ i
] ^
= MASK
;
89 public String
toString() {
95 * Returns the adjusted trichotomous value according to the ordering imposed by this
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
);