(JAL-1016) noted position where race condition occurs
[jalview.git] / src / org / biojava / dasobert / das2 / Das2SourceImpl.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 Feb 9, 2006
21  *
22  */
23 package org.biojava.dasobert.das2;
24
25 import org.biojava.dasobert.dasregistry.*;
26
27 public class Das2SourceImpl extends Das1Source implements Das2Source
28
29 {
30
31   Das2Capability[] capabilities;
32
33   public Das2SourceImpl()
34   {
35     super();
36
37     capabilities = new Das2Capability[0];
38   }
39
40   /**
41    * compare if two DasSources are identical
42    * 
43    */
44   public boolean equals(DasSource other)
45   {
46
47     if (this == other)
48     {
49       return true;
50     }
51
52     if ((other == null) || (other.getClass() != this.getClass()))
53     {
54       return false;
55     }
56
57     // to compare if two Das2Sources are identical we do the following:
58     // we check the capabilities
59
60     Das2SourceImpl d2o = (Das2SourceImpl) other;
61
62     if (nickname.equals(d2o.getNickname()))
63     {
64       return true;
65     }
66
67     Das2Capability[] othercaps = d2o.getDas2Capabilities();
68
69     if (!(capabilities.length == othercaps.length))
70     {
71       return false;
72     }
73
74     for (int x = 0; x < capabilities.length; x++)
75     {
76       Das2Capability tmpcap = capabilities[x];
77       boolean foundCap = false;
78       for (int y = 0; y < othercaps.length; y++)
79       {
80         Das2Capability tmpcapo = othercaps[y];
81         if (tmpcap.equals(tmpcapo))
82         {
83           foundCap = true;
84         }
85       }
86       if (!foundCap)
87       {
88         return false;
89       }
90     }
91
92     // TODO?
93     // should we add a check for coordinate systems?
94     // but we already check for the endpoints, that should be enough...
95
96     return true;
97
98   }
99
100   public int hashCode()
101   {
102     int h = 7;
103
104     h = 31 * h + (null == nickname ? 0 : nickname.hashCode());
105
106     for (int x = 0; x < capabilities.length; x++)
107     {
108       Das2Capability cap = capabilities[x];
109       h = 31 * h + cap.hashCode();
110     }
111
112     return h;
113   }
114
115   public boolean hasDas1Capabilities()
116   {
117
118     // test if any of the capabilities is a das1 capabilitiy
119
120     for (int i = 0; i < capabilities.length; i++)
121     {
122       Das2Capability cap = capabilities[i];
123       if (cap.isDas1Style())
124       {
125         return true;
126       }
127     }
128     return false;
129
130   }
131
132   public String[] getCapabilities()
133   {
134     // todo mark as not needed / not appropriate ...
135     return super.getCapabilities();
136   }
137
138   public void setCapabilities(String[] u)
139   {
140     // TODO Auto-generated method stub
141     super.setCapabilities(u);
142   }
143
144   public Das2Capability[] getDas2Capabilities()
145   {
146     // TODO Auto-generated method stub
147     return capabilities;
148   }
149
150   public void setDas2Capabilities(Das2Capability[] capabilities)
151   {
152     // TODO Auto-generated method stub
153     this.capabilities = capabilities;
154
155   }
156
157 }