JDA icon indicating copy to clipboard operation
JDA copied to clipboard

Refactored verbose code constructs and QoL improvements

Open Cespito opened this issue 1 year ago • 0 comments

Pull Request Etiquette

  • [x] I have checked the PRs for upcoming features/bug fixes.
  • [x] I have read the [contributing guidelines][contributing].

Changes

  • [x] Internal code
  • [ ] Library interface (affecting end-user code)
  • [ ] Documentation
  • [ ] Other: _____

Closes Issue: NaN

Description

This pull request makes the following improvements:

  • Refactor verbose code constructs
  • Fix raw use of parameterized class
  • Delete unnecessary import

Details

  • Added lambda expressions and utilized library methods to reduce code verbosity
  • Removed unnecessary cast expressions
  • Such raw use of generic types is valid in Java, but it defeats the purpose of type parameters and may mask bugs
  • Replaced C like implementations in Java classes
  • Removed unused imports
  • Added log in exception catch on awaitReady() function
  • Simplified this construct
if (currentIterator != null)
{
    if (!currentIterator.hasNext())
    {
        currentIterator.close();
        currentIterator = null;
    }
    else
    {
        if (findNext()) return true;
        currentIterator.close();
        currentIterator = null;
        }
    }

with

if (currentIterator != null)
{
    if (currentIterator.hasNext())
    {
        if (findNext()) return true;
    }
    currentIterator.close();
    currentIterator = null;
}

Benefits Improved code organization, maintainability, and readability. Reduced redundancy and enhanced robustness of the code.

Cespito avatar Feb 26 '24 11:02 Cespito