mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-12 14:58:26 +02:00
made some fields static
This commit is contained in:
parent
fc6c9399cf
commit
08cb206977
@ -11,13 +11,13 @@ import org.apache.commons.lang3.StringUtils;
|
||||
public class TimeAmountFormatter implements Formatter<Long> {
|
||||
|
||||
// Placeholders for the config settings
|
||||
private final String zeroPH = "%zero%";
|
||||
private final String secondsPH = "%seconds%";
|
||||
private final String minutesPH = "%minutes%";
|
||||
private final String hoursPH = "%hours%";
|
||||
private final String daysPH = "%days%";
|
||||
private final String monthsPH = "%months%";
|
||||
private final String yearsPH = "%years%";
|
||||
private static final String ZERO_PH = "%zero%";
|
||||
private static final String SECONDS_PH = "%seconds%";
|
||||
private static final String MINUTES_PH = "%minutes%";
|
||||
private static final String HOURS_PH = "%hours%";
|
||||
private static final String DAYS_PH = "%days%";
|
||||
private static final String MONTHS_PH = "%months%";
|
||||
private static final String YEARS_PH = "%years%";
|
||||
|
||||
@Override
|
||||
public String apply(Long ms) {
|
||||
@ -50,7 +50,7 @@ public class TimeAmountFormatter implements Formatter<Long> {
|
||||
appendMinutes(builder, minutes, hours, hourFormat, minuteFormat);
|
||||
appendSeconds(builder, seconds, minutes, hours, hourFormat, minuteFormat, secondFormat);
|
||||
|
||||
String formattedTime = StringUtils.remove(builder.toString(), zeroPH);
|
||||
String formattedTime = StringUtils.remove(builder.toString(), ZERO_PH);
|
||||
if (formattedTime.isEmpty()) {
|
||||
return Settings.FORMAT_ZERO_SECONDS.toString();
|
||||
}
|
||||
@ -59,15 +59,15 @@ public class TimeAmountFormatter implements Formatter<Long> {
|
||||
|
||||
private void appendSeconds(StringBuilder builder, long seconds, long minutes, long hours, String fHours, String fMinutes, String fSeconds) {
|
||||
if (seconds != 0) {
|
||||
String s = fSeconds.replace(secondsPH, String.valueOf(seconds));
|
||||
if (minutes == 0 && s.contains(minutesPH)) {
|
||||
if (hours == 0 && fMinutes.contains(hoursPH)) {
|
||||
builder.append(fHours.replace(zeroPH, "0").replace(hoursPH, "0"));
|
||||
String s = fSeconds.replace(SECONDS_PH, String.valueOf(seconds));
|
||||
if (minutes == 0 && s.contains(MINUTES_PH)) {
|
||||
if (hours == 0 && fMinutes.contains(HOURS_PH)) {
|
||||
builder.append(fHours.replace(ZERO_PH, "0").replace(HOURS_PH, "0"));
|
||||
}
|
||||
builder.append(fMinutes.replace(hoursPH, "").replace(zeroPH, "0").replace(minutesPH, "0"));
|
||||
builder.append(fMinutes.replace(HOURS_PH, "").replace(ZERO_PH, "0").replace(MINUTES_PH, "0"));
|
||||
}
|
||||
s = s.replace(minutesPH, "");
|
||||
if (s.contains(zeroPH) && String.valueOf(seconds).length() == 1) {
|
||||
s = s.replace(MINUTES_PH, "");
|
||||
if (s.contains(ZERO_PH) && String.valueOf(seconds).length() == 1) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(s);
|
||||
@ -76,13 +76,13 @@ public class TimeAmountFormatter implements Formatter<Long> {
|
||||
|
||||
private void appendMinutes(StringBuilder builder, long minutes, long hours, String fHours, String fMinutes) {
|
||||
if (minutes != 0) {
|
||||
String m = fMinutes.replace(minutesPH, String.valueOf(minutes));
|
||||
if (hours == 0 && m.contains(hoursPH)) {
|
||||
builder.append(fHours.replace(zeroPH, "0").replace(hoursPH, "0"));
|
||||
m = m.replace(hoursPH, "");
|
||||
String m = fMinutes.replace(MINUTES_PH, String.valueOf(minutes));
|
||||
if (hours == 0 && m.contains(HOURS_PH)) {
|
||||
builder.append(fHours.replace(ZERO_PH, "0").replace(HOURS_PH, "0"));
|
||||
m = m.replace(HOURS_PH, "");
|
||||
}
|
||||
m = m.replace(hoursPH, "");
|
||||
if (m.contains(zeroPH) && String.valueOf(minutes).length() == 1) {
|
||||
m = m.replace(HOURS_PH, "");
|
||||
if (m.contains(ZERO_PH) && String.valueOf(minutes).length() == 1) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(m);
|
||||
@ -91,8 +91,8 @@ public class TimeAmountFormatter implements Formatter<Long> {
|
||||
|
||||
private void appendHours(StringBuilder builder, long hours, String fHours) {
|
||||
if (hours != 0) {
|
||||
String h = fHours.replace(hoursPH, String.valueOf(hours));
|
||||
if (h.contains(zeroPH) && String.valueOf(hours).length() == 1) {
|
||||
String h = fHours.replace(HOURS_PH, String.valueOf(hours));
|
||||
if (h.contains(ZERO_PH) && String.valueOf(hours).length() == 1) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(h);
|
||||
@ -102,21 +102,21 @@ public class TimeAmountFormatter implements Formatter<Long> {
|
||||
private void appendDays(StringBuilder builder, long days) {
|
||||
String singular = Settings.FORMAT_DAY.toString();
|
||||
String plural = Settings.FORMAT_DAYS.toString();
|
||||
appendValue(builder, days, singular, plural, daysPH);
|
||||
appendValue(builder, days, singular, plural, DAYS_PH);
|
||||
}
|
||||
|
||||
private void appendMonths(StringBuilder builder, long months) {
|
||||
String singular = Settings.FORMAT_MONTH.toString();
|
||||
String plural = Settings.FORMAT_MONTHS.toString();
|
||||
|
||||
appendValue(builder, months, singular, plural, monthsPH);
|
||||
appendValue(builder, months, singular, plural, MONTHS_PH);
|
||||
}
|
||||
|
||||
private void appendYears(StringBuilder builder, long years) {
|
||||
String singular = Settings.FORMAT_YEAR.toString();
|
||||
String plural = Settings.FORMAT_YEARS.toString();
|
||||
|
||||
appendValue(builder, years, singular, plural, yearsPH);
|
||||
appendValue(builder, years, singular, plural, YEARS_PH);
|
||||
}
|
||||
|
||||
private void appendValue(StringBuilder builder, long amount, String singular, String plural, String replace) {
|
||||
|
Loading…
Reference in New Issue
Block a user