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