3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.protein;
29 import java.util.ArrayList;
30 import java.util.List;
32 import org.forester.go.GoId;
33 import org.forester.util.ForesterUtil;
35 public class DomainId implements Comparable<DomainId> {
37 final private String _id;
38 private List<GoId> _go_ids;
40 public DomainId( final String id ) {
41 if ( ForesterUtil.isEmpty( id ) ) {
42 throw new IllegalArgumentException( "attempt to create domain id from empty or null string" );
45 if ( _id.indexOf( ' ' ) > -1 ) {
46 throw new IllegalArgumentException( "attempt to create domain id from string containing one ore more spaces ["
49 else if ( _id.indexOf( BinaryDomainCombination.SEPARATOR ) > -1 ) {
50 throw new IllegalArgumentException( "attempt to create domain id from string containing the separator character ["
51 + BinaryDomainCombination.SEPARATOR + "] for domain combinations [" + _id + "]" );
56 public void addGoId( final GoId go_id ) {
57 if ( getGoIds() == null ) {
58 setGoIds( new ArrayList<GoId>() );
60 getGoIds().add( go_id );
64 public int compareTo( final DomainId domain_id ) {
65 if ( this == domain_id ) {
68 return getId().toLowerCase().compareTo( domain_id.getId().toLowerCase() );
72 public boolean equals( final Object o ) {
76 else if ( o == null ) {
77 throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to null" );
79 else if ( o.getClass() != this.getClass() ) {
80 throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to " + o + " ["
81 + o.getClass() + "]" );
84 return getId().equals( ( ( DomainId ) o ).getId() );
88 public GoId getGoId( final int i ) {
89 return getGoIds().get( i );
93 // The fact that equals and compareTo do not behave the same in cases where ids only differ by their case
94 // is not ideal. From Sun regarding Interface SortedSet<E>:
95 // "Note that the ordering maintained by a sorted set (whether or not an explicit comparator is provided)
96 // must be consistent with equals if the sorted set is to correctly implement the Set interface.
97 // (See the Comparable interface or Comparator interface for a precise definition of consistent
98 // with equals.) This is so because the Set interface is defined in terms of the equals operation,
99 // but a sorted set performs all element comparisons using its compareTo (or compare) method,
100 // so two elements that are deemed equal by this method are, from the standpoint of the sorted set,
101 // equal. The behavior of a sorted set is well-defined even if its ordering is inconsistent with equals;
102 // it just fails to obey the general contract of the Set interface."
103 public List<GoId> getGoIds() {
107 public String getId() {
111 public int getNumberOfGoIds() {
112 if ( getGoIds() == null ) {
115 return getGoIds().size();
119 public int hashCode() {
120 return getId().hashCode();
123 private void setGoIds( final List<GoId> go_ids ) {
128 public String toString() {