root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / MemoryExpansionFile.java @ 10627
History | View | Annotate | Download (5.86 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.util.ArrayList; |
44 |
import java.util.HashMap; |
45 |
|
46 |
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 |
import com.iver.cit.gvsig.fmap.core.IRow; |
51 |
|
52 |
|
53 |
/**
|
54 |
* Implementaci?n en memoria de ExpansionFile.
|
55 |
*
|
56 |
* @author Vicente Caballero Navarro
|
57 |
*/
|
58 |
public class MemoryExpansionFile implements ExpansionFile { |
59 |
ArrayList rows = new ArrayList(); |
60 |
EditableAdapter edAdapter; |
61 |
|
62 |
private class InternalRow |
63 |
{ |
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 |
|
79 |
public MemoryExpansionFile(EditableAdapter edAdapter)
|
80 |
{ |
81 |
this.edAdapter = edAdapter;
|
82 |
} |
83 |
|
84 |
//BitSet invalidRows = new BitSet();
|
85 |
/**
|
86 |
* @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#addRow(IRow, int)
|
87 |
*/
|
88 |
public int addRow(IRow row, int status, int indexInternalFields) throws ExpansionFileWriteException { |
89 |
int newIndex = rows.size();
|
90 |
IRowEdited edRow = new DefaultRowEdited(row,
|
91 |
status, newIndex); |
92 |
InternalRow iRow = new InternalRow(edRow, indexInternalFields);
|
93 |
rows.add(iRow); |
94 |
|
95 |
return newIndex;
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#modifyRow(int,
|
100 |
* IRow)
|
101 |
*/
|
102 |
// 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 |
|
119 |
public int modifyRow(int index, IRow row, int indexInternalFields) throws ExpansionFileWriteException { |
120 |
/*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 |
|
130 |
InternalRow iRow = new InternalRow(edRow, indexInternalFields);
|
131 |
rows.add(iRow); |
132 |
|
133 |
|
134 |
return rows.size() - 1; |
135 |
} |
136 |
|
137 |
/**
|
138 |
* @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRow(int)
|
139 |
*/
|
140 |
public IRowEdited getRow(int index) throws ExpansionFileReadException { |
141 |
/*if (invalidRows.get(index)) {
|
142 |
return null;
|
143 |
}
|
144 |
*/
|
145 |
InternalRow iRow = (InternalRow) rows.get(index); |
146 |
int indexInternalFields = iRow.getIndexInternalFields();
|
147 |
return edAdapter.createExternalRow(iRow.getRow(), indexInternalFields);
|
148 |
// return iRow.getRow();
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#invalidateRow(int)
|
153 |
*/
|
154 |
/*public void invalidateRow(int index) {
|
155 |
invalidRows.set(index, true);
|
156 |
}
|
157 |
*/
|
158 |
/**
|
159 |
* @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#compact()
|
160 |
*/
|
161 |
public void compact(HashMap relations) { |
162 |
/* ArrayList geoAux = new ArrayList();
|
163 |
Iterator iter = relations.keySet().iterator();
|
164 |
HashMap aux = new HashMap();
|
165 |
int n = 0;
|
166 |
|
167 |
while (iter.hasNext()) {
|
168 |
Integer virtualIndex = (Integer) iter.next();
|
169 |
Integer expansionIndex = (Integer) relations.get(virtualIndex);
|
170 |
|
171 |
if (!invalidRows.get(expansionIndex.intValue())){
|
172 |
geoAux.add(rows.get(expansionIndex.intValue()));
|
173 |
aux.put(new Integer(n), new Integer(geoAux.size()-1));
|
174 |
n++;
|
175 |
}
|
176 |
}
|
177 |
|
178 |
invalidRows.clear();
|
179 |
rows = geoAux;
|
180 |
relations.clear();
|
181 |
relations.putAll(aux);
|
182 |
*/
|
183 |
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRowCount()
|
188 |
*/
|
189 |
/*public int getRowCount() {
|
190 |
return rows.size() - invalidRows.cardinality();
|
191 |
}
|
192 |
*/
|
193 |
public void deleteLastRow() { |
194 |
//invalidRows.set(rows.size()-1,false);
|
195 |
rows.remove(rows.size()-1);
|
196 |
|
197 |
} |
198 |
|
199 |
public void open() throws OpenExpansionFileException { |
200 |
// TODO Auto-generated method stub
|
201 |
|
202 |
} |
203 |
|
204 |
public void close() throws CloseExpansionFileException { |
205 |
rows.clear(); |
206 |
System.gc();
|
207 |
} |
208 |
|
209 |
public int getSize() { |
210 |
return rows.size();
|
211 |
} |
212 |
|
213 |
/* (non-Javadoc)
|
214 |
* @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#validateRow(int)
|
215 |
*/
|
216 |
/*public void validateRow(int previousExpansionFileIndex) {
|
217 |
invalidRows.set(previousExpansionFileIndex, false);
|
218 |
}
|
219 |
|
220 |
public BitSet getInvalidRows() {
|
221 |
return invalidRows;
|
222 |
}*/
|
223 |
} |