1 2 3 4 package net.nutch.io; 5 6 import java.io.*; 7 8 9 public class LongWritable implements WritableComparable { 10 private long value; 11 12 public LongWritable() {} 13 14 public LongWritable(long value) { set(value); } 15 16 17 public void set(long value) { this.value = value; } 18 19 20 public long get() { return value; } 21 22 public void readFields(DataInput in) throws IOException { 23 value = in.readLong(); 24 } 25 26 public void write(DataOutput out) throws IOException { 27 out.writeLong(value); 28 } 29 30 31 public boolean equals(Object o) { 32 if (!(o instanceof LongWritable)) 33 return false; 34 LongWritable other = (LongWritable)o; 35 return this.value == other.value; 36 } 37 38 public int hashCode() { 39 return (int)value; 40 } 41 42 43 public int compareTo(Object o) { 44 long thisValue = this.value; 45 long thatValue = ((LongWritable)o).value; 46 return (thisValue<thatValue ? -1 : (thisValue==thatValue ? 0 : 1)); 47 } 48 49 public String toString() { 50 return Long.toString(value); 51 } 52 53 54 public static class Comparator extends WritableComparator { 55 public Comparator() { 56 super(LongWritable.class); 57 } 58 59 public int compare(byte[] b1, int s1, int l1, 60 byte[] b2, int s2, int l2) { 61 long thisValue = readLong(b1, s1); 62 long thatValue = readLong(b2, s2); 63 return (thisValue<thatValue ? -1 : (thisValue==thatValue ? 0 : 1)); 64 } 65 } 66 67 } 68 69 | Popular Tags |