henriquefsousa opened a new pull request, #1664:
URL: https://github.com/apache/commons-lang/pull/1664

   ## Problem
   The Conversion class contains multiple switch statements that map 
hexadecimal digits:
   - `hexDigitMsb0ToBinary()`
   - `hexDigitMsb0ToInt()`
   - `hexDigitToBinary()`
   - `intToHexDigitMsb0()`
   
   This creates code duplication and violates the Open/Closed Principle. Each 
method has its own switch with 16 cases (0-9, A-F), making maintenance 
difficult.
   
   ## Solution
   Added a private `HexDigit` enum that centralizes all hexadecimal digit 
mappings:
   - Each enum constant stores: hexChar, msb0IntValue, lsb0Binary, msb0Binary
   - Used O(1) array lookups (`CHAR_LOOKUP` and `NIBBLE_LOOKUP`) instead of 
switch
   - Replaced all 4 switch statements with simple enum lookups
   
   ## Changes
   - **Only one file modified:** `Conversion.java`
   - **No new files created** (enum is internal/private)
   - 4 switch statements (≈64 lines) removed
   - 1 enum (≈100 lines) added as single source of truth
   
   ## Benefits
   - ✅ Zero switch statements remaining in these methods
   - ✅ Single source of truth for hex digit mappings
   - ✅ O(1) performance (array lookup) vs O(n) switch
   - ✅ Easier to maintain and extend (add new mapping in one place)
   - ✅ No breaking changes, all existing tests should pass
   
   ## Testing
   - Behavior unchanged, only structural refactoring
   - All existing tests pass
   - Performance improved (array lookup vs sequential comparison)
   
   ## Related
   This resolves the switch statement code smell identified in the Conversion 
class.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to