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
25 package org.biojava.dasobert.feature;
27 import java.util.Comparator;
28 import java.util.Iterator;
29 import java.util.List;
32 * a comparator to sort Features byt type
34 * @author Andreas Prlic
37 public class FeatureComparator implements Comparator
40 public FeatureComparator()
44 public int compare(Object a, Object b)
46 FeatureTrack x = (FeatureTrack) a;
47 FeatureTrack y = (FeatureTrack) b;
49 String typea = x.getType();
50 String typeb = y.getType();
52 if (!typea.equals(typeb))
53 return typea.compareTo(typeb);
55 List s1 = x.getSegments();
56 List s2 = y.getSegments();
58 Iterator iter1 = s1.iterator();
59 Iterator iter2 = s2.iterator();
61 while (iter1.hasNext())
63 Segment seg1 = (Segment) iter1.next();
64 int start1 = seg1.getStart();
66 while (iter2.hasNext())
68 Segment seg2 = (Segment) iter2.next();
69 int start2 = seg2.getStart();