svn-gvsig-desktop / tags / v1_1_Build_1011 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / MemoryExpansionFile.java @ 12904
History | View | Annotate | Download (5.51 KB)
1 | 1251 | vcaballero | /* 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 | 1287 | vcaballero | import java.util.HashMap; |
46 | 1251 | vcaballero | |
47 | 4181 | fjp | import com.iver.cit.gvsig.fmap.core.IRow; |
48 | 1251 | vcaballero | |
49 | 4181 | fjp | |
50 | 1251 | vcaballero | /**
|
51 | 4953 | caballero | * Implementaci?n en memoria de ExpansionFile.
|
52 | 1251 | vcaballero | *
|
53 | * @author Vicente Caballero Navarro
|
||
54 | */
|
||
55 | public class MemoryExpansionFile implements ExpansionFile { |
||
56 | 3652 | fjp | ArrayList rows = new ArrayList(); |
57 | 6212 | fjp | 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 | 3996 | caballero | //BitSet invalidRows = new BitSet();
|
82 | 1251 | vcaballero | /**
|
83 | 4799 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#addRow(IRow, int)
|
84 | 1251 | vcaballero | */
|
85 | 6212 | fjp | public int addRow(IRow row, int status, int indexInternalFields) throws IOException { |
86 | 4115 | fjp | int newIndex = rows.size();
|
87 | 3835 | caballero | IRowEdited edRow = new DefaultRowEdited(row,
|
88 | 4799 | fjp | status, newIndex); |
89 | 6212 | fjp | InternalRow iRow = new InternalRow(edRow, indexInternalFields);
|
90 | rows.add(iRow); |
||
91 | 1251 | vcaballero | |
92 | 4115 | fjp | return newIndex;
|
93 | 1251 | vcaballero | } |
94 | |||
95 | /**
|
||
96 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#modifyRow(int,
|
97 | * IRow)
|
||
98 | 1251 | vcaballero | */
|
99 | 9887 | fjp | // 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 | 6212 | fjp | public int modifyRow(int index, IRow row, int indexInternalFields) throws IOException { |
117 | 9887 | fjp | /*if (invalidRows.get(index)) {
|
118 | throw new RuntimeException(
|
||
119 | "Se ha intentado modificar una geometr?a que ha sido borrada anteriormente");
|
||
120 | }
|
||
121 | */
|
||
122 | //invalidateRow(index);
|
||
123 | InternalRow iOldRow = (InternalRow) rows.get(index); |
||
124 | IRowEdited edRow = new DefaultRowEdited(row,
|
||
125 | iOldRow.getRow().getStatus(), index); |
||
126 | 3835 | caballero | |
127 | 9887 | fjp | InternalRow iRow = new InternalRow(edRow, indexInternalFields);
|
128 | rows.add(iRow); |
||
129 | 1251 | vcaballero | |
130 | 6212 | fjp | |
131 | 9887 | fjp | return rows.size() - 1; |
132 | } |
||
133 | 1251 | vcaballero | |
134 | /**
|
||
135 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRow(int)
|
136 | 1251 | vcaballero | */
|
137 | 3653 | fjp | public IRowEdited getRow(int index) throws IOException { |
138 | 3996 | caballero | /*if (invalidRows.get(index)) {
|
139 | 1251 | vcaballero | return null;
|
140 | }
|
||
141 | 3996 | caballero | */
|
142 | 6212 | fjp | InternalRow iRow = (InternalRow) rows.get(index); |
143 | int indexInternalFields = iRow.getIndexInternalFields();
|
||
144 | return edAdapter.createExternalRow(iRow.getRow(), indexInternalFields);
|
||
145 | // return iRow.getRow();
|
||
146 | 1251 | vcaballero | } |
147 | |||
148 | /**
|
||
149 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#invalidateRow(int)
|
150 | 1251 | vcaballero | */
|
151 | 3996 | caballero | /*public void invalidateRow(int index) {
|
152 | 3651 | fjp | invalidRows.set(index, true);
|
153 | 1251 | vcaballero | }
|
154 | 3996 | caballero | */
|
155 | 1251 | vcaballero | /**
|
156 | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#compact()
|
||
157 | */
|
||
158 | 1287 | vcaballero | public void compact(HashMap relations) { |
159 | 3996 | caballero | /* ArrayList geoAux = new ArrayList();
|
160 | 1291 | fernando | Iterator iter = relations.keySet().iterator();
|
161 | HashMap aux = new HashMap();
|
||
162 | int n = 0;
|
||
163 | 3835 | caballero | |
164 | 1287 | vcaballero | while (iter.hasNext()) {
|
165 | 1291 | fernando | Integer virtualIndex = (Integer) iter.next();
|
166 | Integer expansionIndex = (Integer) relations.get(virtualIndex);
|
||
167 | 3835 | caballero | |
168 | 3651 | fjp | if (!invalidRows.get(expansionIndex.intValue())){
|
169 | 3652 | fjp | geoAux.add(rows.get(expansionIndex.intValue()));
|
170 | 1291 | fernando | aux.put(new Integer(n), new Integer(geoAux.size()-1));
|
171 | 1287 | vcaballero | n++;
|
172 | }
|
||
173 | }
|
||
174 | 1291 | fernando | |
175 | 3651 | fjp | invalidRows.clear();
|
176 | 3652 | fjp | rows = geoAux;
|
177 | 1291 | fernando | relations.clear();
|
178 | relations.putAll(aux);
|
||
179 | 3996 | caballero | */
|
180 | 3835 | caballero | |
181 | 1251 | vcaballero | } |
182 | |||
183 | /**
|
||
184 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRowCount()
|
185 | 1251 | vcaballero | */
|
186 | 3996 | caballero | /*public int getRowCount() {
|
187 | 3652 | fjp | return rows.size() - invalidRows.cardinality();
|
188 | 1251 | vcaballero | }
|
189 | 3996 | caballero | */
|
190 | 3652 | fjp | public void deleteLastRow() { |
191 | 3996 | caballero | //invalidRows.set(rows.size()-1,false);
|
192 | 3652 | fjp | rows.remove(rows.size()-1);
|
193 | 3835 | caballero | |
194 | 3652 | fjp | } |
195 | 3653 | fjp | |
196 | public void open() throws IOException { |
||
197 | // TODO Auto-generated method stub
|
||
198 | 3835 | caballero | |
199 | 3653 | fjp | } |
200 | |||
201 | public void close() throws IOException { |
||
202 | 6127 | fjp | rows.clear(); |
203 | 10234 | caballero | System.gc();
|
204 | 3653 | fjp | } |
205 | 3835 | caballero | |
206 | 4191 | fjp | public int getSize() { |
207 | return rows.size();
|
||
208 | } |
||
209 | |||
210 | 3835 | caballero | /* (non-Javadoc)
|
211 | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#validateRow(int)
|
||
212 | */
|
||
213 | 3996 | caballero | /*public void validateRow(int previousExpansionFileIndex) {
|
214 | 3835 | caballero | invalidRows.set(previousExpansionFileIndex, false);
|
215 | }
|
||
216 | 3996 | caballero | |
217 | public BitSet getInvalidRows() {
|
||
218 | return invalidRows;
|
||
219 | }*/
|
||
220 | 1251 | vcaballero | } |