-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMyThread.java
105 lines (96 loc) · 2.64 KB
/
MyThread.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package lab1;
import java.util.ArrayList;
import java.util.Scanner;
class MyThread implements Runnable {
private Graph G;
private String presentWord;
private StringBuffer path = new StringBuffer();
private static int autoProcess;
private static boolean finish = false;
Thread t;
private boolean stop = false;
private Thread others;
private boolean terminate = false;
public Thread getThread(){
return t;
}
public MyThread(Graph G, String presentWord) {
// TODO Auto-generated constructor stub
this.G = G;
this.presentWord = presentWord;
autoProcess = 1;
t = new Thread(this,"secondThread");
System.out.println(t);
t.start();
}
public MyThread(boolean stop, Thread others) {
// TODO Auto-generated constructor stub
this.stop = stop;
this.others = others;
autoProcess = 0;
t = new Thread(this,"thirdThread");
System.out.println(t);
t.start();
}
public String getPath(){
return path.toString();
}
@Override
public void run() {
if(stop == true){
String s = null;
Scanner in = new Scanner(System.in);
//while(!terminate){
while(true){
s = in.nextLine();
if(s.isEmpty()){
// if(finish == false)
finish = true;
//else
// finish = false;
break;
}
}
}
else{
ArrayList<Edge> edges = new ArrayList<>();
String nextWord = null;
Edge tempEdge = null;
//presentWord = "civilizations";
path.append(presentWord);
while(!finish||autoProcess == 1) {
nextWord = mainWindow.moveOneStep(G, presentWord, path.toString());
if(G.getNodeList().get(presentWord)!=null&&nextWord!=null){
tempEdge = G.getNodeList().get(presentWord).get(nextWord);
presentWord = nextWord;
path.append("->" + presentWord);
System.out.println(path.toString());
if(!edges.contains(tempEdge))
edges.add(tempEdge);
else{
//terminate = true;
break;
}
}
else{
//terminate = true;
break;
}
try {
if(autoProcess == 0){
Thread.sleep(2000);
}
else{
Scanner in = new Scanner(System.in);
String s = in.nextLine();
while(!s.isEmpty()){
s = in.nextLine();
};
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
};