root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / graph / core / GvGraph.java @ 8700
History | View | Annotate | Download (3.08 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.graph.core; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
import java.util.Arrays; |
45 |
import java.util.Collection; |
46 |
import java.util.Hashtable; |
47 |
|
48 |
import edu.uci.ics.jung.utils.Pair; |
49 |
|
50 |
public class GvGraph implements IGraph { |
51 |
private ArrayList nodes; |
52 |
private ArrayList edges; |
53 |
private Hashtable indexArcsEdges; |
54 |
|
55 |
public GvGraph()
|
56 |
{ |
57 |
nodes = new ArrayList(); |
58 |
edges = new ArrayList(); |
59 |
indexArcsEdges = new Hashtable(); |
60 |
} |
61 |
|
62 |
public GvGraph(int numArcs, int numEdges, int numNodes) { |
63 |
nodes = new ArrayList(numNodes); |
64 |
edges = new ArrayList(numEdges); |
65 |
indexArcsEdges = new Hashtable(numArcs); |
66 |
} |
67 |
|
68 |
public GvNode getNodeByID(int idNode) { |
69 |
return (GvNode) nodes.get(idNode);
|
70 |
} |
71 |
|
72 |
public GvEdge getEdgeByID(int idEdge) { |
73 |
return (GvEdge) edges.get(idEdge);
|
74 |
} |
75 |
|
76 |
public int numVertices() { |
77 |
return nodes.size();
|
78 |
} |
79 |
|
80 |
public int numEdges() { |
81 |
return edges.size();
|
82 |
} |
83 |
|
84 |
public EdgePair getEdgesByIdArc(int idArc) { |
85 |
if (idArc < indexArcsEdges.size())
|
86 |
return (EdgePair) indexArcsEdges.get(new Integer(idArc)); |
87 |
return null; |
88 |
} |
89 |
|
90 |
public void addEdge(GvEdge edge) { |
91 |
edges.add(edge); |
92 |
} |
93 |
|
94 |
public void addNode(GvNode node) { |
95 |
nodes.add(node); |
96 |
|
97 |
} |
98 |
|
99 |
public void addEdgePair(int idArc, EdgePair edgePair) { |
100 |
// assert(indexArcsEdges.size() == edgePair.idArc);
|
101 |
indexArcsEdges.put(new Integer(idArc), edgePair); |
102 |
} |
103 |
|
104 |
/* (non-Javadoc)
|
105 |
* @see com.iver.cit.gvsig.graph.core.IGraph#removeEdge(int)
|
106 |
*/
|
107 |
public void removeEdge(int idEdge) { |
108 |
// TODO: Solo se usa para edges a?adidos debido a la incorporaci?n
|
109 |
// de flags. Si se usara para los otros arcos, habr?a que
|
110 |
// revisar indexArcsEdges para ver si es necesario quitarlo
|
111 |
// tambi?n de ah?.
|
112 |
edges.remove(idEdge); |
113 |
} |
114 |
|
115 |
public void removeNode(int idNode) { |
116 |
nodes.remove(idNode); |
117 |
} |
118 |
|
119 |
// public void addEdge(int i, GvEdge edge) {
|
120 |
// edges.set(i, edge);
|
121 |
//
|
122 |
// }
|
123 |
// public void addNode(int i, GvNode node) {
|
124 |
// nodes.set(i, node);
|
125 |
//
|
126 |
// }
|
127 |
|
128 |
|
129 |
} |
130 |
|
131 |
|