Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataDB / src / org / gvsig / data / datastores / vectorial / db / DBFeatureID.java @ 20973

History | View | Annotate | Download (1.52 KB)

1
package org.gvsig.data.datastores.vectorial.db;
2

    
3
import org.gvsig.data.ReadException;
4
import org.gvsig.data.vectorial.IFeature;
5
import org.gvsig.data.vectorial.IFeatureID;
6
import org.gvsig.data.vectorial.IFeatureType;
7

    
8
public class DBFeatureID implements IFeatureID{
9
        protected Object[] featureKey;
10
        protected DBStore store;
11

    
12
        public DBFeatureID(DBStore store,Object[] featureKey) {
13
                this.featureKey=featureKey;
14
                this.store=store;
15
        }
16
        public Object[] getKey(){
17
                return featureKey;
18
        }
19
        public IFeature getFeature(IFeatureType featureType) throws ReadException{
20
                return store.getFeatureByID(featureType, featureKey);
21
        }
22
        public boolean equals(Object obj) {
23
                if (obj instanceof DBFeatureID){
24
                        DBFeatureID other = (DBFeatureID)obj;
25
                        if (this.store != other.store)
26
                                return false;
27
                        Comparable obj1,obj2;
28
                        for (int i=0;i<featureKey.length;i++){
29
                                obj1 = (Comparable)this.featureKey[i];
30
                                obj2 = (Comparable)other.featureKey[i];
31
                                if (obj1 == null || obj2 == null){
32
                                        if (!(obj1 == null && obj2 == null)){
33
                                                return false;
34
                                        }
35
                                } else{
36
                                        if (obj1.compareTo(obj2) != 0){
37
                                                return false;
38
                                        }
39
                                }
40

    
41
                        }
42
                        return true;
43
                }
44
                return false;
45
        }
46
        /* (non-Javadoc)
47
         * @see java.lang.Object#hashCode()
48
         */
49
        public int hashCode() {
50
                StringBuffer strBuffer= new StringBuffer();
51
                strBuffer.append(this.store.hashCode());
52
                strBuffer.append("[$");
53
                for (int i=0;i<featureKey.length;i++){
54
                        strBuffer.append(featureKey[i]);
55
                        strBuffer.append("$,$");
56
                }
57
                strBuffer.append("]");
58
                return strBuffer.toString().hashCode();
59
        }
60

    
61

    
62

    
63
}