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