updated jalview version of dasobert 1.53e client and added Das Sequence Source discov...
[jalview.git] / src / org / biojava / dasobert / dasregistry / DasCoordinateSystem.java
1 /*
2  *                    BioJava development code
3  *
4  * This code may be freely distributed and modified under the
5  * terms of the GNU Lesser General Public Licence.  This should
6  * be distributed with the code.  If you do not have a copy,
7  * see:
8  *
9  *      http://www.gnu.org/copyleft/lesser.html
10  *
11  * Copyright for this code is held jointly by the individual
12  * authors.  These should be listed in @author doc comments.
13  *
14  * For more information on the BioJava project and its aims,
15  * or to join the biojava-l mailing list, visit the home page
16  * at:
17  *
18  *      http://www.biojava.org/
19  *
20  * Created on 15.04.2004
21  * @author Andreas Prlic
22  *
23  */
24 package org.biojava.dasobert.dasregistry;
25
26 /** a Bean to be returned via SOAP. It takes care of the DAS -  coordinate Systems
27  * @author Andreas Prlic
28  */
29 public class DasCoordinateSystem
30 {
31
32   String name;
33   String category;
34   String organism_name;
35   int ncbi_tax_id;
36   String uniqueId;
37   String version;
38   String testCode;
39
40   public DasCoordinateSystem()
41   {
42     uniqueId = "";
43     name = "";
44     category = "";
45     organism_name = "";
46     ncbi_tax_id = 0;
47     version = "";
48     testCode = "";
49   }
50
51   public boolean equals(DasCoordinateSystem other)
52   {
53     boolean match = true;
54     System.out.println("comparing " + this.toString() + " to " + other.toString());
55     // URI has piority
56     if ( (!uniqueId.equals("")) && (uniqueId.equals(other.getUniqueId())))
57     {
58       return true;
59     }
60
61     if (ncbi_tax_id != other.getNCBITaxId())
62     {
63       System.out.println("mismatch in ncbi tax id " + ncbi_tax_id + " != " +
64                          other.getNCBITaxId());
65       match = false;
66     }
67     if (!version.equals(other.getVersion()))
68     {
69       System.out.println("mismatch in version");
70       match = false;
71     }
72     if (!category.equals(other.getCategory()))
73     {
74       System.out.println("mismatch in category");
75       match = false;
76     }
77     if (!name.equals(other.getName()))
78     {
79       System.out.println("mismatch in name");
80       match = false;
81     }
82     System.out.println(" match: " + match);
83
84     return match;
85   }
86   
87     public int hashCode() {
88         int h = 7;
89         
90         h = 31 * h + ( null == name ? 0 : name.hashCode());
91         h = 31 * h + ( null == category ? 0 : category.hashCode());
92         
93         return h;
94     }
95
96   public Object clone()
97   {
98     DasCoordinateSystem d = new DasCoordinateSystem();
99     d.setTestCode(testCode);
100     d.setCategory(category);
101     d.setName(name);
102     d.setNCBITaxId(ncbi_tax_id);
103     d.setUniqueId(getUniqueId());
104     d.setOrganismName(getOrganismName());
105     d.setVersion(getVersion());
106     return d;
107   }
108
109   public String getTestCode()
110   {
111     return testCode;
112   }
113
114   public void setTestCode(String testCode)
115   {
116     if (testCode == null)
117     {
118       testCode = "";
119     }
120     this.testCode = testCode;
121   }
122
123   public void setUniqueId(String id)
124   {
125     uniqueId = id;
126   }
127
128   public String getUniqueId()
129   {
130     return uniqueId;
131   }
132
133   public void setName(String n)
134   {
135     name = n;
136   }
137
138   public String getName()
139   {
140     return name;
141   }
142
143   public void setCategory(String c)
144   {
145     category = c;
146   }
147
148   public String getCategory()
149   {
150     return category;
151   }
152
153   public void setOrganismName(String t)
154   {
155     organism_name = t;
156   }
157
158   public String getOrganismName()
159   {
160     return organism_name;
161   }
162
163   public void setNCBITaxId(int id)
164   {
165     ncbi_tax_id = id;
166   }
167
168   public int getNCBITaxId()
169   {
170     return ncbi_tax_id;
171   }
172
173   public String getVersion()
174   {
175     return version;
176   }
177
178   public void setVersion(String version)
179   {
180     if (version == null)
181     {
182       version = "";
183     }
184     this.version = version;
185   }
186
187   public String toString()
188   {
189     String nam = name;
190     if (!version.equals(""))
191     {
192       nam += "_" + version;
193     }
194
195     if (organism_name.equals(""))
196     {
197       return nam + "," + category;
198     }
199     else
200     {
201       return nam + "," + category + "," + organism_name;
202     }
203   }
204
205   public static DasCoordinateSystem fromString(String rawString)
206   {
207     String[] spl = rawString.split(",");
208     DasCoordinateSystem dcs = new DasCoordinateSystem();
209     if (spl.length == 2)
210     {
211       dcs.setName(spl[0]);
212       dcs.setCategory(spl[1]);
213     }
214     if (spl.length == 3)
215     {
216       dcs.setName(spl[0]);
217       dcs.setCategory(spl[1]);
218       dcs.setOrganismName(spl[2]);
219     }
220     return dcs;
221   }
222
223 }