/
NetworksData.java
90 lines (78 loc) · 1.89 KB
/
NetworksData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.LinkedList;
public class NetworksData
{
private HashMap<Integer,Integer> mapNet;
private HashMap<String,Integer> mapNodi;
private LinkedList<Grafo> gList;
private int cont;
private int i;
public NetworksData()
{
mapNet=new HashMap<Integer,Integer>();
mapNodi=new HashMap<String,Integer>();
gList=new LinkedList<Grafo>();
cont=0;
i=0;
}
public void newNetwork(String fname, String name) throws Exception
{
//Costruzione network
int index=name.indexOf(".");
Grafo g=new Grafo(name.substring(0,index));
BufferedReader br=new BufferedReader(new FileReader(fname));
//JOptionPane.showMessageDialog(adapter.getCySwingApplication().getJFrame(), task.getError());
String str="";
while((str=br.readLine())!=null)
{
String[] campi=str.split("\t");
String idSource=campi[0].trim();
String idDest=campi[1].trim();
double weight=Double.parseDouble(campi[2]);
if(!mapNodi.containsKey(idSource))
{
g.addNode(cont,idSource);
mapNet.put(cont,i);
mapNodi.put(idSource,cont);
cont++;
}
if(!mapNodi.containsKey(idDest))
{
g.addNode(cont,idDest);
mapNet.put(cont,i);
mapNodi.put(idDest, cont);
cont++;
}
g.addArc(mapNodi.get(idSource), mapNodi.get(idDest), weight);
}
br.close();
gList.add(g);
i++;
}
public LinkedList<Grafo> getGList()
{
return gList;
}
public HashMap<Integer, Integer> getMapNet()
{
return mapNet;
}
public HashMap<String, Integer> getMapNodi()
{
return mapNodi;
}
public void deleteAll()
{
gList=new LinkedList<Grafo>();
mapNodi=new HashMap<String,Integer>();
mapNet=new HashMap<Integer,Integer>();
cont=0;
i=0;
}
public boolean isEmpty()
{
return (gList.isEmpty() && mapNodi.isEmpty() && mapNet.isEmpty() && cont==0 && i==0);
}
}