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