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