@Test public void testElapsedTimeInHours() throws Exception { assertThat(StringUtils.getFullElapsedTime(JiveConstants.HOUR), is("1 hour")); assertThat(StringUtils.getFullElapsedTime(JiveConstants.HOUR + JiveConstants.MINUTE + JiveConstants.SECOND + 1), is("1 hour, 1 minute, 1 second, 1 ms")); assertThat(StringUtils.getFullElapsedTime(JiveConstants.HOUR * 10 + JiveConstants.MINUTE * 30), is("10 hours, 30 minutes")); }
public static String getFullElapsedTime(final long delta) { if (delta < JiveConstants.SECOND) { return String.format("%d %s", delta, delta == 1 ? LocaleUtils.getLocalizedString("global.millisecond") : LocaleUtils.getLocalizedString("global.milliseconds")); } else if (delta < JiveConstants.MINUTE) { final long millis = delta % JiveConstants.SECOND; final long seconds = delta / JiveConstants.SECOND; final String secondsString = String.format("%d %s", seconds, seconds == 1 ? LocaleUtils.getLocalizedString("global.second") : LocaleUtils.getLocalizedString("global.seconds")); if (millis > 0) { return secondsString + ", " + getFullElapsedTime(millis); } else { return secondsString; } } else if (delta < JiveConstants.HOUR) { final long millis = delta % JiveConstants.MINUTE; final long minutes = delta / JiveConstants.MINUTE; final String minutesString = String.format("%d %s", minutes, minutes == 1 ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes")); if (millis > 0) { return minutesString + ", " + getFullElapsedTime(millis); } else { return minutesString; } } else if (delta < JiveConstants.DAY) { final long millis = delta % JiveConstants.HOUR; final long hours = delta / JiveConstants.HOUR; final String daysString = String.format("%d %s", hours, hours == 1 ? LocaleUtils.getLocalizedString("global.hour") : LocaleUtils.getLocalizedString("global.hours")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } else { final long millis = delta % JiveConstants.DAY; final long days = delta / JiveConstants.DAY; final String daysString = String.format("%d %s", days, days == 1 ? LocaleUtils.getLocalizedString("global.day") : LocaleUtils.getLocalizedString("global.days")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } }
StringUtils { public static String getFullElapsedTime(final long delta) { if (delta < JiveConstants.SECOND) { return String.format("%d %s", delta, delta == 1 ? LocaleUtils.getLocalizedString("global.millisecond") : LocaleUtils.getLocalizedString("global.milliseconds")); } else if (delta < JiveConstants.MINUTE) { final long millis = delta % JiveConstants.SECOND; final long seconds = delta / JiveConstants.SECOND; final String secondsString = String.format("%d %s", seconds, seconds == 1 ? LocaleUtils.getLocalizedString("global.second") : LocaleUtils.getLocalizedString("global.seconds")); if (millis > 0) { return secondsString + ", " + getFullElapsedTime(millis); } else { return secondsString; } } else if (delta < JiveConstants.HOUR) { final long millis = delta % JiveConstants.MINUTE; final long minutes = delta / JiveConstants.MINUTE; final String minutesString = String.format("%d %s", minutes, minutes == 1 ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes")); if (millis > 0) { return minutesString + ", " + getFullElapsedTime(millis); } else { return minutesString; } } else if (delta < JiveConstants.DAY) { final long millis = delta % JiveConstants.HOUR; final long hours = delta / JiveConstants.HOUR; final String daysString = String.format("%d %s", hours, hours == 1 ? LocaleUtils.getLocalizedString("global.hour") : LocaleUtils.getLocalizedString("global.hours")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } else { final long millis = delta % JiveConstants.DAY; final long days = delta / JiveConstants.DAY; final String daysString = String.format("%d %s", days, days == 1 ? LocaleUtils.getLocalizedString("global.day") : LocaleUtils.getLocalizedString("global.days")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } } }
StringUtils { public static String getFullElapsedTime(final long delta) { if (delta < JiveConstants.SECOND) { return String.format("%d %s", delta, delta == 1 ? LocaleUtils.getLocalizedString("global.millisecond") : LocaleUtils.getLocalizedString("global.milliseconds")); } else if (delta < JiveConstants.MINUTE) { final long millis = delta % JiveConstants.SECOND; final long seconds = delta / JiveConstants.SECOND; final String secondsString = String.format("%d %s", seconds, seconds == 1 ? LocaleUtils.getLocalizedString("global.second") : LocaleUtils.getLocalizedString("global.seconds")); if (millis > 0) { return secondsString + ", " + getFullElapsedTime(millis); } else { return secondsString; } } else if (delta < JiveConstants.HOUR) { final long millis = delta % JiveConstants.MINUTE; final long minutes = delta / JiveConstants.MINUTE; final String minutesString = String.format("%d %s", minutes, minutes == 1 ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes")); if (millis > 0) { return minutesString + ", " + getFullElapsedTime(millis); } else { return minutesString; } } else if (delta < JiveConstants.DAY) { final long millis = delta % JiveConstants.HOUR; final long hours = delta / JiveConstants.HOUR; final String daysString = String.format("%d %s", hours, hours == 1 ? LocaleUtils.getLocalizedString("global.hour") : LocaleUtils.getLocalizedString("global.hours")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } else { final long millis = delta % JiveConstants.DAY; final long days = delta / JiveConstants.DAY; final String daysString = String.format("%d %s", days, days == 1 ? LocaleUtils.getLocalizedString("global.day") : LocaleUtils.getLocalizedString("global.days")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } } private  StringUtils(); }
StringUtils { public static String getFullElapsedTime(final long delta) { if (delta < JiveConstants.SECOND) { return String.format("%d %s", delta, delta == 1 ? LocaleUtils.getLocalizedString("global.millisecond") : LocaleUtils.getLocalizedString("global.milliseconds")); } else if (delta < JiveConstants.MINUTE) { final long millis = delta % JiveConstants.SECOND; final long seconds = delta / JiveConstants.SECOND; final String secondsString = String.format("%d %s", seconds, seconds == 1 ? LocaleUtils.getLocalizedString("global.second") : LocaleUtils.getLocalizedString("global.seconds")); if (millis > 0) { return secondsString + ", " + getFullElapsedTime(millis); } else { return secondsString; } } else if (delta < JiveConstants.HOUR) { final long millis = delta % JiveConstants.MINUTE; final long minutes = delta / JiveConstants.MINUTE; final String minutesString = String.format("%d %s", minutes, minutes == 1 ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes")); if (millis > 0) { return minutesString + ", " + getFullElapsedTime(millis); } else { return minutesString; } } else if (delta < JiveConstants.DAY) { final long millis = delta % JiveConstants.HOUR; final long hours = delta / JiveConstants.HOUR; final String daysString = String.format("%d %s", hours, hours == 1 ? LocaleUtils.getLocalizedString("global.hour") : LocaleUtils.getLocalizedString("global.hours")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } else { final long millis = delta % JiveConstants.DAY; final long days = delta / JiveConstants.DAY; final String daysString = String.format("%d %s", days, days == 1 ? LocaleUtils.getLocalizedString("global.day") : LocaleUtils.getLocalizedString("global.days")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } } private  StringUtils(); @Deprecated static String replace(String string, String oldString, String newString); static String replaceIgnoreCase(String line, String oldString,
                                                 String newString); static String replaceIgnoreCase(String line, String oldString,
            String newString, int[] count); static String replace(String line, String oldString,
            String newString, int[] count); static String stripTags(String in); static String escapeHTMLTags(String in); static String escapeHTMLTags(String in, boolean includeLF); static String hash(String data); static String hash(String data, String algorithm); static String hash(byte[] bytes, String algorithm); static String encodeHex(byte[] bytes); static byte[] decodeHex(String hex); static String encodeBase64(String data); static String encodeBase64(byte[] data); static byte[] decodeBase64(String data); static String encodeBase32(String data); static String encodeBase32(byte[] data); static byte[] decodeBase32(String data); static boolean isBase32(String data); static String[] toLowerCaseWordArray(String text); static String randomString(int length); static String chopAtWord(String string, int length); static String wordWrap(String input, int width, Locale locale); static String escapeForSQL(String string); static String escapeForXML(String string); static String unescapeFromXML(String string); static String zeroPadString(String string, int length); static String dateToMillis(Date date); static String getFullElapsedTime(final long delta); static String getFullElapsedTime(final Duration delta); static String getElapsedTime(long delta); static String getTimeFromLong(long diff); static String collectionToString(Collection<String> collection); static Collection<String> stringToCollection(String string); static boolean contains(String[] array, String item); static String abbreviate(String str, int maxWidth); static boolean isValidEmailAddress(String address); static String validateDomainName(String domain); static String removeXSSCharacters(String input); @Deprecated static byte[] getBytes(String input); @Deprecated static String getString(byte[] input); static boolean containsIgnoringCase(final String nullableString, final String value); static Optional<Integer> parseInteger(final String value); static Optional<Long> parseLong(final String value); static Optional<Double> parseDouble(final String value); static Optional<Boolean> parseBoolean(final String value); static List<String> shellSplit(CharSequence string); }
StringUtils { public static String getFullElapsedTime(final long delta) { if (delta < JiveConstants.SECOND) { return String.format("%d %s", delta, delta == 1 ? LocaleUtils.getLocalizedString("global.millisecond") : LocaleUtils.getLocalizedString("global.milliseconds")); } else if (delta < JiveConstants.MINUTE) { final long millis = delta % JiveConstants.SECOND; final long seconds = delta / JiveConstants.SECOND; final String secondsString = String.format("%d %s", seconds, seconds == 1 ? LocaleUtils.getLocalizedString("global.second") : LocaleUtils.getLocalizedString("global.seconds")); if (millis > 0) { return secondsString + ", " + getFullElapsedTime(millis); } else { return secondsString; } } else if (delta < JiveConstants.HOUR) { final long millis = delta % JiveConstants.MINUTE; final long minutes = delta / JiveConstants.MINUTE; final String minutesString = String.format("%d %s", minutes, minutes == 1 ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes")); if (millis > 0) { return minutesString + ", " + getFullElapsedTime(millis); } else { return minutesString; } } else if (delta < JiveConstants.DAY) { final long millis = delta % JiveConstants.HOUR; final long hours = delta / JiveConstants.HOUR; final String daysString = String.format("%d %s", hours, hours == 1 ? LocaleUtils.getLocalizedString("global.hour") : LocaleUtils.getLocalizedString("global.hours")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } else { final long millis = delta % JiveConstants.DAY; final long days = delta / JiveConstants.DAY; final String daysString = String.format("%d %s", days, days == 1 ? LocaleUtils.getLocalizedString("global.day") : LocaleUtils.getLocalizedString("global.days")); if (millis > 0) { return daysString + ", " + getFullElapsedTime(millis); } else { return daysString; } } } private  StringUtils(); @Deprecated static String replace(String string, String oldString, String newString); static String replaceIgnoreCase(String line, String oldString,
                                                 String newString); static String replaceIgnoreCase(String line, String oldString,
            String newString, int[] count); static String replace(String line, String oldString,
            String newString, int[] count); static String stripTags(String in); static String escapeHTMLTags(String in); static String escapeHTMLTags(String in, boolean includeLF); static String hash(String data); static String hash(String data, String algorithm); static String hash(byte[] bytes, String algorithm); static String encodeHex(byte[] bytes); static byte[] decodeHex(String hex); static String encodeBase64(String data); static String encodeBase64(byte[] data); static byte[] decodeBase64(String data); static String encodeBase32(String data); static String encodeBase32(byte[] data); static byte[] decodeBase32(String data); static boolean isBase32(String data); static String[] toLowerCaseWordArray(String text); static String randomString(int length); static String chopAtWord(String string, int length); static String wordWrap(String input, int width, Locale locale); static String escapeForSQL(String string); static String escapeForXML(String string); static String unescapeFromXML(String string); static String zeroPadString(String string, int length); static String dateToMillis(Date date); static String getFullElapsedTime(final long delta); static String getFullElapsedTime(final Duration delta); static String getElapsedTime(long delta); static String getTimeFromLong(long diff); static String collectionToString(Collection<String> collection); static Collection<String> stringToCollection(String string); static boolean contains(String[] array, String item); static String abbreviate(String str, int maxWidth); static boolean isValidEmailAddress(String address); static String validateDomainName(String domain); static String removeXSSCharacters(String input); @Deprecated static byte[] getBytes(String input); @Deprecated static String getString(byte[] input); static boolean containsIgnoringCase(final String nullableString, final String value); static Optional<Integer> parseInteger(final String value); static Optional<Long> parseLong(final String value); static Optional<Double> parseDouble(final String value); static Optional<Boolean> parseBoolean(final String value); static List<String> shellSplit(CharSequence string);  }