I have a map reduce program that takes input as firstname, lastname and mobile number. I want to group these 3 fields as a single key. For this, I have used WritableComparable interface for a class.
My code is:
private static class Multifield implements WritableComparable<Multifield> {
        Text firstname1;
        Text lastname1;
        Text mobile1;
        public Multifield(Text firstname1, Text lastname1,Text mobile1) {
            this.firstname1 = firstname1;
            this.lastname1 = lastname1;
            this.mobile1=mobile1;
        }
        public Multifield() {
            this.firstname1 = new Text();
            this.lastname1 = new Text();
            this.mobile1=new Text();
        }
        public void write(DataOutput out) throws IOException {
            this.firstname1.write(out);
            this.lastname1.write(out);
            this.mobile1.write(out);
        }
        public void readFields(DataInput in) throws IOException {
            this.firstname1.readFields(in);
            this.lastname1.readFields(in);
            this.mobile1.readFields(in);
        }
        public int compareTo(Multifield pop) {
            if(firstname1.equals(pop.firstname1))
            {
                return lastname1.compareTo(pop.lastname1);
            }
            else
            {
                return firstname1.compareTo(pop.firstname1);
            }
        }
        @Override
        public String toString() {
            return "Customer Details [firstname=" + firstname1 + ", lastname=" + lastname1
                    + ", mobile=" + mobile1 + "]";
        }
The above coding just compares firstname and lastname. So, I get the output only based on the first two fields.
How can I modify the compareTo() method to compare all three fields, so that I can group them together as a key?