Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libDXF / src / org / cresques / io / DxfGroupVector.java @ 21930

History | View | Annotate | Download (3.37 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

    
26
import java.util.Vector;
27

    
28

    
29
/**
30
 * Vector de DxfGroup. Auxiliar para leer ficheros .dxf
31
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
32
 */
33
public class DxfGroupVector extends Vector {
34
    final private static long serialVersionUID = -3370601314380922368L;
35

    
36
    /**
37
     * Valor del dato del codigo de grupo especificado.
38
     *
39
     * @param code C?digo de grupo dxf.
40
     * @return Valor del data del grupo dxf, null si no existe.
41
     */
42
    public boolean hasCode(int code) {
43
        DxfGroup grp = null;
44

    
45
        for (int i = 0; i < size(); i++) {
46
            grp = (DxfGroup) get(i);
47

    
48
            if (grp.code == code) {
49
                return true;
50
            }
51
        }
52

    
53
        return false;
54
    }
55

    
56
    /**
57
     * Devuelve la informaci?n contenida en un DxfGroup.
58
     * @param code, la parte concreta del DxfGroup a la que queremos acceder
59
     * @return
60
     */
61
    public Object getData(int code) {
62
        DxfGroup grp = null;
63

    
64
        for (int i = 0; i < size(); i++) {
65
            grp = (DxfGroup) get(i);
66

    
67
            if (grp.code == code) {
68
                return grp.data;
69
            }
70
        }
71

    
72
        return null;
73
    }
74

    
75
    /**
76
     * Obtiene la informaci?n contenida en un DxfGroup en forma de String
77
     * @param code
78
     * @return
79
     */
80
    public String getDataAsString(int code) {
81
        return (String) getData(code);
82
    }
83

    
84
    /**
85
     * Obtiene la informaci?n contenida en un DxfGroup en forma de double
86
     * @param code
87
     * @return
88
     */
89
    public double getDataAsDouble(int code) {
90
        Double f = (Double) getData(code);
91

    
92
        if (f == null) {
93
            System.err.println(this);
94
            return 0;
95
        }
96

    
97
        return f.doubleValue();
98
    }
99

    
100
    /**
101
     * Obtiene la informaci?n contenida en un DxfGroup en forma de integer
102
     * @param code
103
     * @return
104
     */
105
    public int getDataAsInt(int code) {
106
        Integer i = (Integer) getData(code);
107

    
108
        if (i == null) {
109
            System.err.println(this);
110
        }
111

    
112
        return i.intValue();
113
    }
114

    
115
    /**
116
     * Permite obtener el contenido de un DxfGroup en forma de String
117
     */
118
    public String toString() {
119
        String str = "DxfGroupVector[";
120
        DxfGroup grp = null;
121

    
122
        for (int i = 0; i < size(); i++) {
123
            grp = (DxfGroup) get(i);
124
            str += ("(" + grp.code + ":" + grp.data + "),");
125
        }
126

    
127
        return str;
128
    }
129
}