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 org.forester.util.ForesterUtil;
31 public class DomainId implements Comparable<DomainId> {
33 final private String _id;
35 // private List<GoId> _go_ids;
36 private DomainId( final String id ) {
37 if ( ForesterUtil.isEmpty( id ) ) {
38 throw new IllegalArgumentException( "attempt to create domain id from empty or null string" );
41 if ( _id.indexOf( ' ' ) > -1 ) {
42 throw new IllegalArgumentException( "attempt to create domain id from string containing one ore more spaces ["
45 else if ( _id.indexOf( BinaryDomainCombination.SEPARATOR ) > -1 ) {
46 throw new IllegalArgumentException( "attempt to create domain id from string containing the separator character ["
47 + BinaryDomainCombination.SEPARATOR + "] for domain combinations [" + _id + "]" );
49 ///////////////////////////// // setGoIds( null );
52 // public void addGoId( final GoId go_id ) {
53 // if ( getGoIds() == null ) {
54 // setGoIds( new ArrayList<GoId>() );
56 // getGoIds().add( go_id );
59 public int compareTo( final DomainId domain_id ) {
60 if ( this == domain_id ) {
63 return getId().toLowerCase().compareTo( domain_id.getId().toLowerCase() );
67 public boolean equals( final Object o ) {
71 else if ( o == null ) {
72 throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to null" );
74 else if ( o.getClass() != this.getClass() ) {
75 throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to " + o + " ["
76 + o.getClass() + "]" );
79 return getId().equals( ( ( DomainId ) o ).getId() );
83 // public GoId getGoId( final int i ) {
84 // return getGoIds().get( i );
87 // The fact that equals and compareTo do not behave the same in cases where ids only differ by their case
88 // is not ideal. From Sun regarding Interface SortedSet<E>:
89 // "Note that the ordering maintained by a sorted set (whether or not an explicit comparator is provided)
90 // must be consistent with equals if the sorted set is to correctly implement the Set interface.
91 // (See the Comparable interface or Comparator interface for a precise definition of consistent
92 // with equals.) This is so because the Set interface is defined in terms of the equals operation,
93 // but a sorted set performs all element comparisons using its compareTo (or compare) method,
94 // so two elements that are deemed equal by this method are, from the standpoint of the sorted set,
95 // equal. The behavior of a sorted set is well-defined even if its ordering is inconsistent with equals;
96 // it just fails to obey the general contract of the Set interface."
97 // public List<GoId> getGoIds() {
100 private String getId() {
104 // public int getNumberOfGoIds() {
105 // if ( getGoIds() == null ) {
108 // return getGoIds().size();
111 public int hashCode() {
112 return getId().hashCode();
115 // private void setGoIds( final List<GoId> go_ids ) {
119 public String toString() {