work on: add ability to perform GSDI in applets
[jalview.git] / forester / java / src / org / forester / go / BasicGoSubset.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.go;
27
28 public class BasicGoSubset implements GoSubset {
29
30     final Type _type;
31
32     public BasicGoSubset( final String s ) {
33         final String my_s = s.trim().toLowerCase();
34         if ( my_s.equals( GOSLIM_GENERIC_STR ) ) {
35             _type = Type.GOSLIM_GENERIC;
36         }
37         else if ( my_s.equals( GOSLIM_GOA_STR ) ) {
38             _type = Type.GOSLIM_GOA;
39         }
40         else if ( my_s.equals( GOSLIM_PIR_STR ) ) {
41             _type = Type.GOSLIM_PIR;
42         }
43         else if ( my_s.equals( GOSUBSET_PROK_STR ) ) {
44             _type = Type.GOSUBSET_PROK;
45         }
46         else if ( my_s.equals( GOSLIM_CANDIDA_STR ) ) {
47             _type = Type.GOSLIM_CANDIDA;
48         }
49         else if ( my_s.equals( GOSLIM_ASPERGILLUS_STR ) ) {
50             _type = Type.GOSLIM_ASPERGILLUS;
51         }
52         else if ( my_s.equals( GOSLIM_PLANT_STR ) ) {
53             _type = Type.GOSLIM_PLANT;
54         }
55         else if ( my_s.equals( GOSLIM_YEAST_STR ) ) {
56             _type = Type.GOSLIM_YEAST;
57         }
58         else if ( my_s.equals( GOSLIM_POMBE_STR ) ) {
59             _type = Type.GOSLIM_POMBE;
60         }
61         else if ( my_s.equals( HIGH_LEVEL_ANNOTATION_QC_STR ) ) {
62             _type = Type.HIGH_LEVEL_ANNOTATION_QC;
63         }
64         else if ( my_s.equals( UNVETTED_STR ) ) {
65             _type = Type.UNVETTED;
66         }
67         else if ( my_s.equals( MF_NEEDS_REVIEW_STR ) ) {
68             _type = Type.MF_NEEDS_REVIEW;
69         }
70         else {
71             throw new IllegalArgumentException( "unknown GO subset type: " + my_s );
72         }
73     }
74
75     public BasicGoSubset( final Type type ) {
76         _type = type;
77     }
78
79     @Override
80     public int compareTo( final GoSubset sub ) {
81         return getType().compareTo( sub.getType() );
82     }
83
84     @Override
85     public boolean equals( final Object o ) {
86         if ( this == o ) {
87             return true;
88         }
89         else if ( o == null ) {
90             throw new IllegalArgumentException( "attempt to check go subset equality to null" );
91         }
92         else if ( o.getClass() != this.getClass() ) {
93             throw new IllegalArgumentException( "attempt to check go subset equality to " + o + " [" + o.getClass()
94                     + "]" );
95         }
96         else {
97             return ( getType() == ( ( GoSubset ) o ).getType() );
98         }
99     }
100
101     @Override
102     public Type getType() {
103         return _type;
104     }
105
106     @Override
107     public String toString() {
108         final StringBuilder sb = new StringBuilder();
109         switch ( getType() ) {
110             case GOSLIM_CANDIDA:
111                 sb.append( GOSLIM_CANDIDA_STR );
112                 break;
113             case GOSLIM_GENERIC:
114                 sb.append( GOSLIM_GENERIC_STR );
115                 break;
116             case GOSLIM_GOA:
117                 sb.append( GOSLIM_GOA_STR );
118                 break;
119             case GOSLIM_PIR:
120                 sb.append( GOSLIM_PIR_STR );
121                 break;
122             case GOSLIM_PLANT:
123                 sb.append( GOSLIM_PLANT_STR );
124                 break;
125             case GOSLIM_ASPERGILLUS:
126                 sb.append( GOSLIM_ASPERGILLUS_STR );
127                 break;
128             case GOSLIM_YEAST:
129                 sb.append( GOSLIM_YEAST_STR );
130                 break;
131             case GOSUBSET_PROK:
132                 sb.append( GOSUBSET_PROK_STR );
133                 break;
134             case GOSLIM_POMBE:
135                 sb.append( GOSLIM_POMBE_STR );
136                 break;
137             case MF_NEEDS_REVIEW:
138                 sb.append( MF_NEEDS_REVIEW_STR );
139                 break;
140             case HIGH_LEVEL_ANNOTATION_QC:
141                 sb.append( HIGH_LEVEL_ANNOTATION_QC_STR );
142                 break;
143             case UNVETTED:
144                 sb.append( UNVETTED_STR );
145                 break;
146             default:
147                 new AssertionError( "unknown type: " + getType() );
148         }
149         return sb.toString();
150     }
151 }