-
Notifications
You must be signed in to change notification settings - Fork 0
/
Monitor1.
110 lines (99 loc) · 2.63 KB
/
Monitor1.
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.File;
import java.util.Scanner;
public class Monitor1 {
Lock laas;
SubsekvensRegister register;
Monitor1(){
laas = new ReentrantLock();
register = new SubsekvensRegister();
}
public void settInn(HashMap<String,Subsekvens> map){
laas.lock();
try{
register.hashBeholder.add(map);
}finally{
laas.unlock();
}
}
public HashMap<String, Subsekvens> flett(HashMap<String, Subsekvens> map1, HashMap<String, Subsekvens> map2){
laas.lock();
try{
return register.flett(map1, map2);
}
finally{
laas.unlock();
}
}
public HashMap<String, Subsekvens> flettSammen(){
laas.lock();
try{
return register.flettSammen();
}
finally{
laas.unlock();
}
}
public String finnStørste(HashMap<String, Subsekvens> h){
laas.lock();
try{
return register.finnStørste(h);
}
finally{
laas.unlock();
}
}
public String finnStørste(){
laas.lock();
try{
return register.finnStørste();
}
finally{
laas.unlock();
}
}
public void lesMappe(String mappe) throws FileNotFoundException {
String loc = "./" + mappe + "/";
File metafFile = new File(loc + "metadata.csv");
Scanner scan = new Scanner(metafFile);
ArrayList<Thread> threads = new ArrayList<Thread>();
while (scan.hasNextLine()){
// Thread mintr = new Thread(new LeseTrad(loc + scan.nextLine(), this));
// threads.add(mintr);
// mintr.start();
}
threads.forEach((thr) -> {
try{
thr.join();
}
catch(Exception e){
System.out.println(e);
}
});
scan.close();
}
public HashMap<String,Subsekvens> lesFil(String fil){
laas.lock();
try{
return register.lesFil(fil);
}
catch(Exception e){
System.out.println("Problem med å lese fil. Error: " + e);
}
finally{
laas.unlock();
}
return new HashMap<String,Subsekvens>();
}
public int antall(){
return register.hashBeholder.size();
}
@Override
public String toString(){
return register.toString();
}
}