Skip to content

Refactor collection instantiation to use factory methods#37

Merged
mercyblitz merged 3 commits into
mainfrom
copilot/refactor-factory-methods
May 30, 2026
Merged

Refactor collection instantiation to use factory methods#37
mercyblitz merged 3 commits into
mainfrom
copilot/refactor-factory-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

Refactor collection constructors to use factory methods from microsphere collection utilities, improving code consistency and maintainability across the codebase.

Changes

  • ListUtils factory methods: Replaced new ArrayList<>() and new LinkedList<>() with newArrayList() and newLinkedList() respectively
  • MapUtils factory methods: Replaced new HashMap<>() with newHashMap()
  • Import statements: Added static imports for factory methods without wildcards; removed direct collection class imports where no longer needed
  • Files refactored: 5 files across 3 modules (logging-commons, log4j2, logging-test)

Example

// Before
import java.util.HashMap;
private Map<String, Layout> delegatingLayouts = new HashMap<>();

// After
import static io.microsphere.collection.MapUtils.newHashMap;
private Map<String, Layout> delegatingLayouts = newHashMap();

@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented May 30, 2026

🤖 Augment PR Summary

Summary: Refactors several modules to instantiate collections via Microsphere collection factory methods instead of direct constructors.

Changes:

  • Replaced direct uses of new HashMap/ArrayList/LinkedList with MapUtils.newHashMap and ListUtils.newArrayList/newLinkedList
  • Updated imports to use explicit static factory imports for consistency

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@Override
public List<Extension> getAdditionalExtensions() {
List<Extension> extensions = new ArrayList<>(this.isClassTemplate ? 2 : 1);
List<Extension> extensions = newArrayList();
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extensions is declared as java.util.List, but ensureCapacity(...) is not a List method (it’s specific to ArrayList), so this line won’t compile as written.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Replace the two-step creation (newArrayList() + ensureCapacity(...)) with a single newArrayList(initialCapacity) when building the extensions list in LoggingLevelTemplateInvocationContext#getAdditionalExtensions. This simplifies the code and makes the intended initial capacity explicit without changing behavior.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 30, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...logging/log4j2/layout/SmartFileAppenderLayout.java 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ Complexity Δ
...icrosphere/logging/jmx/LoggingMXBeanRegistrar.java 100.00% <100.00%> (ø) 11.00 <3.00> (ø)
...logging/LoggingLevelTemplateInvocationContext.java 100.00% <ø> (ø) 6.00 <0.00> (ø)
...logging/log4j2/layout/SmartFileAppenderLayout.java 41.30% <0.00%> (ø) 11.00 <0.00> (ø)

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mercyblitz mercyblitz merged commit c401c5c into main May 30, 2026
5 of 6 checks passed
@mercyblitz mercyblitz deleted the copilot/refactor-factory-methods branch May 30, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants