-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.java
More file actions
87 lines (75 loc) · 1.61 KB
/
Copy pathVariable.java
File metadata and controls
87 lines (75 loc) · 1.61 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
package scheduler2PL;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Variable implements Comparable<Variable>
{
private final char var;
public static Set<Variable> liste = new HashSet<>();
public Lock lock = new Lock();
public Variable(char caracter)
{
var = caracter;
}
public static Variable getAVariable(char caracter)
{
liste.add(new Variable(caracter));
Iterator<Variable> it = liste.iterator();
while (it.hasNext())
{
Variable curent = it.next();
if (curent.equals(caracter))
{
return curent;
}
}
return null;
}
@Override
public String toString()
{
return String.valueOf(var);
}
@Override
public boolean equals(Object arg)
{
if (arg instanceof Variable)
{
return var == ((Variable) arg).var;
}
else
{
return ((Character) var).equals(arg);
}
}
public static int getLengt()
{
return liste.size();
}
@Override
public int compareTo(Variable o)
{
if (this.equals(o))
{
return 0;
}
else
{
return -1;
}
}
@Override
public int hashCode()
{
return var;
}
public static void removeLocks(Process process)
{
Iterator<Variable> it = liste.iterator();
while (it.hasNext())
{
Variable curent = it.next();
curent.lock.remove(process);
}
}
}