Skip to content

Refactor Collection instantiations to use factory methods#35

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-collection-factory-methods
Closed

Refactor Collection instantiations to use factory methods#35
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-collection-factory-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

Standardize Collection creation across the codebase to use factory methods from microsphere-collection utilities, improving code consistency and maintainability. This aligns with established patterns and enables better encapsulation of collection initialization logic.

Changes

  • ListUtils factory methods: Replaced new ArrayList<>() and new LinkedList<>() with newArrayList() and newLinkedList()
  • MapUtils factory methods: Replaced new HashMap<>() with newHashMap()
  • SetUtils factory methods: Replaced new ConcurrentSkipListSet<>() with newConcurrentSkipListSet()
  • Import statements: Added specific static imports for each factory method (no wildcard imports)

Example

// Before
List<ObjectInstance> instances = new LinkedList<>();
Map<String, Layout> delegatingLayouts = new HashMap<>();
List<Extension> extensions = new ArrayList<>(this.isClassTemplate ? 2 : 1);

// After
import static io.microsphere.collection.ListUtils.newLinkedList;
import static io.microsphere.collection.MapUtils.newHashMap;
import static io.microsphere.collection.ListUtils.newArrayList;

List<ObjectInstance> instances = newLinkedList();
Map<String, Layout> delegatingLayouts = newHashMap();
List<Extension> extensions = newArrayList(this.isClassTemplate ? 2 : 1);

Scope

  • 6 Java files refactored (4 source files, 2 test files)
  • No logic changes or JavaDoc modifications
  • All collection instantiations in the modified scope replaced with their factory method equivalents

@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented May 30, 2026

🤖 Augment PR Summary

Summary: This PR standardizes collection creation to use Microsphere collection utility factory methods.

Changes:

  • Replaced direct instantiations of ArrayList, LinkedList, HashMap, and ConcurrentSkipListSet with ListUtils/MapUtils/SetUtils factory methods
  • Added explicit static imports for the selected factory methods across main and test code

🤖 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.

private Appender selectAppender(Logger logger, Class<? extends Appender> appenderClass) {
Appender targetAppender = null;
Map<String, Appender> appendersMap = new HashMap<>(logger.getAppenders());
Map<String, Appender> appendersMap = newHashMap(logger.getAppenders());
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.

SmartFileAppenderLayout#selectAppender(...) previously relied on new HashMap<>(logger.getAppenders()) to always create a defensive copy before remove(NAME). Can you confirm MapUtils.newHashMap(map) also always returns a new mutable copy (never the same instance or a view), otherwise this would mutate the logger's original appender map?

Severity: medium

Fix This in Augment

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

Update the microsphere-java.version property in microsphere-logging-parent/pom.xml from 0.3.5 to 0.3.6 so modules inheriting this parent will use the newer microsphere-java release.
@mercyblitz mercyblitz closed this May 30, 2026
@mercyblitz mercyblitz deleted the copilot/refactor-collection-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