001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with this
004 * work for additional information regarding copyright ownership. The ASF
005 * licenses this file to you under the Apache License, Version 2.0 (the
006 * "License"); you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 * License for the specific language governing permissions and limitations under
015 * the License.
016 */
017
018 package org.apache.hadoop.io.file.tfile;
019
020 import java.util.Collections;
021 import java.util.Comparator;
022
023 import org.apache.hadoop.classification.InterfaceAudience;
024 import org.apache.hadoop.classification.InterfaceStability;
025 import org.apache.hadoop.io.RawComparator;
026
027 /**
028 * Interface for objects that can be compared through {@link RawComparator}.
029 * This is useful in places where we need a single object reference to specify a
030 * range of bytes in a byte array, such as {@link Comparable} or
031 * {@link Collections#binarySearch(java.util.List, Object, Comparator)}
032 *
033 * The actual comparison among RawComparable's requires an external
034 * RawComparator and it is applications' responsibility to ensure two
035 * RawComparable are supposed to be semantically comparable with the same
036 * RawComparator.
037 */
038 @InterfaceAudience.Public
039 @InterfaceStability.Evolving
040 public interface RawComparable {
041 /**
042 * Get the underlying byte array.
043 *
044 * @return The underlying byte array.
045 */
046 abstract byte[] buffer();
047
048 /**
049 * Get the offset of the first byte in the byte array.
050 *
051 * @return The offset of the first byte in the byte array.
052 */
053 abstract int offset();
054
055 /**
056 * Get the size of the byte range in the byte array.
057 *
058 * @return The size of the byte range in the byte array.
059 */
060 abstract int size();
061 }