JAL-2805 made needed color set methods public
[jalview.git] / forester / java / src / org / forester / species / BasicSpecies.java
1 // $Id:
2 //
3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
5 //
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
8 // All rights reserved
9 //
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.
14 //
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.
19 //
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
23 //
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26
27 package org.forester.species;
28
29 import org.forester.util.ForesterUtil;
30
31 public class BasicSpecies implements Species {
32
33     final private String _species_id;
34
35     public BasicSpecies( final String species_id ) {
36         if ( ForesterUtil.isEmpty( species_id ) ) {
37             throw new IllegalArgumentException( "attempt to create new species from empty or null string" );
38         }
39         _species_id = species_id.trim();
40     }
41
42     @Override
43     public int compareTo( final Species species ) {
44         if ( this == species ) {
45             return 0;
46         }
47         return getSpeciesId().toLowerCase().compareTo( species.getSpeciesId().toLowerCase() );
48     }
49
50     @Override
51     public boolean equals( final Object o ) {
52         if ( this == o ) {
53             return true;
54         }
55         else if ( o == null ) {
56             throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to null" );
57         }
58         else if ( o.getClass() != this.getClass() ) {
59             throw new IllegalArgumentException( "attempt to check [" + this.getClass() + "] equality to " + o + " ["
60                     + o.getClass() + "]" );
61         }
62         else {
63             return getSpeciesId().equals( ( ( Species ) o ).getSpeciesId() );
64         }
65     }
66
67     /* (non-Javadoc)
68      * @see org.forester.surfacing.Species#getSpeciesId()
69      */
70     @Override
71     public String getSpeciesId() {
72         return _species_id;
73     }
74
75     @Override
76     public int hashCode() {
77         return getSpeciesId().hashCode();
78     }
79
80     @Override
81     public String toString() {
82         return getSpeciesId();
83     }
84 }