forked from inesxferreira/SD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodUser.java
35 lines (30 loc) · 824 Bytes
/
CodUser.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
import java.io.*;
import java.util.HashMap;
import java.util.concurrent.locks.ReentrantLock;
public class CodUser {
private HashMap<String, Positions> codReservaOrigem;
public ReentrantLock l = new ReentrantLock();
public int codReserva = 0;
public CodUser(){
this.codReservaOrigem = new HashMap<>();
}
public String makeCodReserva() {
l.lock();
try {
int n;
this.codReserva++;
n= this.codReserva;
return Integer.toString(n);
} finally {
l.unlock();
}
}
public void addCod(String cod, Positions origem) {
l.lock();
codReservaOrigem.put(cod, origem);
l.unlock();
}
public Positions getOrigem(String cod) {
return codReservaOrigem.get(cod);
}
}