Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

Commit

Permalink
style(clean code): all
Browse files Browse the repository at this point in the history
  • Loading branch information
galexbh committed Mar 15, 2022
1 parent cd72b37 commit f75c852
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 488 deletions.
26 changes: 13 additions & 13 deletions src/main/java/com/unah/planners/controller/HRRNController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.unah.planners.controller;

import com.unah.planners.process.ProcessSRT;
import com.unah.planners.process.SRTProcess;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -33,10 +33,10 @@ public class HRRNController implements Initializable {
@FXML
private Button applyPlannerButton;

private ObservableList<ProcessSRT> processes = FXCollections.observableArrayList();
private ObservableList<ProcessSRT> waitingProcesses = FXCollections.observableArrayList();
private ObservableList<SRTProcess> processes = FXCollections.observableArrayList();
private ObservableList<SRTProcess> waitingProcesses = FXCollections.observableArrayList();

private ProcessSRT runningProcess;
private SRTProcess runningProcess;

@Override
public void initialize(URL location, ResourceBundle resources) {
Expand All @@ -57,7 +57,7 @@ public void initialize(URL location, ResourceBundle resources) {
@FXML
private void addProcess() {
proccessTable.getChildren().add(createProcess(processIdentifier.getText()));
ProcessSRT tempProcess = new ProcessSRT();
SRTProcess tempProcess = new SRTProcess();
tempProcess.setProcessIdentifier(processIdentifier.getText());
tempProcess.setArrivalTime(Integer.parseInt(arrivalTime.getText()) - 1);
tempProcess.setServiceTime(Integer.parseInt(serviceTime.getText()));
Expand Down Expand Up @@ -147,7 +147,7 @@ private void applyPlanner() {
processes.remove(runningProcess);
for (int i = runningProcess.getArrivalTime(); i < quantum; i++) {
if (!processes.isEmpty()) {
ProcessSRT tempProcess = checkProcessStart(i);
SRTProcess tempProcess = checkProcessStart(i);
if (tempProcess != null) {
if (runningProcess.getServiceTime() == 0) {
runningProcess = tempProcess;
Expand Down Expand Up @@ -185,8 +185,8 @@ private void applyPlanner() {
}
}

private ProcessSRT getFirtProcess() {
ProcessSRT firtProcessList;
private SRTProcess getFirtProcess() {
SRTProcess firtProcessList;
int smallerNumber = processes.get(0).getArrivalTime();
int posSmallerNumber = 0;
for (int i = 1; i < processes.size(); i++) {
Expand All @@ -201,18 +201,18 @@ private ProcessSRT getFirtProcess() {

}

private ProcessSRT checkProcessStart(int position) {
ProcessSRT tempProcess = null;
for (ProcessSRT process : processes) {
private SRTProcess checkProcessStart(int position) {
SRTProcess tempProcess = null;
for (SRTProcess process : processes) {
if (process.getArrivalTime() == position) {
tempProcess = process;
}
}
return tempProcess;
}

private ProcessSRT getLowerResponseRate(int position) {
ProcessSRT bestProcess;
private SRTProcess getLowerResponseRate(int position) {
SRTProcess bestProcess;
double smallerNumber = (((waitingProcesses.get(0).getArrivalTime() - (double) position) + waitingProcesses.get(0).getServiceTime()) / waitingProcesses.get(0).getServiceTime());
int posSmallerNumber = 0;
for (int i = 1; i < waitingProcesses.size(); i++) {
Expand Down
254 changes: 127 additions & 127 deletions src/main/java/com/unah/planners/controller/JSFController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.net.URL;
import java.util.ResourceBundle;

import com.unah.planners.process.Process;
import com.unah.planners.process.JSFProcess;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
Expand All @@ -19,132 +19,132 @@

public class JSFController implements Initializable {

@FXML private TableColumn<Process, String> name;
@FXML private TableColumn<Process, Number> timeArrival;
@FXML private TableColumn<Process, Number> timeService;
@FXML private TableColumn<Process, Number> timeStay;
@FXML private TableColumn<Process, Number> timeWaiting;
@FXML private TableColumn<Process, Number> timeStart;
@FXML private TableColumn<Process, Number> timeFinalize;
@FXML private TableColumn<Process, Float> timeNormalized;
@FXML private TextField txtTimeArrival;
@FXML private TextField txtName;
@FXML private TextField txtQuantun;
@FXML private TextField txtTimeService;
@FXML private Button btnAlgorithm;
@FXML private Button btnAddProcess;
@FXML private Button btnNewProcesses;

@FXML private TableView<Process> tbTable;
@FXML private ListView<String> lstProcesses;

private ObservableList<Process> contentTable;
@FXML
private TableColumn<JSFProcess, String> name;
@FXML
private TableColumn<JSFProcess, Number> timeArrival;
@FXML
private TableColumn<JSFProcess, Number> timeService;
@FXML
private TableColumn<JSFProcess, Number> timeStay;
@FXML
private TableColumn<JSFProcess, Number> timeWaiting;
@FXML
private TableColumn<JSFProcess, Number> timeStart;
@FXML
private TableColumn<JSFProcess, Number> timeFinalize;
@FXML
private TableColumn<JSFProcess, Float> timeNormalized;
@FXML
private TextField txtTimeArrival;
@FXML
private TextField txtName;
@FXML
private TextField txtQuantun;
@FXML
private TextField txtTimeService;
@FXML
private Button btnAlgorithm;
@FXML
private Button btnAddProcess;
@FXML
private Button btnNewProcesses;

@FXML
private TableView<JSFProcess> tbTable;
@FXML
private ListView<String> lstProcesses;

private ObservableList<JSFProcess> contentTable;

private ObservableList<String> processes;

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
instantiateObservableList();



lstProcesses.setItems(processes);


}

public void instantiateObservableList() {

contentTable = FXCollections.observableArrayList();
processes = FXCollections.observableArrayList();
}

@FXML
public void addProcess() {
contentTable.add(new Process(txtName.getText(),
Integer.parseInt(txtQuantun.getText()),
Integer.parseInt(txtTimeArrival.getText()),
Integer.parseInt(txtTimeService.getText()
))
);
processes.add(txtName.getText());
times();
System.out.println("------------------------------------");
cleanRegistry();
btnAlgorithm.setDisable(false);
}

public void cleanRegistry() {
txtName.clear();
txtQuantun.clear();
txtTimeArrival.clear();
txtTimeService.clear();
}

public void times() {
contentTable.get(0).timeStartJSF(contentTable);
for(int i = 0; i<contentTable.size(); i++) {
// contentTable.get(i).timeStartJSF(contentTable);
contentTable.get(i).timeWaitingFF();
contentTable.get(i).timeFinalizeFF();
contentTable.get(i).timeStayFF();
contentTable.get(i).timeNormalizedFF();
}
}

@FXML
public void applyAlgorithm() {
// times();
btnAddProcess.setDisable(true);
btnAlgorithm.setDisable(true);
btnNewProcesses.setDisable(false);
tbTable.setItems(contentTable);
bindColumns();
}

public void bindColumns() {
bindStringColumn(name,"name");
bindNumberColumn(timeArrival,"timeArrival");
bindNumberColumn(timeService,"timeService");
bindNumberColumn(timeStay,"timeStay");
bindNumberColumn(timeWaiting,"timeWaiting");
bindNumberColumn(timeStart,"timeStart");
bindNumberColumn(timeFinalize,"timeFinalize");
bindFloatColumn(timeNormalized,"timeNormalized");
}

@FXML
public void newProcesses() {
ObservableList<Process> vacio = FXCollections.observableArrayList();
tbTable.getItems().clear();
tbTable.setItems(vacio);
processes.clear();
cleanRegistry();
btnAddProcess.setDisable(false);
btnNewProcesses.setDisable(true);
}

public void deleteProcess(ObservableList<Process> obs,int index) {obs.remove(index);}


public static void chargeComboBoxNumerico(ObservableList<Integer> obs,int j) {
int i=0;
while(i<j) {
obs.add(Integer.valueOf(i));
i++;
}
}
public static void deleteOptionComboBox(ObservableList<Integer> obs, int index) {obs.remove(index);}


public static void bindStringColumn(TableColumn<Process, String> instanciaClm, String identificador) {
instanciaClm.setCellValueFactory(new PropertyValueFactory<Process, String>(identificador));
}
public static void bindNumberColumn(TableColumn<Process, Number> instanciaClm, String identificador) {
instanciaClm.setCellValueFactory(new PropertyValueFactory<Process, Number>(identificador));
}
public static void bindFloatColumn(TableColumn<Process, Float> instanciaClm, String identificador) {
instanciaClm.setCellValueFactory(new PropertyValueFactory<Process, Float>(identificador));
}


@Override
public void initialize(URL arg0, ResourceBundle arg1) {
instantiateObservableList();

lstProcesses.setItems(processes);

}

public void instantiateObservableList() {

contentTable = FXCollections.observableArrayList();
processes = FXCollections.observableArrayList();
}

@FXML
public void addProcess() {
contentTable.add(new JSFProcess(txtName.getText(),
Integer.parseInt(txtQuantun.getText()),
Integer.parseInt(txtTimeArrival.getText()),
Integer.parseInt(txtTimeService.getText()
))
);
processes.add(txtName.getText());
times();
cleanRegistry();
btnAlgorithm.setDisable(false);
}

public void cleanRegistry() {
txtName.clear();
txtQuantun.clear();
txtTimeArrival.clear();
txtTimeService.clear();
}

public void times() {
contentTable.get(0).timeStartJSF(contentTable);
for (int i = 0; i < contentTable.size(); i++) {
contentTable.get(i).timeWaitingFF();
contentTable.get(i).timeFinalizeFF();
contentTable.get(i).timeStayFF();
contentTable.get(i).timeNormalizedFF();
}
}

@FXML
public void applyAlgorithm() {
btnAddProcess.setDisable(true);
btnAlgorithm.setDisable(true);
btnNewProcesses.setDisable(false);
tbTable.setItems(contentTable);
bindColumns();
}

public void bindColumns() {
bindStringColumn(name, "name");
bindNumberColumn(timeArrival, "timeArrival");
bindNumberColumn(timeService, "timeService");
bindNumberColumn(timeStay, "timeStay");
bindNumberColumn(timeWaiting, "timeWaiting");
bindNumberColumn(timeStart, "timeStart");
bindNumberColumn(timeFinalize, "timeFinalize");
bindFloatColumn(timeNormalized, "timeNormalized");
}

@FXML
public void newProcesses() {
ObservableList<JSFProcess> vacio = FXCollections.observableArrayList();
tbTable.getItems().clear();
tbTable.setItems(vacio);
processes.clear();
cleanRegistry();
btnAddProcess.setDisable(false);
btnNewProcesses.setDisable(true);
}

public static void bindStringColumn(TableColumn<JSFProcess, String> instanciaClm, String identificador) {
instanciaClm.setCellValueFactory(new PropertyValueFactory<>(identificador));
}

public static void bindNumberColumn(TableColumn<JSFProcess, Number> instanciaClm, String identificador) {
instanciaClm.setCellValueFactory(new PropertyValueFactory<>(identificador));
}

public static void bindFloatColumn(TableColumn<JSFProcess, Float> instanciaClm, String identificador) {
instanciaClm.setCellValueFactory(new PropertyValueFactory<>(identificador));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public void onOpenForm(ActionEvent actionEvent) throws IOException {
switch (value) {
case 1 -> fxmlLoader = loadForm("/com/unah/planners/fifo-view.fxml");
case 2 -> fxmlLoader = loadForm("/com/unah/planners/round-robin-view.fxml");
case 3 -> fxmlLoader = loadForm("/com/unah/planners/JSF-view.fxml");
case 4 -> fxmlLoader = loadForm("/com/unah/planners/SRT-view.fxml");
case 5 -> fxmlLoader = loadForm("/com/unah/planners/HRRN-view.fxml");
case 3 -> fxmlLoader = loadForm("/com/unah/planners/jsf-view.fxml");
case 4 -> fxmlLoader = loadForm("/com/unah/planners/srt-view.fxml");
case 5 -> fxmlLoader = loadForm("/com/unah/planners/hrrn-view.fxml");
}

Parent root = fxmlLoader.load();
Expand Down
Loading

0 comments on commit f75c852

Please sign in to comment.