-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnweisung.java
More file actions
134 lines (120 loc) · 2.95 KB
/
Copy pathAnweisung.java
File metadata and controls
134 lines (120 loc) · 2.95 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package scheduler2PL;
public class Anweisung
{
private final AnweisungsTyp typ;
private final Process process;
private final Variable variable;
private Status status = Status.OPEN;
public Anweisung(String anweisung)
{
typ = parseAnweisungsTyp(anweisung);
process = Process.getAProcess(parseProcessId(anweisung));
if (typ == AnweisungsTyp.R | typ == AnweisungsTyp.W)
{
variable = parseVariable(anweisung);
}
else
{
variable = null;
}
}
public static Variable parseVariable(String anweisung)
{
return Variable.getAVariable(anweisung.charAt(anweisung.length() - 2));
}
public static int parseProcessId(String anweisung)
{
return Integer.parseInt("" + anweisung.charAt(1));
}
public static AnweisungsTyp parseAnweisungsTyp(String anweisung)
{
switch (anweisung.toUpperCase().charAt(0))
{
case 'R':
return AnweisungsTyp.R;
case 'W':
return AnweisungsTyp.W;
case 'C':
return AnweisungsTyp.C;
default:
System.err.println("Type nicht erkannt bei String: " + anweisung);
return AnweisungsTyp.E;
}
}
public AnweisungsTyp getAnweisungsTyp()
{
return typ;
}
public Process getProcess()
{
return process;
}
public Variable getVariable()
{
return variable;
}
@Override
public String toString()
{
StringBuilder r = new StringBuilder();
switch (typ)
{
case R:
r.append("r");
break;
case W:
r.append("w");
break;
case C:
r.append("c");
break;
case E:
return "Die Anweisung war Fehlerhaft.";
}
r.append(process.toString());
if (variable != null)
{
r.append('(');
r.append(variable.toString());
r.append(')');
}
return r.toString();
}
public boolean work(boolean debugPrint)
{
if (status == Status.DONE)
{
return false;
}
return process.work(this, debugPrint);
}
public Status getStatus()
{
if (status == Status.DONE)
{
return Status.DONE;
}
return process.getStatus();
}
public void setDone()
{
status = Status.DONE;
}
public static String toStringArray(Anweisung[] anweisungen)
{
StringBuilder r = new StringBuilder();
for (int i = 0; i < anweisungen.length; i++)
{
if (i != 0)
{
r.append(", ");
}
r.append(anweisungen[i].toString());
}
return r.toString();
}
public static void printArray(Anweisung[] anweisungen)
{
System.out.println(toStringArray(anweisungen));
}
}