1 2 3 4 package net.nutch.io; 5 6 import java.io.*; 7 8 11 public class BooleanWritable implements WritableComparable { 12 private boolean value; 13 14 16 public BooleanWritable() {}; 17 18 20 public BooleanWritable(boolean value) { 21 set(value); 22 } 23 24 27 public void set(boolean value) { 28 this.value = value; 29 } 30 31 34 public boolean get() { 35 return value; 36 } 37 38 40 public void readFields(DataInput in) throws IOException { 41 value = in.readBoolean(); 42 } 43 44 46 public void write(DataOutput out) throws IOException { 47 out.writeBoolean(value); 48 } 49 50 52 public boolean equals(Object o) { 53 if (!(o instanceof BooleanWritable)) { 54 return false; 55 } 56 BooleanWritable other = (BooleanWritable) o; 57 return this.value == other.value; 58 } 59 60 62 public int compareTo(Object o) { 63 boolean a = this.value; 64 boolean b = ((BooleanWritable) o).value; 65 return ((a == b) ? 0 : (a == false) ? -1 : 1); 66 } 67 68 71 public static class Comparator extends WritableComparator { 72 public Comparator() { 73 super(BooleanWritable.class); 74 } 75 76 public int compare(byte[] b1, int s1, int l1, 77 byte[] b2, int s2, int l2) { 78 boolean a = (readInt(b1, s1) == 1) ? true : false; 79 boolean b = (readInt(b2, s2) == 1) ? true : false; 80 return ((a == b) ? 0 : (a == false) ? -1 : 1); 81 } 82 } 83 } 84 | Popular Tags |