// Path: halvade/src/be/ugent/intec/halvade/hadoop/datatypes/GenomeSJ.java
// public class GenomeSJ implements WritableComparable<GenomeSJ> {
//     protected int type; // -2 = overhang length, -1 = sj string, 2 =  count per key region
//     protected int secondary_key;
// 
//     public void setOverhang(int overhang) {
//         this.type = -2;
//         this.secondary_key = overhang;
//     }
//     
//     public void parseSJString(String sjString, SAMSequenceDictionary dict) {
//         String columns[] = sjString.split("\t");
//         this.type = -1;
//         this.secondary_key = dict.getSequenceIndex(columns[0]);
//     }
//     
//     public void setRegion(int key, int pos) {
//         this.type = key;
//         this.secondary_key = pos;
//     }
//     
//     public int getType() {
//         return type;
//     }
//     public int getSecKey() {
//         return secondary_key;
//     }
//     
//     public GenomeSJ() {
//         this.type = 0;
//         this.secondary_key = -1;
//     }
//     
//     @Override
//     public void write(DataOutput d) throws IOException {
//         d.writeInt(type);
//         d.writeInt(secondary_key);
//     }
// 
//     @Override
//     public String toString() {
//         return "GenomeSJ{" + "1=" + type + ", 2=" + secondary_key + '}';
//     }
// 
//     
//     @Override
//     public void readFields(DataInput di) throws IOException {
//         type = di.readInt();
//         secondary_key = di.readInt();
//     }
// 
//     @Override
//     public int compareTo(GenomeSJ o) {
//         if(type == o.type) {
//             return secondary_key - o.secondary_key;
//         } else 
//             return type - o.type;
//     }
//     
// }


import be.ugent.intec.halvade.hadoop.datatypes.GenomeSJ;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;
/*
 * Copyright (C) 2014 ddecap
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package be.ugent.intec.halvade.hadoop.partitioners;


/**
 *
 * @author ddecap
 */
public class GenomeSJGroupingComparator extends WritableComparator {
    protected GenomeSJGroupingComparator() {
        super(GenomeSJ.class, true);
    }
    
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
// Path: halvade/src/be/ugent/intec/halvade/hadoop/datatypes/GenomeSJ.java
// public class GenomeSJ implements WritableComparable<GenomeSJ> {
//     protected int type; // -2 = overhang length, -1 = sj string, 2 =  count per key region
//     protected int secondary_key;
// 
//     public void setOverhang(int overhang) {
//         this.type = -2;
//         this.secondary_key = overhang;
//     }
//     
//     public void parseSJString(String sjString, SAMSequenceDictionary dict) {
//         String columns[] = sjString.split("\t");
//         this.type = -1;
//         this.secondary_key = dict.getSequenceIndex(columns[0]);
//     }
//     
//     public void setRegion(int key, int pos) {
//         this.type = key;
//         this.secondary_key = pos;
//     }
//     
//     public int getType() {
//         return type;
//     }
//     public int getSecKey() {
//         return secondary_key;
//     }
//     
//     public GenomeSJ() {
//         this.type = 0;
//         this.secondary_key = -1;
//     }
//     
//     @Override
//     public void write(DataOutput d) throws IOException {
//         d.writeInt(type);
//         d.writeInt(secondary_key);
//     }
// 
//     @Override
//     public String toString() {
//         return "GenomeSJ{" + "1=" + type + ", 2=" + secondary_key + '}';
//     }
// 
//     
//     @Override
//     public void readFields(DataInput di) throws IOException {
//         type = di.readInt();
//         secondary_key = di.readInt();
//     }
// 
//     @Override
//     public int compareTo(GenomeSJ o) {
//         if(type == o.type) {
//             return secondary_key - o.secondary_key;
//         } else 
//             return type - o.type;
//     }
//     
// }


// Path: halvade/src/be/ugent/intec/halvade/hadoop/partitioners/GenomeSJGroupingComparator.java
import be.ugent.intec.halvade.hadoop.datatypes.GenomeSJ;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/*
 * Copyright (C) 2014 ddecap
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package be.ugent.intec.halvade.hadoop.partitioners;


/**
 *
 * @author ddecap
 */
public class GenomeSJGroupingComparator extends WritableComparator {
    protected GenomeSJGroupingComparator() {
        super(GenomeSJ.class, true);
    }
    
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        GenomeSJ sj1 = (GenomeSJ) a;