2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
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.
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.
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
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.go;
28 public class BasicGoRelationship implements GoRelationship {
33 public BasicGoRelationship( final String s ) {
34 final String[] sa = s.split( " " );
35 if ( sa.length != 2 ) {
36 throw new IllegalArgumentException( "unexpected format for GO relationship: " + s );
38 final String type = sa[ 0 ].trim();
39 final String go_id = sa[ 1 ].trim();
40 if ( type.toLowerCase().equals( PART_OF_STR ) ) {
43 else if ( type.toLowerCase().equals( REGULATES_STR ) ) {
44 _type = Type.REGULATES;
46 else if ( type.toLowerCase().equals( NEGATIVELY_REGULATES_STR ) ) {
47 _type = Type.NEGATIVELY_REGULATES;
49 else if ( type.toLowerCase().equals( POSITIVELY_REGULATES_STR ) ) {
50 _type = Type.POSITIVELY_REGULATES;
52 else if ( type.toLowerCase().equals( HAS_PART_STR ) ) {
53 _type = Type.HAS_PART;
56 throw new IllegalArgumentException( "unknown GO relationship type: " + type );
58 _go_id = new GoId( go_id );
61 public BasicGoRelationship( final String type, final String go_id ) {
62 if ( type.toLowerCase().equals( PART_OF_STR ) ) {
66 throw new IllegalArgumentException( "unknown GO relationship type: " + type );
68 _go_id = new GoId( go_id );
71 public BasicGoRelationship( final Type type, final GoId go_id ) {
77 public int compareTo( final GoRelationship rel ) {
78 return getGoId().compareTo( rel.getGoId() );
82 * Based on value and type.
87 public boolean equals( final Object o ) {
91 else if ( o == null ) {
92 throw new IllegalArgumentException( "attempt to check go relationship equality to null" );
94 else if ( o.getClass() != this.getClass() ) {
95 throw new IllegalArgumentException( "attempt to check go relationship equality to " + o + " ["
96 + o.getClass() + "]" );
99 return getType().equals( ( ( GoRelationship ) o ).getType() )
100 && getGoId().equals( ( ( GoRelationship ) o ).getGoId() );
105 public GoId getGoId() {
110 public Type getType() {
115 public String toString() {
116 final StringBuffer sb = new StringBuffer();
117 switch ( getType() ) {
119 sb.append( PART_OF_STR );
121 case NEGATIVELY_REGULATES:
122 sb.append( NEGATIVELY_REGULATES_STR );
124 case POSITIVELY_REGULATES:
125 sb.append( POSITIVELY_REGULATES_STR );
128 sb.append( REGULATES_STR );
131 sb.append( HAS_PART_STR );
134 new IllegalStateException( "unknown type: " + getType() );
137 sb.append( getGoId().toString() );
138 return sb.toString();