2 * BioJava development code
4 * This code may be freely distributed and modified under the
5 * terms of the GNU Lesser General Public Licence. This should
6 * be distributed with the code. If you do not have a copy,
9 * http://www.gnu.org/copyleft/lesser.html
11 * Copyright for this code is held jointly by the individual
12 * authors. These should be listed in @author doc comments.
14 * For more information on the BioJava project and its aims,
15 * or to join the biojava-l mailing list, visit the home page
18 * http://www.biojava.org/
20 * Created on 23.09.2004
21 * @author Andreas Prlic
26 package org.biojava.dasobert.feature ;
28 import java.util.Comparator ;
29 import java.util.Iterator;
30 import java.util.List;
33 /** a comparator to sort Features byt type
34 * @author Andreas Prlic
37 public class FeatureComparator
41 public FeatureComparator() {
44 public int compare(Object a, Object b) {
45 FeatureTrack x = (FeatureTrack) a;
46 FeatureTrack y = (FeatureTrack) b;
48 String typea = x.getType();
49 String typeb = y.getType();
51 if ( ! typea.equals(typeb))
52 return typea.compareTo(typeb);
54 List s1 = x.getSegments();
55 List s2 = y.getSegments();
57 Iterator iter1 = s1.iterator();
58 Iterator iter2 = s2.iterator();
60 while (iter1.hasNext()){
61 Segment seg1 = (Segment)iter1.next();
62 int start1 = seg1.getStart();
64 while (iter2.hasNext()){
65 Segment seg2 = (Segment)iter2.next();
66 int start2 = seg2.getStart();
68 if ( start1 < start2){
70 } if ( start1 > start2){