made some fields static

This commit is contained in:
Rsl1122 2018-08-12 10:42:38 +03:00
parent fc6c9399cf
commit 08cb206977

View File

@ -11,13 +11,13 @@ import org.apache.commons.lang3.StringUtils;
public class TimeAmountFormatter implements Formatter<Long> { public class TimeAmountFormatter implements Formatter<Long> {
// Placeholders for the config settings // Placeholders for the config settings
private final String zeroPH = "%zero%"; private static final String ZERO_PH = "%zero%";
private final String secondsPH = "%seconds%"; private static final String SECONDS_PH = "%seconds%";
private final String minutesPH = "%minutes%"; private static final String MINUTES_PH = "%minutes%";
private final String hoursPH = "%hours%"; private static final String HOURS_PH = "%hours%";
private final String daysPH = "%days%"; private static final String DAYS_PH = "%days%";
private final String monthsPH = "%months%"; private static final String MONTHS_PH = "%months%";
private final String yearsPH = "%years%"; private static final String YEARS_PH = "%years%";
@Override @Override
public String apply(Long ms) { public String apply(Long ms) {
@ -50,7 +50,7 @@ public class TimeAmountFormatter implements Formatter<Long> {
appendMinutes(builder, minutes, hours, hourFormat, minuteFormat); appendMinutes(builder, minutes, hours, hourFormat, minuteFormat);
appendSeconds(builder, seconds, minutes, hours, hourFormat, minuteFormat, secondFormat); 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()) { if (formattedTime.isEmpty()) {
return Settings.FORMAT_ZERO_SECONDS.toString(); 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) { private void appendSeconds(StringBuilder builder, long seconds, long minutes, long hours, String fHours, String fMinutes, String fSeconds) {
if (seconds != 0) { if (seconds != 0) {
String s = fSeconds.replace(secondsPH, String.valueOf(seconds)); String s = fSeconds.replace(SECONDS_PH, String.valueOf(seconds));
if (minutes == 0 && s.contains(minutesPH)) { if (minutes == 0 && s.contains(MINUTES_PH)) {
if (hours == 0 && fMinutes.contains(hoursPH)) { if (hours == 0 && fMinutes.contains(HOURS_PH)) {
builder.append(fHours.replace(zeroPH, "0").replace(hoursPH, "0")); 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, ""); s = s.replace(MINUTES_PH, "");
if (s.contains(zeroPH) && String.valueOf(seconds).length() == 1) { if (s.contains(ZERO_PH) && String.valueOf(seconds).length() == 1) {
builder.append('0'); builder.append('0');
} }
builder.append(s); 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) { private void appendMinutes(StringBuilder builder, long minutes, long hours, String fHours, String fMinutes) {
if (minutes != 0) { if (minutes != 0) {
String m = fMinutes.replace(minutesPH, String.valueOf(minutes)); String m = fMinutes.replace(MINUTES_PH, String.valueOf(minutes));
if (hours == 0 && m.contains(hoursPH)) { if (hours == 0 && m.contains(HOURS_PH)) {
builder.append(fHours.replace(zeroPH, "0").replace(hoursPH, "0")); builder.append(fHours.replace(ZERO_PH, "0").replace(HOURS_PH, "0"));
m = m.replace(hoursPH, ""); m = m.replace(HOURS_PH, "");
} }
m = m.replace(hoursPH, ""); m = m.replace(HOURS_PH, "");
if (m.contains(zeroPH) && String.valueOf(minutes).length() == 1) { if (m.contains(ZERO_PH) && String.valueOf(minutes).length() == 1) {
builder.append('0'); builder.append('0');
} }
builder.append(m); builder.append(m);
@ -91,8 +91,8 @@ public class TimeAmountFormatter implements Formatter<Long> {
private void appendHours(StringBuilder builder, long hours, String fHours) { private void appendHours(StringBuilder builder, long hours, String fHours) {
if (hours != 0) { if (hours != 0) {
String h = fHours.replace(hoursPH, String.valueOf(hours)); String h = fHours.replace(HOURS_PH, String.valueOf(hours));
if (h.contains(zeroPH) && String.valueOf(hours).length() == 1) { if (h.contains(ZERO_PH) && String.valueOf(hours).length() == 1) {
builder.append('0'); builder.append('0');
} }
builder.append(h); builder.append(h);
@ -102,21 +102,21 @@ public class TimeAmountFormatter implements Formatter<Long> {
private void appendDays(StringBuilder builder, long days) { private void appendDays(StringBuilder builder, long days) {
String singular = Settings.FORMAT_DAY.toString(); String singular = Settings.FORMAT_DAY.toString();
String plural = Settings.FORMAT_DAYS.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) { private void appendMonths(StringBuilder builder, long months) {
String singular = Settings.FORMAT_MONTH.toString(); String singular = Settings.FORMAT_MONTH.toString();
String plural = Settings.FORMAT_MONTHS.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) { private void appendYears(StringBuilder builder, long years) {
String singular = Settings.FORMAT_YEAR.toString(); String singular = Settings.FORMAT_YEAR.toString();
String plural = Settings.FORMAT_YEARS.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) { private void appendValue(StringBuilder builder, long amount, String singular, String plural, String replace) {