Applet is going more functions.
[jalview.git] / forester / java / src / org / forester / go / BasicGoXRef.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 BasicGoXRef implements GoXRef {
29
30     private final String _xref;
31     private final Type   _type;
32
33     public BasicGoXRef( final String s ) {
34         final String[] sa = s.split( ":" );
35         if ( sa.length < 2 ) {
36             throw new IllegalArgumentException( "unexpected format for GO xref: " + s );
37         }
38         final String type = sa[ 0 ].trim();
39         if ( type.equals( EC_STR ) ) {
40             _type = Type.EC;
41         }
42         else if ( type.equals( META_CYC_STR ) ) {
43             _type = Type.META_CYC;
44         }
45         else if ( type.equals( REACTOME_STR ) ) {
46             _type = Type.REACTOME;
47         }
48         else if ( type.equals( RESID_STR ) ) {
49             _type = Type.RESID;
50         }
51         else if ( type.equals( UM_BBD_ENZYME_ID_STR ) ) {
52             _type = Type.UM_BBD_ENZYME_ID;
53         }
54         else if ( type.equals( UM_BBD_PATHWAY_ID_STR ) ) {
55             _type = Type.UM_BBD_PATHWAY_ID;
56         }
57         else if ( type.equals( UM_BBD_REACTIONID_STR ) ) {
58             _type = Type.UM_BBD_REACTIONID;
59         }
60         else if ( type.equals( TC_STR ) ) {
61             _type = Type.TC;
62         }
63         else if ( type.equals( ARACYC_STR ) ) {
64             _type = Type.ARACYC;
65         }
66         else if ( type.equals( XX_STR ) ) {
67             _type = Type.XX;
68         }
69         else if ( type.equals( PMID_STR ) ) {
70             _type = Type.PMID;
71         }
72         else if ( type.equals( IMG_STR ) ) {
73             _type = Type.IMG;
74         }
75         else if ( type.equals( GOC_STR ) ) {
76             _type = Type.GOC;
77         }
78         else if ( type.equals( KEGG_STR ) ) {
79             _type = Type.KEGG;
80         }
81         else if ( type.equals( WIKIPEDIA_STR ) ) {
82             _type = Type.WIKIPEDIA;
83         }
84         else if ( type.equals( RHEA_STR ) ) {
85             _type = Type.RHEA;
86         }
87         else if ( type.equals( NIF_SUBCELLULAR_STR ) ) {
88             _type = Type.NIF_SUBCELLULAR;
89         }
90         else if ( type.equals( CORUM_STR ) ) {
91             _type = Type.CORUM;
92         }
93         else if ( type.equals( UNIPATHWAY_STR ) ) {
94             _type = Type.UNIPATHWAY;
95         }
96         else if ( type.equals( PO_STR ) ) {
97             _type = Type.PO;
98         }
99         else if ( type.equals( SABIO_RK_STR ) ) {
100             _type = Type.SABIO_RK;
101         }
102         else {
103             _type = Type.OTHER;
104         }
105         _xref = sa[ 1 ].trim();
106     }
107
108     public BasicGoXRef( final Type type, final String xref ) {
109         _type = type;
110         _xref = xref;
111     }
112
113     @Override
114     public int compareTo( final GoXRef xref ) {
115         return getXRef().compareTo( xref.getXRef() );
116     }
117
118     /**
119      * Based on value and type.
120      *
121      *
122      */
123     @Override
124     public boolean equals( final Object o ) {
125         if ( this == o ) {
126             return true;
127         }
128         else if ( o == null ) {
129             throw new IllegalArgumentException( "attempt to check go xref equality to null" );
130         }
131         else if ( o.getClass() != this.getClass() ) {
132             throw new IllegalArgumentException( "attempt to check go xref equality to " + o + " [" + o.getClass() + "]" );
133         }
134         else {
135             return getXRef().equals( ( ( GoXRef ) o ).getXRef() ) && getType().equals( ( ( GoXRef ) o ).getType() );
136         }
137     }
138
139     @Override
140     public Type getType() {
141         return _type;
142     }
143
144     @Override
145     public String getXRef() {
146         return _xref;
147     }
148
149     @Override
150     public String toString() {
151         final StringBuffer sb = new StringBuffer();
152         switch ( getType() ) {
153             case EC:
154                 sb.append( EC_STR );
155                 break;
156             case META_CYC:
157                 sb.append( META_CYC_STR );
158                 break;
159             case REACTOME:
160                 sb.append( REACTOME_STR );
161                 break;
162             case RESID:
163                 sb.append( RESID_STR );
164                 break;
165             case UM_BBD_ENZYME_ID:
166                 sb.append( UM_BBD_ENZYME_ID_STR );
167                 break;
168             case UM_BBD_PATHWAY_ID:
169                 sb.append( UM_BBD_PATHWAY_ID_STR );
170                 break;
171             case UM_BBD_REACTIONID:
172                 sb.append( UM_BBD_REACTIONID_STR );
173                 break;
174             case TC:
175                 sb.append( TC_STR );
176                 break;
177             case ARACYC:
178                 sb.append( ARACYC_STR );
179                 break;
180             case XX:
181                 sb.append( XX_STR );
182                 break;
183             case GOC:
184                 sb.append( GOC_STR );
185                 break;
186             case IMG:
187                 sb.append( IMG_STR );
188                 break;
189             case PMID:
190                 sb.append( PMID_STR );
191                 break;
192             case WIKIPEDIA:
193                 sb.append( WIKIPEDIA_STR );
194                 break;
195             case OTHER:
196                 sb.append( "other" );
197                 break;
198             default:
199                 new AssertionError( "unknown type: " + getType() );
200         }
201         sb.append( ":" );
202         sb.append( getXRef() );
203         return sb.toString();
204     }
205 }