-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBCP.java
More file actions
126 lines (97 loc) · 3.05 KB
/
BCP.java
File metadata and controls
126 lines (97 loc) · 3.05 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
import java.util.*;
import java.io.*;
public class BCP {
private String nomeArquivo = "";
private int prioridadeArquivo;
private int contadorDePrograma = 0;
private String cabecalho;
private String estado; // EXECUTANDO, PRONTO, BLOQUEADO
private int processosAposBloqueio = 0;
private String statusBloqueado = "";
private int regX = 0;
private int regY = 0;
private final String[] segmentoTexto;
public BCP(String nomeArquivoEntrada) throws FileNotFoundException {
Scanner scanner = new Scanner(new File(nomeArquivoEntrada));
this.segmentoTexto = new String[21];
this.cabecalho = scanner.next();
int i = 0;
while (scanner.hasNext()) {
this.segmentoTexto[i] = scanner.next();
if (this.segmentoTexto[i].equals("SAIDA")) break;
i++;
}
}
public int getPrioridadeArquivo() {
return this.prioridadeArquivo;
}
public void setPrioridadeArquivo(int prioridade) {
this.prioridadeArquivo = prioridade;
}
public String getNomeArquivo() {
return this.nomeArquivo;
}
public void setNomeArquivo(String nomeArquivo) {
this.nomeArquivo = nomeArquivo;
}
public String getStatusBloqueado() {
return this.statusBloqueado;
}
public void setStatusBloqueado(String statusBloqueado) {
this.statusBloqueado = statusBloqueado;
}
public void atualizarProcessosAposBloqueio(int num) {
this.processosAposBloqueio = num;
}
public int getProcessosAposBloqueio() {
return this.processosAposBloqueio;
}
public String getCabecalho() {
return this.cabecalho;
}
public int getContadorDePrograma() {
return this.contadorDePrograma;
}
public String getSegmentoTexto(int i) {
return this.segmentoTexto[i];
}
public String getComando() {
return this.segmentoTexto[this.contadorDePrograma];
}
public int getRegX() {
return this.regX;
}
public int getRegY() {
return this.regY;
}
public void setContadorDePrograma(int contadorDePrograma) {
this.contadorDePrograma = contadorDePrograma;
}
public void incrementaContadorDePrograma() {
this.contadorDePrograma++;
}
public void setEstadoProcesso(String estado) {
this.estado = estado;
}
public String getEstadoProcesso() {
return this.estado;
}
public void setRegX(int regX) {
this.regX = regX;
}
public void setRegY(int regY) {
this.regY = regY;
}
// Método para verificar se o processo pode ser desbloqueado e se poder desbloquear
public boolean tentarDesbloquear() {
if (!(this.processosAposBloqueio == 2)) return false;
atualizarProcessosAposBloqueio(0);
setEstadoProcesso("PRONTO");
return true;
}
public void atualizarBloqueio() {
if (!getStatusBloqueado().contains("E/S INICIADA")) {
atualizarProcessosAposBloqueio(getProcessosAposBloqueio() + 1);
}
}
}