Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.api / src / main / java / org / gvsig / fmap / geom / type / AbstractGeometryType.java @ 45425

History | View | Annotate | Download (3.13 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.geom.type;
25

    
26
import java.util.ArrayList;
27
import java.util.List;
28

    
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.operation.GeometryOperation;
31

    
32
public abstract class AbstractGeometryType implements GeometryType {
33

    
34
    /**
35
     * Registered operations for a concrete geometry type
36
     */
37
    private final List<GeometryOperation> GEOMETRY_OPERATIONS = new ArrayList();
38

    
39
    @Override
40
    public boolean isTypeOf(GeometryType geometryType) {
41
        return isTypeOf(geometryType.getType());
42
    }
43

    
44
    @Override
45
    public boolean isSubTypeOf(GeometryType geometryType) {
46
        return isSubTypeOf(geometryType.getSubType());
47
    }
48

    
49
    @Override
50
    public void setGeometryOperation(int index, GeometryOperation geomOp) {
51
        while (index > GEOMETRY_OPERATIONS.size()) {
52
            GEOMETRY_OPERATIONS.add(null);
53
        }
54

    
55
        if (index == GEOMETRY_OPERATIONS.size()) {
56
            GEOMETRY_OPERATIONS.add(geomOp);
57
        } else {
58
            GEOMETRY_OPERATIONS.set(index, geomOp);
59
        }
60
    }
61

    
62
    @Override
63
    public GeometryOperation getGeometryOperation(int index) {
64
        return (GeometryOperation) GEOMETRY_OPERATIONS.get(index);
65
    }
66

    
67
    @Override
68
    public boolean equals(Object obj) {
69
        if (obj instanceof GeometryType) {
70
            GeometryType other = (GeometryType) obj;
71
            return getType() == other.getType()
72
                    && getSubType() == other.getSubType();
73
        }
74
        return false;
75
    }
76

    
77
    protected List getGeometryOperations() {
78
        return GEOMETRY_OPERATIONS;
79
    }
80

    
81
    @Override
82
    public String toString() {
83
        StringBuilder sb = new StringBuilder("[")
84
                .append(getName())
85
                .append(",[")
86
                .append(getGeometryOperations().toString())
87
                .append("]");
88

    
89
        return sb.toString();
90
    }
91

    
92
    @Override
93
    public boolean hasZ() {
94
        int subtype = this.getSubType();
95
        return subtype == Geometry.SUBTYPES.GEOM3D || subtype == Geometry.SUBTYPES.GEOM3DM;
96
    }
97

    
98
    @Override
99
    public boolean hasM() {
100
        int subtype = this.getSubType();
101
        return subtype == Geometry.SUBTYPES.GEOM2DM || subtype == Geometry.SUBTYPES.GEOM3DM;
102
    }
103
    
104
}