1 // Originally based on an example from "Hadoop: The Definitive Guide" by Tom White.
2 // https://github.com/tomwhite/hadoop-book/blob/master/ch05-io/src/main/java/oldapi/TextPair.java
3 // Copyright (C) 2014 Tom White
5 // Adapted by Filip Darmanovic and Cem Okulmus
6 // Created as a template for Advanced Database Systems 2019
9 import org.apache.hadoop.io.*;
11 public class TextPair implements WritableComparable<TextPair> {
17 set(new Text(), new Text());
20 public TextPair(TextPair copy) {
21 set(new Text(copy.getFirst().toString()),
22 new Text(copy.getSecond().toString()));
25 public TextPair(String first, String second) {
26 set(new Text(first), new Text(second));
29 public TextPair(Text first, Text second) {
33 public void set(Text first, Text second) {
38 public void set(String first,String second){
39 set(new Text(first),new Text(second));
42 public Text getFirst() {
46 public Text getSecond() {
52 public void write(DataOutput out) throws IOException {
58 public void readFields(DataInput in) throws IOException {
60 second.readFields(in);
64 public int hashCode() {
65 return (1013 * first.hashCode()) ^ (1009 * second.hashCode()); // any large prime numbers should do
69 public boolean equals(Object o) {
70 if (o instanceof TextPair) {
71 TextPair tp = (TextPair) o;
72 return first.equals(tp.first) && second.equals(tp.second);
78 public String toString() {
79 return first + "," + second;
83 public int compareTo(TextPair tp) {
84 int cmp = first.compareTo(tp.first);
88 return second.compareTo(tp.second);