Skip to content

Instantly share code, notes, and snippets.

@kzk
Created November 23, 2010 16:42
Show Gist options
  • Save kzk/712067 to your computer and use it in GitHub Desktop.
Save kzk/712067 to your computer and use it in GitHub Desktop.
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));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment