Seah Eu Jin, Assignment 1. Handle error for null command in PoolBasedSequentialScheduledExecutorService.java & Refactor code readability and maintainability #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
### Assignment Part 1, WIF3005 SME, Seah Eu Jin, S2130467
Reengineering tasks chosen are Code Refactoring and Improve Error Handling.
File chosen to be worked at is openhab-core/bundles/org.openhab.core/src/main/java/org/openhab/core/common/PoolBasedSequentialScheduledExecutorService.java
Check on head 1111444 with commit message "[Added changes on code for refactoring]", the first commit did not receive the code changes
Improve Error Handling tasks:
I create validateCommand() method here because validate a command/callable before passing into concurrent/parallel service is important as it may cause a catastrophic failure in an application when the service is needed and being called.
Code Refactoring
The shutdownNow() method's code is now cleaner and more readability with higher maintainability as the method are commented in details and operation part is being represented by a new method. The core logic for this method is now being handle by cleanupScheduledTasks() while the shutdownNow() handles the flow for the operation. Thus, achieved code clarity and readability, and as the core logic is extracted into a single method (originally cramped inside shutdownNow()), it improved the maintainability for such operation.
The code for these methods had indentation not following good coding practice and inconsistent. Indentation and brackets were corrected, then the common spacing between lines are being adjust. Thus, readability for the code and method are being improved.
Originally using a method that needed return value, but did not make use of the returned value, leading to waste of computation cost in terms of time for processing the return value and passing boolean value. After being modified, the method now make use of forEach loop, clearly stated operation on each object. Thus improved readability and indirectly done code optimization (although it is minimal).