Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use or operators to test the equality of enums #584

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- Clean unused Replicate methods and update tests. (#573)
- Clean unused `ReplicateStatus#RESULT_UPLOAD_REQUEST_FAILED`. (#575)
- Refactor unnotified detectors to avoid code duplication. (#580)
- Use `==` or `!=` operators to test the equality of enums. (#584)
### Dependency Upgrades
- Upgrade to `iexec-common` 8.0.0-NEXT-SNAPSHOT. (#571 #575)
- Add new `iexec-commons-poco` 1.0.2-NEXT-SNAPSHOT dependency. (#571 #574)
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/iexec/core/task/update/TaskUpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Task updateTaskStatusAndSave(Task task, TaskStatus newStatus, ChainReceipt chain
}

void received2Initializing(Task task) {
boolean isCurrentStatusReceived = task.getCurrentStatus().equals(RECEIVED);
boolean isCurrentStatusReceived = task.getCurrentStatus() == RECEIVED;

if (!isCurrentStatusReceived) {
log.error("Cannot initialize task [chainTaskId:{}, currentStatus:{}]",
Expand Down Expand Up @@ -242,7 +242,7 @@ void received2Initializing(Task task) {
}

void initializing2Initialized(Task task) {
if (!INITIALIZING.equals(task.getCurrentStatus())) {
if (INITIALIZING != task.getCurrentStatus()) {
return;
}
// TODO: the block where initialization happened can be found
Expand Down Expand Up @@ -289,15 +289,15 @@ void initialized2Running(Task task) {
};
final int nbReplicatesContainingStartingStatus = replicatesService.getNbReplicatesWithLastRelevantStatus(chainTaskId, acceptableStatus);
boolean condition1 = nbReplicatesContainingStartingStatus > 0;
boolean condition2 = task.getCurrentStatus().equals(INITIALIZED);
boolean condition2 = task.getCurrentStatus() == INITIALIZED;

if (condition1 && condition2) {
updateTaskStatusAndSave(task, RUNNING);
}
}

void running2ConsensusReached(Task task) {
boolean isTaskInRunningStatus = task.getCurrentStatus().equals(RUNNING);
boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING;
final String chainTaskId = task.getChainTaskId();
final Optional<ReplicatesList> oReplicatesList = replicatesService.getReplicatesList(chainTaskId);
if (oReplicatesList.isEmpty()) {
Expand Down Expand Up @@ -328,7 +328,7 @@ void running2ConsensusReached(Task task) {
}

void running2Finalized2Completed(Task task) {
boolean isTaskInRunningStatus = task.getCurrentStatus().equals(RUNNING);
boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING;
final String chainTaskId = task.getChainTaskId();
final Optional<ReplicatesList> oReplicatesList = replicatesService.getReplicatesList(chainTaskId);

Expand Down Expand Up @@ -368,8 +368,8 @@ void running2Finalized2Completed(Task task) {
}

void initializedOrRunning2ContributionTimeout(Task task) {
boolean isInitializedOrRunningTask = task.getCurrentStatus().equals(INITIALIZED) ||
task.getCurrentStatus().equals(RUNNING);
boolean isInitializedOrRunningTask = task.getCurrentStatus() == INITIALIZED ||
task.getCurrentStatus() == RUNNING;
boolean isNowAfterContributionDeadline = task.getContributionDeadline() != null && new Date().after(task.getContributionDeadline());

if (isInitializedOrRunningTask && isNowAfterContributionDeadline) {
Expand All @@ -391,7 +391,7 @@ void initializedOrRunning2ContributionTimeout(Task task) {
* @param task Task to check and to make become {@link TaskStatus#RUNNING_FAILED}.
*/
void running2RunningFailed(Task task) {
boolean isRunningTask = task.getCurrentStatus().equals(RUNNING);
boolean isRunningTask = task.getCurrentStatus() == RUNNING;
if (!isRunningTask || !task.isTeeTask()) {
return;
}
Expand Down Expand Up @@ -435,7 +435,7 @@ void running2RunningFailed(Task task) {
}

void consensusReached2AtLeastOneReveal2ResultUploading(Task task) {
boolean condition1 = task.getCurrentStatus().equals(CONSENSUS_REACHED);
boolean condition1 = task.getCurrentStatus() == CONSENSUS_REACHED;
boolean condition2 = replicatesService.getNbReplicatesWithCurrentStatus(task.getChainTaskId(), ReplicateStatus.REVEALED) > 0;

if (condition1 && condition2) {
Expand All @@ -447,7 +447,7 @@ void consensusReached2AtLeastOneReveal2ResultUploading(Task task) {
void consensusReached2Reopening(Task task) {
Date now = new Date();

boolean isConsensusReachedStatus = task.getCurrentStatus().equals(CONSENSUS_REACHED);
boolean isConsensusReachedStatus = task.getCurrentStatus() == CONSENSUS_REACHED;
boolean isAfterRevealDeadline = task.getRevealDeadline() != null && now.after(task.getRevealDeadline());
boolean hasAtLeastOneReveal = replicatesService.getNbReplicatesWithCurrentStatus(task.getChainTaskId(), ReplicateStatus.REVEALED) > 0;

Expand Down Expand Up @@ -488,7 +488,7 @@ void reopening2Reopened(Task task, ChainReceipt chainReceipt) {
ChainTask chainTask = oChainTask.get();

// re-initialize the task if it has been reopened
if (chainTask.getStatus().equals(ChainTaskStatus.ACTIVE)) {
if (chainTask.getStatus() == ChainTaskStatus.ACTIVE) {

// set replicates to REVEAL_TIMEOUT
for (Replicate replicate : replicatesService.getReplicates(task.getChainTaskId())) {
Expand All @@ -504,7 +504,7 @@ void reopening2Reopened(Task task, ChainReceipt chainReceipt) {
}

void resultUploading2Uploaded(Task task) {
boolean isTaskInResultUploading = task.getCurrentStatus().equals(RESULT_UPLOADING);
boolean isTaskInResultUploading = task.getCurrentStatus() == RESULT_UPLOADING;
Optional<Replicate> oUploadedReplicate = replicatesService.getReplicateWithResultUploadedStatus(task.getChainTaskId());
boolean didReplicateUpload = oUploadedReplicate.isPresent();

Expand Down Expand Up @@ -546,7 +546,7 @@ void resultUploading2Uploaded(Task task) {
}

void resultUploading2UploadTimeout(Task task) {
boolean isTaskInResultUploading = task.getCurrentStatus().equals(RESULT_UPLOADING);
boolean isTaskInResultUploading = task.getCurrentStatus() == RESULT_UPLOADING;
boolean isNowAfterFinalDeadline = task.getFinalDeadline() != null
&& new Date().after(task.getFinalDeadline());

Expand Down Expand Up @@ -585,7 +585,7 @@ void requestUpload(Task task) {
}

void resultUploaded2Finalizing(Task task) {
boolean isTaskInResultUploaded = task.getCurrentStatus().equals(RESULT_UPLOADED);
boolean isTaskInResultUploaded = task.getCurrentStatus() == RESULT_UPLOADED;
boolean canFinalize = iexecHubService.canFinalize(task.getChainTaskId());

Optional<ChainTask> optional = iexecHubService.getChainTask(task.getChainTaskId());
Expand Down Expand Up @@ -644,7 +644,7 @@ void finalizing2Finalized2Completed(Task task) {
}

void finalizedToCompleted(Task task) {
if (!task.getCurrentStatus().equals(FINALIZED)) {
if (task.getCurrentStatus() != FINALIZED) {
return;
}
updateTaskStatusAndSave(task, COMPLETED);
Expand Down