Skip to content

Commit

Permalink
BugFix to InTextNumberAppender: toString() should work better now
Browse files Browse the repository at this point in the history
The `toString()` method of `InTextNumberAppender` would more likely
return the raw number (like "2") instead of the textual representation
(like "two") for small numbers (for larger ones, this is the right
behavior). This has been fixed now.
  • Loading branch information
thomasWeise committed Sep 12, 2015
1 parent 85ae659 commit d53ca87
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ public final ETextCase appendTo(final long v, final ETextCase textCase,
/** {@inheritDoc} */
@Override
public final String toString(final long v, final ETextCase textCase) {
if ((v < 0) || (v >= InTextNumberAppender.SMALL_NUMBERS.length)
|| ((textCase != null) && (textCase != ETextCase.IN_SENTENCE))) {
return super.toString(v, textCase);
final String str;
if ((v >= 0) && (v < InTextNumberAppender.SMALL_NUMBERS.length)) {
str = InTextNumberAppender.SMALL_NUMBERS[(int) v];
if (textCase == ETextCase.IN_SENTENCE) {
return str;
}
return (textCase.adjustCaseOfFirstCharInWord(str.charAt(0))//
+ str.substring(1));
}
return Long.toString(v);
}
Expand All @@ -72,9 +77,14 @@ public final ETextCase appendTo(final int v, final ETextCase textCase,
/** {@inheritDoc} */
@Override
public final String toString(final int v, final ETextCase textCase) {
if ((v < 0) || (v >= InTextNumberAppender.SMALL_NUMBERS.length)
|| ((textCase != null) && (textCase != ETextCase.IN_SENTENCE))) {
return super.toString(v, textCase);
final String str;
if ((v >= 0) && (v < InTextNumberAppender.SMALL_NUMBERS.length)) {
str = InTextNumberAppender.SMALL_NUMBERS[v];
if (textCase == ETextCase.IN_SENTENCE) {
return str;
}
return (textCase.adjustCaseOfFirstCharInWord(str.charAt(0))//
+ str.substring(1));
}
return Integer.toString(v);
}
Expand Down

0 comments on commit d53ca87

Please sign in to comment.