59bcf30675ca3744e97e7e278f5747650ae8ff54
[jabaws.git] / webservices / compbio / data / msa / Category.java
1 /**\r
2  * Class that splits {@link Services} to categories. Services themselves have no\r
3  * knowledge which category they belongs to.\r
4  * \r
5  * This class is responsible for initialization of all the categories (done\r
6  * statically) and holds the category names as constrains.\r
7  * \r
8  * Two categories considered equals if their names are equals.\r
9  * \r
10  * @author pvtroshin\r
11  * @version 1.0 September 2011\r
12  */\r
13 \r
14 package compbio.data.msa;\r
15 \r
16 import java.util.HashSet;\r
17 import java.util.Set;\r
18 import java.util.TreeSet;\r
19 \r
20 import javax.xml.bind.annotation.XmlAccessType;\r
21 import javax.xml.bind.annotation.XmlAccessorType;\r
22 \r
23 import compbio.ws.client.Services;\r
24 \r
25 @XmlAccessorType(XmlAccessType.FIELD)\r
26 public class Category {\r
27         /*\r
28          * TODO refactor initialization and constrains into separate classes if\r
29          * further complexity is expected.\r
30          */\r
31 \r
32         /**\r
33          * All of the Category names\r
34          */\r
35         public static final String CATEGORY_ALIGNMENT = "Alignment";\r
36         public static final String CATEGORY_DISORDER = "Protein Disorder";\r
37         public static final String CATEGORY_CONSERVATION = "Conservation";\r
38         public static final String CATEGORY_PREDICTION = "Prediction";\r
39         \r
40         public String name;\r
41         Set<Services> services;\r
42 \r
43         private Category(String name, Set<Services> services) {\r
44                 this.name = name;\r
45                 this.services = services;\r
46         }\r
47 \r
48         private Category() {\r
49                 // Default constructor for JAXB\r
50         }\r
51 \r
52         public Set<Services> getServices() {\r
53                 return new TreeSet<Services>(services);\r
54         }\r
55 \r
56         public static Set<Category> getCategories() {\r
57                 return init();\r
58         }\r
59 \r
60         private static Set<Category> init() {\r
61                 Set<Services> align_services = new HashSet<Services>();\r
62                 align_services.add(Services.ClustalOWS);\r
63                 align_services.add(Services.ClustalWS);\r
64                 align_services.add(Services.MafftWS);\r
65                 align_services.add(Services.MuscleWS);\r
66                 align_services.add(Services.ProbconsWS);\r
67                 align_services.add(Services.TcoffeeWS);\r
68                 Category alignment = new Category(CATEGORY_ALIGNMENT, align_services);\r
69 \r
70                 Set<Services> disorder_services = new HashSet<Services>();\r
71                 disorder_services.add(Services.DisemblWS);\r
72                 disorder_services.add(Services.GlobPlotWS);\r
73                 disorder_services.add(Services.IUPredWS);\r
74                 disorder_services.add(Services.JronnWS);\r
75                 Category disorder = new Category(CATEGORY_DISORDER, disorder_services);\r
76 \r
77                 Set<Services> conservation_services = new HashSet<Services>();\r
78                 conservation_services.add(Services.AAConWS);\r
79                 Category conservation = new Category(CATEGORY_CONSERVATION, conservation_services);\r
80 \r
81                 Set<Services> prediction_services = new HashSet<Services>();\r
82                 prediction_services.add(Services.JpredWS);\r
83                 Category prediction = new Category(CATEGORY_PREDICTION, prediction_services);\r
84 \r
85                 Set<Category> categories = new HashSet<Category>();\r
86                 categories.add(alignment);\r
87                 categories.add(disorder);\r
88                 categories.add(conservation);\r
89                 categories.add(prediction);\r
90 \r
91                 return categories;\r
92         }\r
93 \r
94         @Override\r
95         public int hashCode() {\r
96                 final int prime = 31;\r
97                 int result = 1;\r
98                 result = prime * result + ((name == null) ? 0 : name.hashCode());\r
99                 return result;\r
100         }\r
101 \r
102         @Override\r
103         public boolean equals(Object obj) {\r
104                 if (this == obj)\r
105                         return true;\r
106                 if (obj == null)\r
107                         return false;\r
108                 if (getClass() != obj.getClass())\r
109                         return false;\r
110                 Category other = (Category) obj;\r
111                 if (name == null) {\r
112                         if (other.name != null)\r
113                                 return false;\r
114                 } else if (!name.equals(other.name))\r
115                         return false;\r
116                 return true;\r
117         }\r
118 \r
119 }\r