[120] | 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 |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 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. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | package org.apache.hadoop.io; |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * A {@link Writable} which is also {@link Comparable}. |
---|
| 23 | * |
---|
| 24 | * <p><code>WritableComparable</code>s can be compared to each other, typically |
---|
| 25 | * via <code>Comparator</code>s. Any type which is to be used as a |
---|
| 26 | * <code>key</code> in the Hadoop Map-Reduce framework should implement this |
---|
| 27 | * interface.</p> |
---|
| 28 | * |
---|
| 29 | * <p>Example:</p> |
---|
| 30 | * <p><blockquote><pre> |
---|
| 31 | * public class MyWritableComparable implements WritableComparable { |
---|
| 32 | * // Some data |
---|
| 33 | * private int counter; |
---|
| 34 | * private long timestamp; |
---|
| 35 | * |
---|
| 36 | * public void write(DataOutput out) throws IOException { |
---|
| 37 | * out.writeInt(counter); |
---|
| 38 | * out.writeLong(timestamp); |
---|
| 39 | * } |
---|
| 40 | * |
---|
| 41 | * public void readFields(DataInput in) throws IOException { |
---|
| 42 | * counter = in.readInt(); |
---|
| 43 | * timestamp = in.readLong(); |
---|
| 44 | * } |
---|
| 45 | * |
---|
| 46 | * public int compareTo(MyWritableComparable w) { |
---|
| 47 | * int thisValue = this.value; |
---|
| 48 | * int thatValue = ((IntWritable)o).value; |
---|
| 49 | * return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0 : 1)); |
---|
| 50 | * } |
---|
| 51 | * } |
---|
| 52 | * </pre></blockquote></p> |
---|
| 53 | */ |
---|
| 54 | public interface WritableComparable<T> extends Writable, Comparable<T> { |
---|
| 55 | } |
---|