magefree / magefree/mage

Potential refactor: use EnumMap for Counters

Open
#10,906 0 comments 0 reactions 0 assignees View on GitHub
refactoring
Dominant language
Java
Stars
2.4k
Forks
940
Avg merge
2d 12h
Merged PRs (30d)
160

Description

So I was going to add a constructor `new Counters(Counter counter)` to reduce verbosity on a handful of methods that have to use a `Counters` argument just to add a single counter, and realized that there's a lot more potential improvement here.

Although we use the enum `CounterType` for creating instances of counters, the actual objects are handled in most places by their names which are Strings.

`Counters` extends `HashMap` mapping counter names as strings to Counter objects which have a `String name` and an `int count`. I'm not sure why it's set up this way but it doesn't seem very efficient to me.

I think it could be adjusted so that `Counters` is instead an `EnumMap`, without too much trouble. Any thoughts?

(Probably much harder to adjust the `Counter` object and no clear payoff for doing so.)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the Counters, Counter, and CounterType classes and their usages throughout the project. Determine whether replacing string-keyed handling with CounterType-keyed handling is viable, then define the affected API and migration scope before making changes; completion requires agreement on the design and a consistent update of all affected uses.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.