Skip to content

Commit

Permalink
Fix literals in DurationFormatUtility
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Jun 27, 2023
1 parent a010d6f commit 12c718d
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static String formatDuration(long durationMillis, @NotNull String format,
inLiteral = false;
} else {
lexxBuilder = new StringBuilder();
list.add(new Token(""));
list.add(new Token(lexxBuilder));
inLiteral = true;
}
break;
Expand All @@ -68,10 +68,10 @@ public static String formatDuration(long durationMillis, @NotNull String format,
case 's':
case 'S':
final String value = String.valueOf(ch);
if (previous != null && previous.value.equals(value)) {
if (previous != null && previous.value.toString().equals(value)) {
previous.count++;
} else {
final Token token = new Token(value);
final Token token = new Token(new StringBuilder(value));
list.add(token);
previous = token;
}
Expand All @@ -80,7 +80,7 @@ public static String formatDuration(long durationMillis, @NotNull String format,
default:
if (lexxBuilder == null) {
lexxBuilder = new StringBuilder();
list.add(new Token(""));
list.add(new Token(lexxBuilder));
}
lexxBuilder.append(ch);
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public static String formatDuration(long durationMillis, @NotNull String format,
final StringBuilder builder = new StringBuilder();
boolean lastOutputSeconds = false;
for (final Token token : tokens) {
final String value = token.value;
final String value = token.value.toString();
final int count = token.count;
switch (value) {
case "y":
Expand Down Expand Up @@ -191,15 +191,15 @@ private DurationFormatUtility() {
* Element that is parsed from the format pattern
*/
private static class Token {
@NotNull private final String value;
@NotNull private final StringBuilder value;
private int count = 1;

/**
* Wraps a token around a value. A value would be something like a 'Y'
*
* @param value to wrap
*/
private Token(@NotNull String value) {
private Token(@NotNull StringBuilder value) {
this.value = value;
}

Expand All @@ -213,7 +213,7 @@ private Token(@NotNull String value) {
*/
@Contract(pure = true)
static boolean containsTokenWithValue(@NotNull Token[] tokens, @NotNull String value) {
for (final Token token : tokens) if (token.value.equals(value)) return true;
for (final Token token : tokens) if (token.value.toString().equals(value)) return true;
return false;
}
}
Expand Down

0 comments on commit 12c718d

Please sign in to comment.