@Test public void testFormat() { RemainingPeriodFormatter f = new RemainingPeriodFormatter(); assertEquals("5 seconds remaining", f.format(5L)); assertEquals("5 minutes remaining", f.format(5 * 60)); assertEquals("60 minutes remaining", f.format(60 * 60)); assertEquals("120 minutes remaining", f.format(60 * 60 * 2)); assertEquals("2.0 hours remaining", f.format(60 * 60 * 2 + 1)); assertEquals("2.1 hours remaining", f.format(60 * 60 * 2 + 6 * 60)); }
@Override public String format(final long remaining) { StringBuilder b = new StringBuilder(); if(remaining < 0) { return LocaleFactory.localizedString("Unknown"); } if(remaining > 7200) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} hours remaining", "Status"), new BigDecimal(remaining).divide(new BigDecimal(3600), 1, BigDecimal.ROUND_DOWN).toString()) ); } else if(remaining > 120) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} minutes remaining", "Status"), String.valueOf((int) (remaining / 60))) ); } else { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} seconds remaining", "Status"), String.valueOf((int) remaining)) ); } return b.toString(); }
RemainingPeriodFormatter implements PeriodFormatter { @Override public String format(final long remaining) { StringBuilder b = new StringBuilder(); if(remaining < 0) { return LocaleFactory.localizedString("Unknown"); } if(remaining > 7200) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} hours remaining", "Status"), new BigDecimal(remaining).divide(new BigDecimal(3600), 1, BigDecimal.ROUND_DOWN).toString()) ); } else if(remaining > 120) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} minutes remaining", "Status"), String.valueOf((int) (remaining / 60))) ); } else { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} seconds remaining", "Status"), String.valueOf((int) remaining)) ); } return b.toString(); } }
RemainingPeriodFormatter implements PeriodFormatter { @Override public String format(final long remaining) { StringBuilder b = new StringBuilder(); if(remaining < 0) { return LocaleFactory.localizedString("Unknown"); } if(remaining > 7200) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} hours remaining", "Status"), new BigDecimal(remaining).divide(new BigDecimal(3600), 1, BigDecimal.ROUND_DOWN).toString()) ); } else if(remaining > 120) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} minutes remaining", "Status"), String.valueOf((int) (remaining / 60))) ); } else { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} seconds remaining", "Status"), String.valueOf((int) remaining)) ); } return b.toString(); }  }
RemainingPeriodFormatter implements PeriodFormatter { @Override public String format(final long remaining) { StringBuilder b = new StringBuilder(); if(remaining < 0) { return LocaleFactory.localizedString("Unknown"); } if(remaining > 7200) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} hours remaining", "Status"), new BigDecimal(remaining).divide(new BigDecimal(3600), 1, BigDecimal.ROUND_DOWN).toString()) ); } else if(remaining > 120) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} minutes remaining", "Status"), String.valueOf((int) (remaining / 60))) ); } else { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} seconds remaining", "Status"), String.valueOf((int) remaining)) ); } return b.toString(); }  @Override String format(final long remaining); }
RemainingPeriodFormatter implements PeriodFormatter { @Override public String format(final long remaining) { StringBuilder b = new StringBuilder(); if(remaining < 0) { return LocaleFactory.localizedString("Unknown"); } if(remaining > 7200) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} hours remaining", "Status"), new BigDecimal(remaining).divide(new BigDecimal(3600), 1, BigDecimal.ROUND_DOWN).toString()) ); } else if(remaining > 120) { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} minutes remaining", "Status"), String.valueOf((int) (remaining / 60))) ); } else { b.append(MessageFormat.format(LocaleFactory.localizedString("{0} seconds remaining", "Status"), String.valueOf((int) remaining)) ); } return b.toString(); }  @Override String format(final long remaining);  }