4cb6212c75f8cce8108d82fa37c3a88b5d6bb6c1
[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 Object clone()
88   {
89     DasCoordinateSystem d = new DasCoordinateSystem();
90     d.setTestCode(testCode);
91     d.setCategory(category);
92     d.setName(name);
93     d.setNCBITaxId(ncbi_tax_id);
94     d.setUniqueId(getUniqueId());
95     d.setOrganismName(getOrganismName());
96     d.setVersion(getVersion());
97     return d;
98   }
99
100   public String getTestCode()
101   {
102     return testCode;
103   }
104
105   public void setTestCode(String testCode)
106   {
107     if (testCode == null)
108     {
109       testCode = "";
110     }
111     this.testCode = testCode;
112   }
113
114   public void setUniqueId(String id)
115   {
116     uniqueId = id;
117   }
118
119   public String getUniqueId()
120   {
121     return uniqueId;
122   }
123
124   public void setName(String n)
125   {
126     name = n;
127   }
128
129   public String getName()
130   {
131     return name;
132   }
133
134   public void setCategory(String c)
135   {
136     category = c;
137   }
138
139   public String getCategory()
140   {
141     return category;
142   }
143
144   public void setOrganismName(String t)
145   {
146     organism_name = t;
147   }
148
149   public String getOrganismName()
150   {
151     return organism_name;
152   }
153
154   public void setNCBITaxId(int id)
155   {
156     ncbi_tax_id = id;
157   }
158
159   public int getNCBITaxId()
160   {
161     return ncbi_tax_id;
162   }
163
164   public String getVersion()
165   {
166     return version;
167   }
168
169   public void setVersion(String version)
170   {
171     if (version == null)
172     {
173       version = "";
174     }
175     this.version = version;
176   }
177
178   public String toString()
179   {
180     String nam = name;
181     if (!version.equals(""))
182     {
183       nam += "_" + version;
184     }
185
186     if (organism_name.equals(""))
187     {
188       return nam + "," + category;
189     }
190     else
191     {
192       return nam + "," + category + "," + organism_name;
193     }
194   }
195
196   public static DasCoordinateSystem fromString(String rawString)
197   {
198     String[] spl = rawString.split(",");
199     DasCoordinateSystem dcs = new DasCoordinateSystem();
200     if (spl.length == 2)
201     {
202       dcs.setName(spl[0]);
203       dcs.setCategory(spl[1]);
204     }
205     if (spl.length == 3)
206     {
207       dcs.setName(spl[0]);
208       dcs.setCategory(spl[1]);
209       dcs.setOrganismName(spl[2]);
210     }
211     return dcs;
212   }
213
214 }