licencing and format applied (eclipse)
[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 /**
27  * a Bean to be returned via SOAP. It takes care of the DAS - coordinate Systems
28  * 
29  * @author Andreas Prlic
30  */
31 public class DasCoordinateSystem
32 {
33
34   String name;
35
36   String category;
37
38   String organism_name;
39
40   int ncbi_tax_id;
41
42   String uniqueId;
43
44   String version;
45
46   String testCode;
47
48   public DasCoordinateSystem()
49   {
50     uniqueId = "";
51     name = "";
52     category = "";
53     organism_name = "";
54     ncbi_tax_id = 0;
55     version = "";
56     testCode = "";
57   }
58
59   public boolean equals(DasCoordinateSystem other)
60   {
61     boolean match = true;
62     System.out.println("comparing " + this.toString() + " to "
63             + other.toString());
64     // URI has piority
65     if ((!uniqueId.equals("")) && (uniqueId.equals(other.getUniqueId())))
66     {
67       return true;
68     }
69
70     if (ncbi_tax_id != other.getNCBITaxId())
71     {
72       System.out.println("mismatch in ncbi tax id " + ncbi_tax_id + " != "
73               + other.getNCBITaxId());
74       match = false;
75     }
76     if (!version.equals(other.getVersion()))
77     {
78       System.out.println("mismatch in version");
79       match = false;
80     }
81     if (!category.equals(other.getCategory()))
82     {
83       System.out.println("mismatch in category");
84       match = false;
85     }
86     if (!name.equals(other.getName()))
87     {
88       System.out.println("mismatch in name");
89       match = false;
90     }
91     System.out.println(" match: " + match);
92
93     return match;
94   }
95
96   public int hashCode()
97   {
98     int h = 7;
99
100     h = 31 * h + (null == name ? 0 : name.hashCode());
101     h = 31 * h + (null == category ? 0 : category.hashCode());
102
103     return h;
104   }
105
106   public Object clone()
107   {
108     DasCoordinateSystem d = new DasCoordinateSystem();
109     d.setTestCode(testCode);
110     d.setCategory(category);
111     d.setName(name);
112     d.setNCBITaxId(ncbi_tax_id);
113     d.setUniqueId(getUniqueId());
114     d.setOrganismName(getOrganismName());
115     d.setVersion(getVersion());
116     return d;
117   }
118
119   public String getTestCode()
120   {
121     return testCode;
122   }
123
124   public void setTestCode(String testCode)
125   {
126     if (testCode == null)
127     {
128       testCode = "";
129     }
130     this.testCode = testCode;
131   }
132
133   public void setUniqueId(String id)
134   {
135     uniqueId = id;
136   }
137
138   public String getUniqueId()
139   {
140     return uniqueId;
141   }
142
143   public void setName(String n)
144   {
145     name = n;
146   }
147
148   public String getName()
149   {
150     return name;
151   }
152
153   public void setCategory(String c)
154   {
155     category = c;
156   }
157
158   public String getCategory()
159   {
160     return category;
161   }
162
163   public void setOrganismName(String t)
164   {
165     organism_name = t;
166   }
167
168   public String getOrganismName()
169   {
170     return organism_name;
171   }
172
173   public void setNCBITaxId(int id)
174   {
175     ncbi_tax_id = id;
176   }
177
178   public int getNCBITaxId()
179   {
180     return ncbi_tax_id;
181   }
182
183   public String getVersion()
184   {
185     return version;
186   }
187
188   public void setVersion(String version)
189   {
190     if (version == null)
191     {
192       version = "";
193     }
194     this.version = version;
195   }
196
197   public String toString()
198   {
199     String nam = name;
200     if (!version.equals(""))
201     {
202       nam += "_" + version;
203     }
204
205     if (organism_name.equals(""))
206     {
207       return nam + "," + category;
208     }
209     else
210     {
211       return nam + "," + category + "," + organism_name;
212     }
213   }
214
215   public static DasCoordinateSystem fromString(String rawString)
216   {
217     String[] spl = rawString.split(",");
218     DasCoordinateSystem dcs = new DasCoordinateSystem();
219     if (spl.length == 2)
220     {
221       dcs.setName(spl[0]);
222       dcs.setCategory(spl[1]);
223     }
224     if (spl.length == 3)
225     {
226       dcs.setName(spl[0]);
227       dcs.setCategory(spl[1]);
228       dcs.setOrganismName(spl[2]);
229     }
230     return dcs;
231   }
232
233 }