@Test public void testParseDuration() { long m = ConfigurationUtils.parseDuration(duration); assertEquals(durationInMillis, m); assertEquals(Times.MS_PER_YEAR, ConfigurationUtils.parseDuration("1y")); assertEquals(2 * Times.MS_PER_YEAR, ConfigurationUtils.parseDuration("2y")); assertEquals(Times.MS_PER_MONTH, ConfigurationUtils.parseDuration("1m")); assertEquals(2 * Times.MS_PER_MONTH, ConfigurationUtils.parseDuration("2m")); assertEquals(Times.MS_PER_WEEK, ConfigurationUtils.parseDuration("1w")); assertEquals(2 * Times.MS_PER_WEEK, ConfigurationUtils.parseDuration("2w")); assertEquals(Times.MS_PER_DAY, ConfigurationUtils.parseDuration("1d")); assertEquals(2 * Times.MS_PER_DAY, ConfigurationUtils.parseDuration("2d")); assertEquals(Times.MS_PER_HOUR, ConfigurationUtils.parseDuration("1H")); assertEquals(2 * Times.MS_PER_HOUR, ConfigurationUtils.parseDuration("2H")); assertEquals(Times.MS_PER_MIN, ConfigurationUtils.parseDuration("1M")); assertEquals(2 * Times.MS_PER_MIN, ConfigurationUtils.parseDuration("2M")); }
public static long parseDuration(String duration) throws IllegalArgumentException { if (duration == null) return 0; long millis = 0; try { return Long.parseLong(duration); } catch (NumberFormatException e) { Pattern p = Pattern.compile("^([\\d]+y)?([\\d]+m)?([\\d]+w)?([\\d]+d)?([\\d]+H)?([\\d]+M)?([\\d]+S)?$"); Matcher m = p.matcher(duration); if (m.matches()) { for (int i = 1; i <= m.groupCount(); i++) { String match = m.group(i); if (match == null) continue; if (match.endsWith("y")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_YEAR; if (match.endsWith("m")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MONTH; if (match.endsWith("w")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_WEEK; if (match.endsWith("d")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_DAY; if (match.endsWith("H")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_HOUR; if (match.endsWith("M")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MIN; if (match.endsWith("S")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_SECOND; } } else { throw new IllegalArgumentException("Unknown duration format: " + duration); } } return millis; }
ConfigurationUtils { public static long parseDuration(String duration) throws IllegalArgumentException { if (duration == null) return 0; long millis = 0; try { return Long.parseLong(duration); } catch (NumberFormatException e) { Pattern p = Pattern.compile("^([\\d]+y)?([\\d]+m)?([\\d]+w)?([\\d]+d)?([\\d]+H)?([\\d]+M)?([\\d]+S)?$"); Matcher m = p.matcher(duration); if (m.matches()) { for (int i = 1; i <= m.groupCount(); i++) { String match = m.group(i); if (match == null) continue; if (match.endsWith("y")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_YEAR; if (match.endsWith("m")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MONTH; if (match.endsWith("w")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_WEEK; if (match.endsWith("d")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_DAY; if (match.endsWith("H")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_HOUR; if (match.endsWith("M")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MIN; if (match.endsWith("S")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_SECOND; } } else { throw new IllegalArgumentException("Unknown duration format: " + duration); } } return millis; } }
ConfigurationUtils { public static long parseDuration(String duration) throws IllegalArgumentException { if (duration == null) return 0; long millis = 0; try { return Long.parseLong(duration); } catch (NumberFormatException e) { Pattern p = Pattern.compile("^([\\d]+y)?([\\d]+m)?([\\d]+w)?([\\d]+d)?([\\d]+H)?([\\d]+M)?([\\d]+S)?$"); Matcher m = p.matcher(duration); if (m.matches()) { for (int i = 1; i <= m.groupCount(); i++) { String match = m.group(i); if (match == null) continue; if (match.endsWith("y")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_YEAR; if (match.endsWith("m")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MONTH; if (match.endsWith("w")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_WEEK; if (match.endsWith("d")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_DAY; if (match.endsWith("H")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_HOUR; if (match.endsWith("M")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MIN; if (match.endsWith("S")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_SECOND; } } else { throw new IllegalArgumentException("Unknown duration format: " + duration); } } return millis; } private  ConfigurationUtils(); }
ConfigurationUtils { public static long parseDuration(String duration) throws IllegalArgumentException { if (duration == null) return 0; long millis = 0; try { return Long.parseLong(duration); } catch (NumberFormatException e) { Pattern p = Pattern.compile("^([\\d]+y)?([\\d]+m)?([\\d]+w)?([\\d]+d)?([\\d]+H)?([\\d]+M)?([\\d]+S)?$"); Matcher m = p.matcher(duration); if (m.matches()) { for (int i = 1; i <= m.groupCount(); i++) { String match = m.group(i); if (match == null) continue; if (match.endsWith("y")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_YEAR; if (match.endsWith("m")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MONTH; if (match.endsWith("w")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_WEEK; if (match.endsWith("d")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_DAY; if (match.endsWith("H")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_HOUR; if (match.endsWith("M")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MIN; if (match.endsWith("S")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_SECOND; } } else { throw new IllegalArgumentException("Unknown duration format: " + duration); } } return millis; } private  ConfigurationUtils(); static Object getValue(Object object, Object defaultObject); static Object getValue(Object object, Object defaultObject,
      boolean processTemplates); static int getValue(String value, int defaultValue); static long getValue(String value, long defaultValue); static String[] getMultiOptionValues(String optionValue); static boolean isDefault(Node node); static boolean isTrue(Node node); static boolean isTrue(String value); static boolean isTrue(String value, boolean defaultValue); static boolean isFalse(String value); static boolean isFalse(String value, boolean defaultValue); static boolean isEnabled(String value); static boolean isEnabled(String value, boolean defaultValue); static boolean isDisabled(String value); static boolean isDisabled(String value, boolean defaultValue); static String toHumanReadableDuration(long millis); static String toDuration(long millis); static long parseDuration(String duration); static String processTemplate(String text); static String processTemplate(String text,
      Map<String, String> variables); static String processTemplate(String text, Module module,
      Environment environment); static String processTemplate(String text, Site site,
      Environment environment); }
ConfigurationUtils { public static long parseDuration(String duration) throws IllegalArgumentException { if (duration == null) return 0; long millis = 0; try { return Long.parseLong(duration); } catch (NumberFormatException e) { Pattern p = Pattern.compile("^([\\d]+y)?([\\d]+m)?([\\d]+w)?([\\d]+d)?([\\d]+H)?([\\d]+M)?([\\d]+S)?$"); Matcher m = p.matcher(duration); if (m.matches()) { for (int i = 1; i <= m.groupCount(); i++) { String match = m.group(i); if (match == null) continue; if (match.endsWith("y")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_YEAR; if (match.endsWith("m")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MONTH; if (match.endsWith("w")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_WEEK; if (match.endsWith("d")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_DAY; if (match.endsWith("H")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_HOUR; if (match.endsWith("M")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_MIN; if (match.endsWith("S")) millis += Long.parseLong(match.substring(0, match.length() - 1)) * Times.MS_PER_SECOND; } } else { throw new IllegalArgumentException("Unknown duration format: " + duration); } } return millis; } private  ConfigurationUtils(); static Object getValue(Object object, Object defaultObject); static Object getValue(Object object, Object defaultObject,
      boolean processTemplates); static int getValue(String value, int defaultValue); static long getValue(String value, long defaultValue); static String[] getMultiOptionValues(String optionValue); static boolean isDefault(Node node); static boolean isTrue(Node node); static boolean isTrue(String value); static boolean isTrue(String value, boolean defaultValue); static boolean isFalse(String value); static boolean isFalse(String value, boolean defaultValue); static boolean isEnabled(String value); static boolean isEnabled(String value, boolean defaultValue); static boolean isDisabled(String value); static boolean isDisabled(String value, boolean defaultValue); static String toHumanReadableDuration(long millis); static String toDuration(long millis); static long parseDuration(String duration); static String processTemplate(String text); static String processTemplate(String text,
      Map<String, String> variables); static String processTemplate(String text, Module module,
      Environment environment); static String processTemplate(String text, Site site,
      Environment environment);  }