clean up
[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: www.phylosoft.org/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 {
85             throw new IllegalArgumentException( "unknown GO xref type: " + type );
86         }
87         _xref = sa[ 1 ].trim();
88     }
89
90     public BasicGoXRef( final Type type, final String xref ) {
91         _type = type;
92         _xref = xref;
93     }
94
95     @Override
96     public int compareTo( final GoXRef xref ) {
97         return getXRef().compareTo( xref.getXRef() );
98     }
99
100     /**
101      * Based on value and type.
102      * 
103      * 
104      */
105     @Override
106     public boolean equals( final Object o ) {
107         if ( this == o ) {
108             return true;
109         }
110         else if ( o == null ) {
111             throw new IllegalArgumentException( "attempt to check go xref equality to null" );
112         }
113         else if ( o.getClass() != this.getClass() ) {
114             throw new IllegalArgumentException( "attempt to check go xref equality to " + o + " [" + o.getClass() + "]" );
115         }
116         else {
117             return getXRef().equals( ( ( GoXRef ) o ).getXRef() ) && getType().equals( ( ( GoXRef ) o ).getType() );
118         }
119     }
120
121     @Override
122     public Type getType() {
123         return _type;
124     }
125
126     @Override
127     public String getXRef() {
128         return _xref;
129     }
130
131     @Override
132     public String toString() {
133         final StringBuffer sb = new StringBuffer();
134         switch ( getType() ) {
135             case EC:
136                 sb.append( EC_STR );
137                 break;
138             case META_CYC:
139                 sb.append( META_CYC_STR );
140                 break;
141             case REACTOME:
142                 sb.append( REACTOME_STR );
143                 break;
144             case RESID:
145                 sb.append( RESID_STR );
146                 break;
147             case UM_BBD_ENZYME_ID:
148                 sb.append( UM_BBD_ENZYME_ID_STR );
149                 break;
150             case UM_BBD_PATHWAY_ID:
151                 sb.append( UM_BBD_PATHWAY_ID_STR );
152                 break;
153             case UM_BBD_REACTIONID:
154                 sb.append( UM_BBD_REACTIONID_STR );
155                 break;
156             case TC:
157                 sb.append( TC_STR );
158                 break;
159             case ARACYC:
160                 sb.append( ARACYC_STR );
161                 break;
162             case XX:
163                 sb.append( XX_STR );
164                 break;
165             case GOC:
166                 sb.append( GOC_STR );
167                 break;
168             case IMG:
169                 sb.append( IMG_STR );
170                 break;
171             case PMID:
172                 sb.append( PMID_STR );
173                 break;
174             case WIKIPEDIA:
175                 sb.append( WIKIPEDIA_STR );
176                 break;
177             default:
178                 new AssertionError( "unknown type: " + getType() );
179         }
180         sb.append( ":" );
181         sb.append( getXRef() );
182         return sb.toString();
183     }
184 }