svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / MemoryExpansionFile.java @ 3836
History | View | Annotate | Download (4.1 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 | 3612 | fjp | import com.iver.cit.gvsig.fmap.core.IFeature; |
44 | 1251 | vcaballero | import com.iver.cit.gvsig.fmap.core.IGeometry; |
45 | 3651 | fjp | import com.iver.cit.gvsig.fmap.core.IRow; |
46 | 1251 | vcaballero | |
47 | import java.io.IOException; |
||
48 | 1291 | fernando | |
49 | 1251 | vcaballero | import java.util.ArrayList; |
50 | import java.util.BitSet; |
||
51 | 1287 | vcaballero | import java.util.HashMap; |
52 | import java.util.Iterator; |
||
53 | 1251 | vcaballero | |
54 | |||
55 | /**
|
||
56 | * Implementaci?n de prueba en memoria de ExpansionFile.
|
||
57 | *
|
||
58 | * @author Vicente Caballero Navarro
|
||
59 | */
|
||
60 | public class MemoryExpansionFile implements ExpansionFile { |
||
61 | 3652 | fjp | ArrayList rows = new ArrayList(); |
62 | 3651 | fjp | BitSet invalidRows = new BitSet(); |
63 | 1251 | vcaballero | /**
|
64 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#addRow(IRow)
|
65 | 1251 | vcaballero | */
|
66 | 3651 | fjp | public int addRow(IRow row) throws IOException { |
67 | 3835 | caballero | IRowEdited edRow = new DefaultRowEdited(row,
|
68 | 3653 | fjp | IRowEdited.STATUS_ADDED); |
69 | rows.add(edRow); |
||
70 | 1251 | vcaballero | |
71 | 3652 | fjp | return rows.size() - 1; |
72 | 1251 | vcaballero | } |
73 | |||
74 | /**
|
||
75 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#modifyRow(int,
|
76 | * IRow)
|
||
77 | 1251 | vcaballero | */
|
78 | 3651 | fjp | public int modifyRow(int index, IRow row) throws IOException { |
79 | if (invalidRows.get(index)) {
|
||
80 | 1291 | fernando | throw new RuntimeException( |
81 | "Se ha intentado modificar una geometr?a que ha sido borrada anteriormente");
|
||
82 | } |
||
83 | |||
84 | 3651 | fjp | invalidateRow(index); |
85 | 3835 | caballero | IRowEdited edRow = new DefaultRowEdited(row,
|
86 | 3653 | fjp | IRowEdited.STATUS_MODIFIED); |
87 | 3835 | caballero | |
88 | 3653 | fjp | rows.add(edRow); |
89 | 1251 | vcaballero | |
90 | 3652 | fjp | return rows.size() - 1; |
91 | 1251 | vcaballero | } |
92 | |||
93 | /**
|
||
94 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRow(int)
|
95 | 1251 | vcaballero | */
|
96 | 3653 | fjp | public IRowEdited getRow(int index) throws IOException { |
97 | 3651 | fjp | if (invalidRows.get(index)) {
|
98 | 1251 | vcaballero | return null; |
99 | } |
||
100 | 1291 | fernando | |
101 | 3653 | fjp | return (IRowEdited) rows.get(index);
|
102 | 1251 | vcaballero | } |
103 | |||
104 | /**
|
||
105 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#invalidateRow(int)
|
106 | 1251 | vcaballero | */
|
107 | 3651 | fjp | public void invalidateRow(int index) { |
108 | invalidRows.set(index, true);
|
||
109 | 1251 | vcaballero | } |
110 | |||
111 | /**
|
||
112 | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#compact()
|
||
113 | */
|
||
114 | 1287 | vcaballero | public void compact(HashMap relations) { |
115 | 1291 | fernando | ArrayList geoAux = new ArrayList(); |
116 | Iterator iter = relations.keySet().iterator();
|
||
117 | HashMap aux = new HashMap(); |
||
118 | int n = 0; |
||
119 | 3835 | caballero | |
120 | 1287 | vcaballero | while (iter.hasNext()) {
|
121 | 1291 | fernando | Integer virtualIndex = (Integer) iter.next(); |
122 | Integer expansionIndex = (Integer) relations.get(virtualIndex); |
||
123 | 3835 | caballero | |
124 | 3651 | fjp | if (!invalidRows.get(expansionIndex.intValue())){
|
125 | 3652 | fjp | geoAux.add(rows.get(expansionIndex.intValue())); |
126 | 1291 | fernando | aux.put(new Integer(n), new Integer(geoAux.size()-1)); |
127 | 1287 | vcaballero | n++; |
128 | } |
||
129 | } |
||
130 | 1291 | fernando | |
131 | 3651 | fjp | invalidRows.clear(); |
132 | 3652 | fjp | rows = geoAux; |
133 | 1291 | fernando | relations.clear(); |
134 | relations.putAll(aux); |
||
135 | 3835 | caballero | |
136 | |||
137 | 1251 | vcaballero | } |
138 | |||
139 | /**
|
||
140 | 3651 | fjp | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRowCount()
|
141 | 1251 | vcaballero | */
|
142 | 3651 | fjp | public int getRowCount() { |
143 | 3652 | fjp | return rows.size() - invalidRows.cardinality();
|
144 | 1251 | vcaballero | } |
145 | 3652 | fjp | |
146 | public void deleteLastRow() { |
||
147 | invalidRows.set(rows.size()-1,false); |
||
148 | rows.remove(rows.size()-1);
|
||
149 | 3835 | caballero | |
150 | 3652 | fjp | } |
151 | 3653 | fjp | |
152 | public void open() throws IOException { |
||
153 | // TODO Auto-generated method stub
|
||
154 | 3835 | caballero | |
155 | 3653 | fjp | } |
156 | |||
157 | public void close() throws IOException { |
||
158 | // TODO Auto-generated method stub
|
||
159 | 3835 | caballero | |
160 | 3653 | fjp | } |
161 | 3835 | caballero | |
162 | /* (non-Javadoc)
|
||
163 | * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#validateRow(int)
|
||
164 | */
|
||
165 | public void validateRow(int previousExpansionFileIndex) { |
||
166 | invalidRows.set(previousExpansionFileIndex, false);
|
||
167 | } |
||
168 | 1251 | vcaballero | } |