(JAL-1016) noted position where race condition occurs
[jalview.git] / src / org / biojava / dasobert / feature / FeatureMapComparator.java
1 /*
2  *                    BioJava development code
3  *
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,
7  * see:
8  *
9  *      http://www.gnu.org/copyleft/lesser.html
10  *
11  * Copyright for this code is held jointly by the individual
12  * authors.  These should be listed in @author doc comments.
13  *
14  * For more information on the BioJava project and its aims,
15  * or to join the biojava-l mailing list, visit the home page
16  * at:
17  *
18  *      http://www.biojava.org/
19  *
20  * Created on 23.09.2004
21  * @author Andreas Prlic
22  *
23  */
24
25 package org.biojava.dasobert.feature;
26
27 import java.util.Comparator;
28 import java.util.Map;
29
30 /**
31  * a comparator to sort Features if they are still in a Map ( sorts by type )
32  * 
33  * @author Andreas Prlic
34  */
35
36 public class FeatureMapComparator implements Comparator
37 {
38
39   public FeatureMapComparator()
40   {
41   }
42
43   public int compare(Object a, Object b)
44   {
45     Map x = (Map) a;
46     Map y = (Map) b;
47
48     String typea = (String) x.get("TYPE");
49     String typeb = (String) y.get("TYPE");
50
51     if (isSecstruc(typea) && isSecstruc(typeb))
52     {
53       return 0;
54     }
55     return typea.compareTo(typeb);
56   }
57
58   public boolean isSecstruc(String type)
59   {
60     if (type.equals("HELIX") || type.equals("STRAND")
61             || type.equals("TURN"))
62     {
63       return true;
64     }
65     return false;
66   }
67
68 }