Refactor NumberConversionUtil and toString() of CookieList & XML Classes. #831
+20
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello @stleary,
I have made 3 refactorings.
1. Renamed Variable boolean b in toString() method of CookieList Class.
boolean
isEndOfPair
is more meaningful as compared to just booleanb
.2. Introduced indentationSuffix variable in toString() method of XML Class.
There are multiple long expressions which are using
(indentFactor > 0) ? "\n" : ""
sub-expression.indentationSuffix
is introduced to replace this sub-expression to improve readability and reduce duplication.3. Added method isNumericChar(...) in NumberConversionUtil Class.
There are some digit-related conditions which may look complex to some developers due to multiple conditional operators.
Eg:
if ((initial >= '0' && initial <= '9') || initial == '-' )
and
if(at1 == '0' && at2 >= '0' && at2 <= '9')
The sub-condition
c >= '0' && c <= '9'
is moved to a methodisNumericChar(...)
to reduce the complexity of these conditions and better readability.Notes:

All the unit tests are passing successfully.
This code is compatible with Java 6.