clean up
[jalview.git] / forester / java / src / org / forester / go / GoNameSpace.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: www.phylosoft.org/forester
25
26 package org.forester.go;
27
28 public class GoNameSpace {
29
30     public final String           MOLECULAR_FUNCTION_STR = "molecular_function";
31     public final String           BIOLOGICAL_PROCESS_STR = "biological_process";
32     public final String           CELLULAR_COMPONENT_STR = "cellular_component";
33     public final String           UNASSIGNED_STR         = "unassigned";
34     private final GoNamespaceType _type;
35
36     public GoNameSpace( final GoNamespaceType type ) {
37         _type = type;
38     };
39
40     public GoNameSpace( final String type ) {
41         if ( type.toLowerCase().equals( MOLECULAR_FUNCTION_STR ) ) {
42             _type = GoNamespaceType.MOLECULAR_FUNCTION;
43         }
44         else if ( type.toLowerCase().equals( BIOLOGICAL_PROCESS_STR ) ) {
45             _type = GoNamespaceType.BIOLOGICAL_PROCESS;
46         }
47         else if ( type.toLowerCase().equals( CELLULAR_COMPONENT_STR ) ) {
48             _type = GoNamespaceType.CELLULAR_COMPONENT;
49         }
50         else if ( type.toLowerCase().equals( UNASSIGNED_STR ) ) {
51             _type = GoNamespaceType.UNASSIGNED;
52         }
53         else {
54             throw new IllegalArgumentException( "unknown GO namespace: " + type );
55         }
56     }
57
58     @Override
59     public boolean equals( final Object o ) {
60         if ( this == o ) {
61             return true;
62         }
63         else if ( ( o == null ) || ( o.getClass() != this.getClass() ) ) {
64             return false;
65         }
66         else {
67             return getType() == ( ( GoNameSpace ) o ).getType();
68         }
69     }
70
71     public GoNamespaceType getType() {
72         return _type;
73     }
74
75     public boolean isBiologicalProcess() {
76         return getType() == GoNamespaceType.BIOLOGICAL_PROCESS;
77     }
78
79     public boolean isCellularComponent() {
80         return getType() == GoNamespaceType.CELLULAR_COMPONENT;
81     }
82
83     public boolean isMolecularFunction() {
84         return getType() == GoNamespaceType.MOLECULAR_FUNCTION;
85     }
86
87     public boolean isUnassigned() {
88         return getType() == GoNamespaceType.UNASSIGNED;
89     }
90
91     public String toShortString() {
92         switch ( _type ) {
93             case BIOLOGICAL_PROCESS:
94                 return ( "B" );
95             case CELLULAR_COMPONENT:
96                 return ( "C" );
97             case MOLECULAR_FUNCTION:
98                 return ( "M" );
99             case UNASSIGNED:
100                 return ( "?" );
101             default:
102                 throw new RuntimeException();
103         }
104     }
105
106     @Override
107     public String toString() {
108         switch ( _type ) {
109             case BIOLOGICAL_PROCESS:
110                 return ( BIOLOGICAL_PROCESS_STR );
111             case CELLULAR_COMPONENT:
112                 return ( CELLULAR_COMPONENT_STR );
113             case MOLECULAR_FUNCTION:
114                 return ( MOLECULAR_FUNCTION_STR );
115             case UNASSIGNED:
116                 return ( UNASSIGNED_STR );
117             default:
118                 throw new RuntimeException();
119         }
120     }
121
122     public static GoNameSpace createBiologicalProcess() {
123         return new GoNameSpace( GoNamespaceType.BIOLOGICAL_PROCESS );
124     }
125
126     public static GoNameSpace createCellularComponent() {
127         return new GoNameSpace( GoNamespaceType.CELLULAR_COMPONENT );
128     }
129
130     public static GoNameSpace createMolecularFunction() {
131         return new GoNameSpace( GoNamespaceType.MOLECULAR_FUNCTION );
132     }
133
134     public static GoNameSpace createUnassigned() {
135         return new GoNameSpace( GoNamespaceType.UNASSIGNED );
136     }
137
138     public static enum GoNamespaceType {
139         MOLECULAR_FUNCTION, BIOLOGICAL_PROCESS, CELLULAR_COMPONENT, UNASSIGNED;
140     }
141 }