| 1 |
package sort; |
| 2 |
|
| 3 |
import stream.Read; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
public final class ReadLengthComparator extends ReadComparator { |
| 12 |
|
| 13 |
private ReadLengthComparator(){} |
| 14 |
|
| 15 |
@Override |
| 16 |
public int compare(Read a, Read b) { |
| 17 |
int x=compareInner(a, b); |
| 18 |
if(x==0){x=compareInner(a.mate, b.mate);} |
| 19 |
if(x==0){x=a.id.compareTo(b.id);} |
| 20 |
if(x==0){x=a.numericID>b.numericID ? 1 : a.numericID<b.numericID ? -1 : 0;} |
| 21 |
return ascending*x; |
| 22 |
} |
| 23 |
|
| 24 |
private static int compareInner(Read a, Read b) { |
| 25 |
if(a==b){return 0;} |
| 26 |
if(a==null){return 1;} |
| 27 |
if(b==null){return -1;} |
| 28 |
int x=a.length()-b.length(); |
| 29 |
return x; |
| 30 |
} |
| 31 |
|
| 32 |
public static final ReadLengthComparator comparator=new ReadLengthComparator(); |
| 33 |
|
| 34 |
private int ascending=-1; |
| 35 |
|
| 36 |
@Override |
| 37 |
public void setAscending(boolean asc){ |
| 38 |
ascending=(asc ? 1 : -1); |
| 39 |
} |
| 40 |
|
| 41 |
} |