From c7da225c1f426ae01f0681cadf0e8de372ed4b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Cordier?= Date: Wed, 17 May 2023 09:57:23 +0200 Subject: [PATCH] Use or operators to test the equality of enums --- CHANGELOG.md | 1 + .../core/task/update/TaskUpdateManager.java | 30 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0f18f8a..877610dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java index c447a4c4..bf818527 100644 --- a/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java +++ b/src/main/java/com/iexec/core/task/update/TaskUpdateManager.java @@ -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:{}]", @@ -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 @@ -289,7 +289,7 @@ 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); @@ -297,7 +297,7 @@ void initialized2Running(Task task) { } void running2ConsensusReached(Task task) { - boolean isTaskInRunningStatus = task.getCurrentStatus().equals(RUNNING); + boolean isTaskInRunningStatus = task.getCurrentStatus() == RUNNING; final String chainTaskId = task.getChainTaskId(); final Optional oReplicatesList = replicatesService.getReplicatesList(chainTaskId); if (oReplicatesList.isEmpty()) { @@ -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 oReplicatesList = replicatesService.getReplicatesList(chainTaskId); @@ -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) { @@ -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; } @@ -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) { @@ -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; @@ -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())) { @@ -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 oUploadedReplicate = replicatesService.getReplicateWithResultUploadedStatus(task.getChainTaskId()); boolean didReplicateUpload = oUploadedReplicate.isPresent(); @@ -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()); @@ -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 optional = iexecHubService.getChainTask(task.getChainTaskId()); @@ -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);