p2pMapReduce.mapreduceModule.io
Interface WritableComparable<T>

All Superinterfaces:
java.lang.Comparable<T>, Writable
All Known Implementing Classes:
IntWritable, LongWritable, NullWritable, StringWritable

public interface WritableComparable<T>
extends Writable, java.lang.Comparable<T>

A Writable which is also Comparable.

WritableComparables can be compared to each other, typically via Comparators. Any type which is to be used as a key in the Hadoop Map-Reduce framework should implement this interface.

Example:

     public class MyWritableComparable implements
         WritableComparable<MyWritableComparable> {

       // Some data
       private int counter;
       private long timestamp;
       
       public void write(DataOutput out) throws IOException {
         out.writeInt(counter);
         out.writeLong(timestamp);
       }
       
       public void readFields(DataInput in) throws IOException {
         counter = in.readInt();
         timestamp = in.readLong();
       }
       
       public int compareTo(MyWritableComparable other) {
         int thisValue = this.counter;
         int thatValue = other.counter;
         return (thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1));
       }
     }
 


Method Summary
 
Methods inherited from interface p2pMapReduce.mapreduceModule.io.Writable
readFields, write
 
Methods inherited from interface java.lang.Comparable
compareTo