Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / MemoryExpansionFile.java @ 6212

History | View | Annotate | Download (4.92 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.edition;
42

    
43
import java.io.IOException;
44
import java.util.ArrayList;
45
import java.util.HashMap;
46

    
47
import com.iver.cit.gvsig.fmap.core.IRow;
48

    
49

    
50
/**
51
 * Implementaci?n en memoria de ExpansionFile.
52
 *
53
 * @author Vicente Caballero Navarro
54
 */
55
public class MemoryExpansionFile implements ExpansionFile {
56
        ArrayList rows = new ArrayList();
57
        EditableAdapter edAdapter;
58
        
59
        private class InternalRow 
60
        {
61
                private IRowEdited row;
62
                private int indexInternalFields;
63
                public InternalRow(IRowEdited row, int indexInternalFields)
64
                {
65
                        this.row = row;
66
                        this.indexInternalFields = indexInternalFields;
67
                }
68
                public int getIndexInternalFields() {
69
                        return indexInternalFields;
70
                }
71
                public IRowEdited getRow() {
72
                        return row;
73
                }
74
        }
75
        
76
        public MemoryExpansionFile(EditableAdapter edAdapter)
77
        {
78
                this.edAdapter = edAdapter;
79
        }
80
        
81
        //BitSet invalidRows = new BitSet();
82
        /**
83
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#addRow(IRow, int)
84
         */
85
        public int addRow(IRow row, int status, int indexInternalFields) throws IOException {
86
                int newIndex = rows.size();
87
                IRowEdited edRow = new DefaultRowEdited(row,
88
                                status, newIndex);
89
                InternalRow iRow = new InternalRow(edRow, indexInternalFields);
90
                rows.add(iRow);
91

    
92
                return newIndex;
93
        }
94

    
95
        /**
96
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#modifyRow(int,
97
         *                 IRow)
98
         */
99
        public int modifyRow(int index, IRow row, int indexInternalFields) throws IOException {
100
                /*if (invalidRows.get(index)) {
101
                        throw new RuntimeException(
102
                                "Se ha intentado modificar una geometr?a que ha sido borrada anteriormente");
103
                }
104
*/
105
                //invalidateRow(index);
106
                IRowEdited edRow = new DefaultRowEdited(row,
107
                                IRowEdited.STATUS_MODIFIED, index);
108

    
109
                InternalRow iRow = new InternalRow(edRow, indexInternalFields);
110
                rows.add(iRow);
111

    
112

    
113
                return rows.size() - 1;
114
        }
115

    
116
        /**
117
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRow(int)
118
         */
119
        public IRowEdited getRow(int index) throws IOException {
120
                /*if (invalidRows.get(index)) {
121
                        return null;
122
                }
123
*/
124
                InternalRow iRow = (InternalRow) rows.get(index); 
125
                int indexInternalFields = iRow.getIndexInternalFields();
126
                return edAdapter.createExternalRow(iRow.getRow(), indexInternalFields);
127
                // return iRow.getRow();
128
        }
129

    
130
        /**
131
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#invalidateRow(int)
132
         */
133
        /*public void invalidateRow(int index) {
134
                invalidRows.set(index, true);
135
        }
136
*/
137
        /**
138
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#compact()
139
         */
140
        public void compact(HashMap relations) {
141
        /*        ArrayList geoAux = new ArrayList();
142
                Iterator iter = relations.keySet().iterator();
143
                HashMap aux = new HashMap();
144
                int n = 0;
145

146
                while (iter.hasNext()) {
147
                        Integer virtualIndex = (Integer) iter.next();
148
                        Integer expansionIndex = (Integer) relations.get(virtualIndex);
149

150
                        if (!invalidRows.get(expansionIndex.intValue())){
151
                                geoAux.add(rows.get(expansionIndex.intValue()));
152
                                aux.put(new Integer(n), new Integer(geoAux.size()-1));
153
                                n++;
154
                        }
155
                }
156

157
                invalidRows.clear();
158
                rows = geoAux;
159
                relations.clear();
160
                relations.putAll(aux);
161
*/
162

    
163
        }
164

    
165
        /**
166
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRowCount()
167
         */
168
        /*public int getRowCount() {
169
                return rows.size() - invalidRows.cardinality();
170
        }
171
*/
172
        public void deleteLastRow() {
173
                //invalidRows.set(rows.size()-1,false);
174
                rows.remove(rows.size()-1);
175

    
176
        }
177

    
178
        public void open() throws IOException {
179
                // TODO Auto-generated method stub
180

    
181
        }
182

    
183
        public void close() throws IOException {
184
                rows.clear();
185

    
186
        }
187

    
188
        public int getSize() {
189
                return rows.size();
190
        }
191

    
192
        /* (non-Javadoc)
193
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#validateRow(int)
194
         */
195
        /*public void validateRow(int previousExpansionFileIndex) {
196
                invalidRows.set(previousExpansionFileIndex, false);
197
        }
198

199
        public BitSet getInvalidRows() {
200
                return invalidRows;
201
        }*/
202
}